1 / 34

Evening’s Goals

Evening’s Goals. Discuss viewing and modeling transformations Describe matrix stacks and their uses Show basic geometric rasterization and clipping algorithms. Modeling Objects. Recall objects are composed of geometric primitives each primitive is composed of vertices.

zea
Download Presentation

Evening’s Goals

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Evening’s Goals • Discuss viewing and modeling transformations • Describe matrix stacks and their uses • Show basic geometric rasterization and clipping algorithms COEN 290 - Computer Graphics I

  2. Modeling Objects • Recall objects are composed of geometric primitives • each primitive is composed of vertices • Model around the origin • model just means “determine an object’s vertices” COEN 290 - Computer Graphics I

  3. Modeling Transformations • Position objects in world coordinates • Move coordinate systems, not objects • Affects all objects rendered after transformation • Types • translation • scale • rotation • shear COEN 290 - Computer Graphics I

  4. Translation • Move the origin to a new location COEN 290 - Computer Graphics I

  5. glTranslate[fd]() glTranslatef( tx, ty, tz ); COEN 290 - Computer Graphics I

  6. Scale • Stretch, mirror or decimate a coordinate direction Note, there’s a translation applied here to make thingseasier to see COEN 290 - Computer Graphics I

  7. glScale[fd]() glScalef( sx, sy, sz ); COEN 290 - Computer Graphics I

  8. Rotation • Rotate coordinate system about an axis in space Note, there’s a translation applied here to make thingseasier to see COEN 290 - Computer Graphics I

  9. glRotate[fd]() glRotatef( angle, x, y, z ); M COEN 290 - Computer Graphics I

  10. Some Additional Rotation Examples COEN 290 - Computer Graphics I

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

  12. Shear • Making a shear matrix COEN 290 - Computer Graphics I

  13. Other OpenGL Matrix Commands • glMultMatrix( m ) • multiples the current matrix by m • glLoadMatrix( m ) • replaces the current matrix by m • glLoadIdentity() • replace the current matrix with an identity matrix COEN 290 - Computer Graphics I

  14. OpenGL Matrix Format GLfloat m[16]; COEN 290 - Computer Graphics I

  15. Modeling Transforms and our Pipeline World Coordinates Eye Coordinates ClipCoordinates NDC’s Model Coordinates Perspective Divide ModelingTransformations ProjectionTransformation COEN 290 - Computer Graphics I

  16. Using Multiple Modeling Transforms • Multiple modeling transforms form a composite modeling transform • Individual transform matrices are multiplied together • for example COEN 290 - Computer Graphics I

  17. Multiplying Matrices • Matrix multiplication is not commutative • in general, • order of operations is important • OpenGL multiples matrices on the right COEN 290 - Computer Graphics I

  18. Independent vs. Dependent Transforms • Every modeling transform affects the model coordinate system • Transformations accumulate • we record every transformation every made • to undo a transform, we’d need to do the inverse transform • this is very inconvenient COEN 290 - Computer Graphics I

  19. A Stack Based Solution • We create a stack containing matrices • Any transform multiples the top of stack • Push makes a copy and pushes it onto the stack • Pop discards the top of stack COEN 290 - Computer Graphics I

  20. ModelingTransformations A Stack Based Solution ( cont. ) ProjectionTransformation COEN 290 - Computer Graphics I

  21. OpenGL Matrix Stack Commands • Top of stack matrix is called the current matrix • glPushMatrix() • copy the current matrix and pushes it • glPopMatrix() • pop the current matrix COEN 290 - Computer Graphics I

  22. OpenGL Matrix Stacks • Why multiple matrix stacks? • certain techniques are done in different spaces glMatrixMode( mode ) • choose which stack to manipulate • GL_MODELVIEW • GL_PROJECTION COEN 290 - Computer Graphics I

  23. Model Coordinates Model Coordinates Model Coordinates Current Transformation Pipeline World Coordinates Eye Coordinates ClipCoordinates NDC’s Perspective Divide ProjectionTransformation ModelingTransformations COEN 290 - Computer Graphics I

  24. Eye coordinates are nice, but ... • Eye coordinates are restrictive • eye’s positioned at the origin • looking down the -z axis • What if we want to look at the scene from somewhere else? • use a viewing transformation COEN 290 - Computer Graphics I

  25. Viewing Transformations • Reorient world coordinates to match eye coordinates • Basically just a modeling transform • affects the entire scene • usually a translation and a rotation • Usually set up after the projection transform, but before any modeling transforms COEN 290 - Computer Graphics I

  26. The Simplest Viewing Transform • “Push” the origin into the viewing frustum near far COEN 290 - Computer Graphics I

  27. polarview() • 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 COEN 290 - Computer Graphics I

  28. Transforming World to Eye Coordinates • Viewing transform gluLookAt( eyex, eyey, eyez, lookx, looky, lookz, upx, upy, upz ); • Creates an orthonormal basis • a set of linearly independent vectors of unit length COEN 290 - Computer Graphics I

  29. Creating an Orthonormal Basis COEN 290 - Computer Graphics I

  30. gluLookAt( eyex, eyey, eyez, lookx, looky, lookz, upx, upy, upz ){ /* Create matrix m */ glMultMatrixf( m ); glTranslatef( -eyex, -eyey, -eyez );} COEN 290 - Computer Graphics I

  31. Model Coordinates Model Coordinates Model Coordinates Our Final Transformation Pipeline ViewingTransformation World Coordinates Eye Coordinates ClipCoordinates NDC’s Perspective Divide ProjectionTransformation ModelingTransformations COEN 290 - Computer Graphics I

  32. Retrieving Matrix information GLfloat m[16]; glGetFloatv( which, m ); • which is which matrix stack to access • GL_MODELVIEW_MATRIX • GL_PROJECTION_MATRIX COEN 290 - Computer Graphics I

  33. Putting it all Together • General flow of transformations • projection transformation • viewing transformation • push matrix • modeling transformation • render • pop matrix • goto  as necessary COEN 290 - Computer Graphics I

More Related