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 rasterization and clipping algorithms
3 COEN Computer Graphics I Modeling Objects n Recall objects are composed of geometric primitives each primitive is composed of vertices n Model around the origin model just means “determine an object’s vertices”
4 COEN Computer Graphics I Modeling Transformations n Position objects in world coordinates n Move coordinate systems, not objects n Affects all objects rendered after transformation n Types translation scale rotation shear
5 COEN Computer Graphics I Translation n Move the origin to a new location
6 COEN Computer Graphics I glTranslate[fd]() glTranslatef( t x, t y, t z );
7 COEN Computer Graphics I Scale n Stretch, mirror or decimate a coordinate direction Note, there’s a translation applied here to make things easier to see
8 COEN Computer Graphics I glScale[fd]() glScalef( s x, s y, s z );
9 COEN Computer Graphics I Rotation n Rotate coordinate system about an axis in space Note, there’s a translation applied here to make things easier to see
10 COEN Computer Graphics I glRotate[fd]() glRotatef( angle, x, y, z ); M
11 COEN Computer Graphics I Some Additional Rotation Examples
12 COEN Computer Graphics I Shear n Scaling in one dimension depends on another n For example n No OpenGL command load custom matrix
13 COEN Computer Graphics I Shear n Making a shear matrix
14 COEN Computer Graphics I Other OpenGL Matrix Commands n glMultMatrix( m ) multiples the current matrix by m n glLoadMatrix( m ) replaces the current matrix by m n glLoadIdentity() replace the current matrix with an identity matrix
15 COEN Computer Graphics I OpenGL Matrix Format GLfloat m[16];
16 COEN Computer Graphics I Modeling Transforms and our Pipeline World Coordinates Eye Coordinates Clip Coordinates NDC’s Perspective Divide Projection Transformation Model Coordinates Modeling Transformations
17 COEN Computer Graphics I Using Multiple Modeling Transforms n Multiple modeling transforms form a composite modeling transform n Individual transform matrices are multiplied together for example
18 COEN Computer Graphics I Multiplying Matrices n Matrix multiplication is not commutative in general, order of operations is important n OpenGL multiples matrices on the right
19 COEN Computer Graphics I Independent vs. Dependent Transforms n Every modeling transform affects the model coordinate system n Transformations accumulate we record every transformation every made to undo a transform, we’d need to do the inverse transform –this is very inconvenient
20 COEN Computer Graphics I A Stack Based Solution n We create a stack containing matrices n Any transform multiples the top of stack n Push makes a copy and pushes it onto the stack n Pop discards the top of stack
21 COEN Computer Graphics I A Stack Based Solution ( cont. ) Projection Transformation Modeling Transformations
22 COEN Computer Graphics I OpenGL Matrix Stack Commands Top of stack matrix is called the current matrix n glPushMatrix() copy the current matrix and pushes it n glPopMatrix() pop the current matrix
23 COEN Computer Graphics I OpenGL Matrix Stacks n Why multiple matrix stacks? certain techniques are done in different spaces glMatrixMode( mode ) choose which stack to manipulate –GL_MODELVIEW –GL_PROJECTION
24 COEN Computer Graphics I Current Transformation Pipeline World Coordinates Eye Coordinates Clip Coordinates NDC’s Perspective Divide Projection Transformation Model Coordinates Model Coordinates Model Coordinates Modeling Transformations
25 COEN Computer Graphics I Eye coordinates are nice, but... n Eye coordinates are restrictive eye’s positioned at the origin looking down the -z axis n What if we want to look at the scene from somewhere else? use a viewing transformation
26 COEN Computer Graphics I Viewing Transformations n Reorient world coordinates to match eye coordinates n Basically just a modeling transform affects the entire scene usually a translation and a rotation n Usually set up after the projection transform, but before any modeling transforms
27 COEN Computer Graphics I The Simplest Viewing Transform n “Push” the origin into the viewing frustum near far
28 COEN Computer Graphics I polarview() n Useful if you want to view an entire object polarview( dist, elev, azim, twist ) { glTranslatef( 0, 0, -dist ); glRotatef( -twist, 0, 0, 1 ); glRotatef( -elev, 1, 0, 0 ); glRotatef( azim, 0, 0, 1 ); } update elev and azim for interactive viewing
29 COEN Computer Graphics I Transforming World to Eye Coordinates n Viewing transform gluLookAt( eye x, eye y, eye z, look x, look y, look z, up x, up y, up z ); n Creates an orthonormal basis a set of linearly independent vectors of unit length
30 COEN Computer Graphics I Creating an Orthonormal Basis
31 COEN Computer Graphics I gluLookAt( eye x, eye y, eye z, look x, look y, look z, up x, up y, up z ) { /* Create matrix m */ glMultMatrixf( m ); glTranslatef( -eye x, -eye y, -eye z ); }
32 COEN Computer Graphics I Our Final Transformation Pipeline World Coordinates Eye Coordinates Clip Coordinates NDC’s Perspective Divide Projection Transformation Viewing Transformation Model Coordinates Model Coordinates Model Coordinates Modeling Transformations
33 COEN Computer Graphics I Retrieving Matrix information GLfloat m[16]; glGetFloatv( which, m ); n which is which matrix stack to access GL_MODELVIEW_MATRIX GL_PROJECTION_MATRIX
34 COEN Computer Graphics I Putting it all Together n General flow of transformations À projection transformation Á viewing transformation  push matrix à modeling transformation Ä render Å pop matrix Å goto as necessary