1 / 30

Understanding Modeling Transformations for 3D Objects

Learn about rotation, scaling, and translation in 3D modeling using OpenGL utilities. Experiment with multiple rotations, order of transformations, and projection and modelview matrices. Practice composing transformations and placing multiple objects in a 3D scene.

hmcelroy
Download Presentation

Understanding Modeling Transformations for 3D Objects

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. Chapter 4/5 glMatrixMode Modeling Transformations glTranslate quick look at glPushMatrix and glPopMatrix glScale reflection glRotate composing transformations placing multiple objects

  2. MJBBasicTransformations.cpp • Notice display list for createshape • note use of glPushMatrix() and glPopMatrix for isolating transformations for stroke text and transformed shape.

  3. MJBBasicTransformations.cpp • rotation • scaling • translation

  4. Multiple rotation experiment • work in pairs: • Both, place book face up so you can read it. • Person 1, rotate 90 degrees around z-axis, then rotate 180 degrees around y axis. • Person 2, rotate 180 degrees around y axis, then rotate 90 degrees around z-axis. • Compare.

  5. Multiple rotation experiment Conclusions: Order Matters!

  6. PROJECTION and MODELVIEW Matrices • GL_MODELVIEW is for organizing the pieces of the picture - building the model. • GL_PROJECTION is for setting viewing box and type of projection for viewing.

  7. PROJECTION and MODELVIEW Matrices • GL_MODELVIEW is for organizing the pieces of the picture - building the model. • drawing: glBegin, glutSphere,.... • GL_PROJECTION is for setting viewing box and type of projection for viewing. • glOrtho, glFrustum

  8. PROJECTION and MODELVIEW Matrices • Both matrices are alway active and being used. • We can only change or set one at a time. • To modify one we have to put it in the "matrix modifying machine", eg • glMatrixMode(GL_PROJECTION); • glMatrixMode(GL_MODELVIEW);

  9. PROJECTION and MODELVIEW Matrices • To make sure we start with a clean slate: glLoadIdentity(); • Any new changes are made to the matrix that is currently "in Mode". • The current state of both is used for whatever is being drawn.

  10. PROJECTION Matrix glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho... or glFrustum... This is usually in resize routine, but it can be modified in display routine. Remember to then return to the MODELVIEW matrix, glMatrixMode(GL_MODELVIEW);

  11. Modeling Transformations • Run box.cpp • In resize: glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-5.0, 5.0, -5.0, 5.0, 5.0, 100.0); glMatrixMode(GL_MODELVIEW);

  12. box.cpp • in drawScene glLoadIdentity(); // Modeling transformations. glTranslatef(0.0, 0.0, -15.0); glutWireCube(5.0); // Box. //A 5x5 cube, centered at the origin

  13. Moving the box into view

  14. glTranslatef( p, q, r) • translate (x,y,z) to (x+p,y+q,z+r); • Reminder - away from your eye is NEGATIVE z direction.

  15. boxWPushPop.cpp //Apply glTranslatef only to glutWireCube glPushMatrix(); glTranslatef(0.0, 0.0, -15.0); glutWireCube(5.0); // Box. glPopMatrix();

  16. boxV2.cpp //Modeling Transformations glTranslatef(0.0, 0.0, -15.0); ... glScalef(.7,2.0,3.0); Run boxV2.cpp

  17. boxV2.cpp Black box is • First scaled (while at the origin) • Then translated.

  18. glScalef(u,v,w); maps (x, y, z) of an object to (u*x, v*y, w*z)

  19. Reflection • glScale(1.0, -1.0, 1.0); • Run boxV3.cpp. press m to see before and after reflection. Notice toggle.

  20. boxV4.cpp //Modeling Transformations glTranslatef(0.0, 0.0, -15.0); ... glRotatef(60.0, 0.0,0.0,1.0); glutWireTeapot(3.0); Run and look at boxV4.cpp

  21. boxV4.cpp glRotatef(60.0, 0.0,0.0,1.0); Counterclockwise rotation looking from • origin to (0,0,1) or • (0,0,1) to origin?

  22. boxV4.cpp glRotatef(60.0, 0.0,0.0,1.0); Counterclockwise rotation looking from • origin to (0,0,1) or • (0,0,1) to origin?

  23. glRotatef(A, p, q, r) • rotate around the vector (p, q, r) • A is the angle • in degrees, counterclockwise • looking from the point (p, q, r) toward the origin

  24. Transformations • Run the experiments in the book. Think through the answer before you run it.

  25. Composing Transformations • run boxV5.cpp, draw on board • Key input t: glTranslatef(10.0,0.0,0.0); glRotatef(45.0, 0.0,0.0,1.0); glutWireCube(5.0); • Key input r: glRotatef(45.0, 0.0,0.0,1.0); glTranslatef(10.0,0.0,0.0); glutWireCube(5.0);

  26. Placing multiple objects • Do experiment with Powerpoint:

  27. Trotate.cpp //Modeling Transformations glTranslatef(0.0, 0.0, -15.0); ... glRotatef(60.0, 0.0,0.0,1.0); glBegin(GL_LINES); glVertex3f(0, 0, 0); glVertex3f(3, 0, 0); glVertex3f(3, -1, 0); glVertex3f(3, 1, 0); glEnd(); Run and look at Trotate.cpp

  28. boxV6.cpp • original - a box and a sphere • draw on board • m: translate together • o: say translate then rotate, but really rotate then translate • Check out the code! • try ortho and frustrum

  29. pushPopDemo.cpp Any transformations (rotate,translate, scale) put inside a glPushMatrix() and a glPopMatrix() pair are ignored outside that pair. Other statements (color, draw something,...) are NOT ignored

  30. pushPopDemo.cpp Any transformations (rotate,translate, scale) put inside a glPushMatrix() and a glPopMatrix() pair are ignored outside that pair. Other statements (color, draw something,...) are NOT ignored

More Related