Presentation is loading. Please wait.

Presentation is loading. Please wait.

2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric.

Similar presentations


Presentation on theme: "2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric."— Presentation transcript:

1

2 2 COEN 290 - 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 3 COEN 290 - 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 4 COEN 290 - 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 5 COEN 290 - Computer Graphics I Translation n Move the origin to a new location

6 6 COEN 290 - Computer Graphics I glTranslate[fd]() glTranslatef( t x, t y, t z );

7 7 COEN 290 - 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 8 COEN 290 - Computer Graphics I glScale[fd]() glScalef( s x, s y, s z );

9 9 COEN 290 - 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 10 COEN 290 - Computer Graphics I glRotate[fd]() glRotatef( angle, x, y, z ); M

11 11 COEN 290 - Computer Graphics I Some Additional Rotation Examples

12 12 COEN 290 - Computer Graphics I Shear n Scaling in one dimension depends on another n For example n No OpenGL command load custom matrix

13 13 COEN 290 - Computer Graphics I Shear n Making a shear matrix

14 14 COEN 290 - 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 15 COEN 290 - Computer Graphics I OpenGL Matrix Format GLfloat m[16];

16 16 COEN 290 - 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 17 COEN 290 - 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 18 COEN 290 - 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 19 COEN 290 - 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 20 COEN 290 - 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 21 COEN 290 - Computer Graphics I A Stack Based Solution ( cont. ) Projection Transformation Modeling Transformations

22 22 COEN 290 - 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 23 COEN 290 - 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 24 COEN 290 - 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 25 COEN 290 - 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 26 COEN 290 - 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 27 COEN 290 - Computer Graphics I The Simplest Viewing Transform n “Push” the origin into the viewing frustum near far

28 28 COEN 290 - 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 29 COEN 290 - 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 30 COEN 290 - Computer Graphics I Creating an Orthonormal Basis

31 31 COEN 290 - 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 32 COEN 290 - 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 33 COEN 290 - 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 34 COEN 290 - 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


Download ppt "2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric."

Similar presentations


Ads by Google