Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

Today Composing transformations 3D Transformations
This terms course Last term we both worked on learning 2 things –Processing –The concepts of graphics etc. This term will focus more on the basic concepts.
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
Graphics Pipeline.
1 Computer Graphics Week6 –Basic Transformations- Translation & Scaling.
Projection Matrices CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Based on slides created by Edward Angel
1 3D modelling with OpenGL Brian Farrimond Robina Hetherington.
OpenGL 3D and Animation for Simulating a Solar System
Now Playing: Gong Sigur Rós From Takk... Released September 13, 2005.
OpenGL (II). How to Draw a 3-D object on Screen?
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
10/5/04© University of Wisconsin, CS559 Fall 2004 Last Time Compositing Painterly Rendering Intro to 3D Graphics Homework 3 due Oct 12 in class.
Course Overview, Introduction to CG Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 5, 2003.
Transformations Aaron Bloomfield CS 445: Introduction to Graphics
Mouse-Based Viewing & Navigation Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 3, 2003.
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
Linear Interpolation, Brief Introduction to OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September.
CS 481 Preview, Some Lighting Details Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 19, 2003.
02/26/02 (c) 2002 University of Wisconsin, CS 559 Last Time Canonical view pipeline Orthographic projection –There was an error in the matrix for taking.
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Geometric transformations The Pipeline
Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009.
Week 5 - Wednesday.  What did we talk about last time?  Project 2  Normal transforms  Euler angles  Quaternions.
MIT EECS 6.837, Durand and Cutler Graphics Pipeline: Projective Transformations.
Data Structures for Scenes, The Basics of Scene Graphs Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday,
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Shadows via Projection Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 5, 2003.
Lecture 6: 3D graphics Concepts 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 
More on Advanced Interfaces, Image Basics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, November 21, 2003.
Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Lecture 19 of 42 William H. Hsu.
1 Computer Graphics Week9 -3D Geometric Transformation.
Computer Graphics Bing-Yu Chen National Taiwan University.
Computer Graphics I, Fall 2010 Computer Viewing.
More on Drawable Objects, Hierarchical Objects Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, January.
Lighting Review & Example Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
Advanced Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 31, 2003.
2 COEN Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Lecture 3 Transformations. 2D Object Transformations The functions used for modifying the size, location, and orientation of objects or of the camera.
The Camera Analogy ► Set up your tripod and point the camera at the scene (viewing transformation) ► Arrange the scene to be photographed into the desired.
Introduction to Computer Graphics: Viewing Transformations Rama C
Introduction to Input/Interaction Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 19, 2003.
Viewing and Projection. The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation.
Selection Mode, Introduction to Widgets Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 6, 2003.
Some Notes on 3-D Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 24, 2003.
CS5500 Computer Graphics March 20, Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
3D Ojbects: Transformations and Modeling. Matrix Operations Matrices have dimensions: Vectors can be thought of as matrices: v=[2,3,4,1] is a 1x4 matrix.
Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.
- Introduction - Graphics Pipeline
Stenciling Effects Glenn G. Chappell
Camera Position (5.6) we specify the position and orientation of the camera to determine what will be seen. use gluLookAt (eye x, y, z, at x, y, z, up.
Summary of Properties of 3D Affine Transformations
CSCE 441 Computer Graphics 3-D Viewing
CSC461: Lecture 20 Parallel Projections in OpenGL
CENG 477 Introduction to Computer Graphics
CS451Real-time Rendering Pipeline
Computer Graphics Imaging
Projection in 3-D Glenn G. Chappell
More on Widgets, Misc. Topics
Last Time Canonical view pipeline Projection Local Coordinate Space
CS5500 Computer Graphics April 24, 2006.
Preview of 3-D Graphics Glenn G. Chappell
Presentation transcript:

Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20, 2003

20 Oct 2003CS 3812 Note Friday we looked at some virtual- reality research projects. This is part of the class, and will be covered on the test. However, it is outside the normal flow of topics. I have no review slides on VR.

20 Oct 2003CS 3813 Review: Unit Vectors [1/2] A unit vector is a vector whose magnitude is 1. We use unit vectors to represent quantities that have only direction. To find the unit vector pointing in the same direction as a given vector, divide the given vector by its magnitude. That is, given v, the unit vector pointing in the same direction is v/|v| = (1/|v|)v. Unit vectors are convenient when dealing with angles. If u and v are unit vectors, then the cosine of the angle between u & v is just u · v.

20 Oct 2003CS 3814 Review: Unit Vectors [2/2] Example Find a unit vector with the same direction as the vector (1, 2, 3). Solution: The magnitude of this vector is sqrt[ ] = sqrt[14]. Multiply: (1/sqrt[14])(1, 2, 3) = (1/sqrt[14], 2/sqrt[14], 3/sqrt[14]).

20 Oct 2003CS 3815 Review: Matrices & Transformations [1/3] We can use 33 matrices to represent some kinds of 3-D transformations: All rotations (about any line through the origin). All scaling. We apply the transformation to a point by using matrix multiplication. Matrix  point = transformed point.

20 Oct 2003CS 3816 Review: Matrices & Transformations [2/3] Example 1 What 33 matrix represents the transformation produced by: glScaled(2., 1., 1.); Solution: Note: This is not the actual matrix produced by this command. OpenGL does not use 33 matrices. Example 2 Apply the above transformation to the point (2, 3, 5) using matrix multiplication.

20 Oct 2003CS 3817 Review: Matrices & Transformations [3/3] We cannot represent translations in this way. Translations move the origin (0, 0, 0). Except for the do-nothing (identity) translation, which leaves all points alone. But matrix multiplication always leaves the origin alone. So, this method of representing transformations is not the one we want. How can we represent transformations in a more general way? In order to solve this, we need to alter the way we represent points & vectors. Next we look at “homogeneous form”.

20 Oct 2003CS 3818 Homogeneous Form: What Is It? OpenGL (along with other CG libraries) represents points and vectors internally using not 3 coordinates, but 4. Make the 4 th coordinate (“w”) a 1 to get the internal representation. This is called homogeneous form. For example, glVertex3d(4., 5., 6.); would result in (4, 5, 6, 1) being sent through the pipeline. We allow other values besides 1 in the 4 th coordinate. Divide x, y, and z by w in order to find the point or vector represented. For example, (4, 5, 6, 2) would be a homogeneous representation for (4/2, 5/2, 6/2) = (2, 2.5, 3). But (4, 5, 6, 1) represents (4/1, 5/1, 6/1) = (4, 5, 6), as above.

20 Oct 2003CS 3819 Homogeneous Form: What Is It Good For? Using homogenous form allows many kinds of transformations to be represented in a common form: Translation. Rotation. Scaling. Orthogonal projection. Perspective projection. We represent all of these using 44 matrices.

20 Oct 2003CS Homogeneous Form: Transformations [1/3] If a 3-D transformation can be represented as a 33 matrix (like rotation & scaling), then we make a 44 matrix for it as follows:

20 Oct 2003CS Homogeneous Form: Transformations [2/3] Other transformations are represented in other ways. Here is how we do translation: The code glLoadIdentity(); glTranslated( a, b, c ); generates the matrix:

20 Oct 2003CS Homogeneous Form: Transformations [3/3] We perform the transformations by using matrix multiplication, as before. Matrix multiplication cannot move (0, 0, 0, 0), as before. However, we now represent the origin in homogenous form as (0, 0, 0, 1). Remember, we may have to divide by the 4 th coordinate when we are done. This will not be an issue until we get talk about how to represent perspective projection. Try it!

20 Oct 2003CS Homogenous Form: The “Punch Line” If matrix multiplication is used for performing transformations, then multiplying two transformation matrices together results in the matrix representing one transformation followed by the other. Thus, we can use a 44 matrix to represent, not only a single transformation, but any series of transformations. What the transformation commands ( glTranslate *, glRotate *, glScale *) really do is to multiply the current matrix, on the left, by the matrix for the given transformation. This is why we need glLoadIdentity.

20 Oct 2003CS Introduction to 3-D Graphics: Three Issues Remember the three issues in 3-D CG: Viewing and Transformations This is what we are concentrating on now. Hidden-Surface Removal Easy-to-use depth buffering is built into OpenGL. Other methods are tricky … Lighting This will come later.

20 Oct 2003CS Introduction to 3-D Graphics: Example Code In class, we looked at a preliminary version of start3d.cpp and modified it. No further slides were shown in class. The following slides summarize the topics covered. The file start3d.cpp is now on the web page. It is intended to be a starting point for 3-D programs.

20 Oct 2003CS Introduction to 3-D Graphics: Double Buffering Nearly all of your 3-D programs will be double buffered. Drawing in the back buffer, and then swapping, means users see only completed frames. Result: smooth animation. This topic is review, of course. How to Do It Use GLUT_DOUBLE in your glutInitDisplayMode call. This allocates a back buffer and enables it for drawing. Maybe double buffering will work using GLUT_SINGLE. Maybe not. In any case, don’t do it. Use glutSwapBuffers instead of glFlush at the end of your display routine.

20 Oct 2003CS Introduction to 3-D Graphics: HSR with the Depth Buffer To draw 3-D scenes, hidden-surface removal is required. HSR is a complex topic. However … OpenGL includes a simple, easy-to-use, general-purpose HSR method: depth buffering. This method is memory intensive. That was once a major issue. How to Do It Use GLUT_DEPTH in your glutInitDisplayMode call. This allocates a depth buffer. Enable the depth test with “ glEnable(GL_DEPTH_TEST); ” You can do this in your initialization. You may wish to do some drawing without the depth test. In that case, you can enable & disable in the display function. Clear the depth buffer, using GL_DEPTH_BUFFER_BIT in glClear. When this happens depends on what you want to achieve. Typically, you clear the depth buffer when you clear the color buffer.

20 Oct 2003CS Introduction to 3-D Graphics: Perspective Projection [1/2] So far, we have used only orthogonal projection. In 3-D, we usually use perspective projection. Distant objects appear small, just as in the real world. To set up a perspective projection, replace gluOrtho2D with glFrustum. The viewpoint ( “eye”) is at (0,0,0), looking in the –z direction. Now we have near and far clipping planes. Think of the screen as lying on the near clipping plane. So you look through the screen at the scene. Objects in front of the screen cannot be seen. Objects behind the far plane also cannot be seen. The left, right, bottom, top parameters set up the coordinate system on the near plane.

20 Oct 2003CS Introduction to 3-D Graphics: Perspective Projection [2/2] Function glFrustum has 6 parameters: left, right: just as with gluOrtho2D. bottom, top: just as with gluOrtho2D. near, far: The distance to the near & far clipping planes. So near = 1, means that the near clipping plane lies at z = –1. Remember: The left, right, bottom, top parameters set up the coordinate system on the near plane. In 3-D it is easy to put things where you cannot see them. In particular, you cannot see objects at the origin. But you still want to draw things with their center at the origin. This makes rotation work well, for example. Solution: translate. For example, “ glTranslated(0., 0., -4.); ”. GLU includes the function gluPerspective. This is an alternate way to set up a perspective projection. It calls glFrustum. See the doc’s.

20 Oct 2003CS Introduction to 3-D Graphics: Drawing 3-D Objects Serious 3-D graphics always involves lighting. But we have not covered lighting yet. One solution: Draw the faces of your objects in different colors. When we get to lighting, we will distinguish between the “front” and “back” sides of a polygon. These can be lit differently. The front side of a polygon drawn with GL_TRIANGLES, GL_QUADS, or GL_POLYGON is the one on which the vertices appear in counterclockwise order. Front or back makes no difference yet. However, drawing objects so that all polygons are front-side-out is a good habit to get into. Draw your objects so that they are centered at the origin. To make them to appear somewhere else, use transformations.

20 Oct 2003CS Introduction to 3-D Graphics: Transformations For now, we generally do our transformations in the display function. Remember: Do glPushMatrix. Do transformations. Order: translate, then rotate, then scale. Draw the objects that are to be affected by the transformations. Do glPopMatrix. Using glRotate *, we can rotate about any line through the origin. For example, “ glRotated( theta, 1.,2.,3.); ” rotates through theta degrees about the line through the points (0, 0, 0) and (1, 2, 3).