1 / 17

Understanding OpenGL Transformations for Object Visualization

Learn the correct order of transformations in OpenGL to achieve accurate object visualization. Move the object in its local coordinate frame and let OpenGL perform the transformations in reverse order.

dunlapa
Download Presentation

Understanding OpenGL Transformations for Object Visualization

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. Wrong!!! Watch out!! • OpenGL post-multiplies each new transformation matrix M = M x Mnew • Example: perform translation, then rotation 0) M = Identity 1) translation T(tx,ty,0) -> M = M x T(tx,ty,0) 2) rotation R(q) -> M = M x R(q) 3) Now, transform a point P -> P’ = M x P = T(tx, ty, 0) x R(q) x P

  2. glTranslated(5,0,0); glRotate(60,0,0,1); glBegin() … glRotated(60,0,0,1); glTranslated(5,0,0); glBegin() Example Revisit • We want rotation first and then translation • Generate wrong results if you do: You need to specify the transformation in the opposite order!!

  3. How Strange … • OpenGL has its reason … • It wants you to think of transformation in a different way • Instead of thinking of transformation as moving the object in a fixed global coordinate system, you should think of transforming the object as moving (transforming) its local coordinate frame

  4. OpenGL Transformation • When use OpenGL, we need to think of object transformations as moving (transforming) its local coordinate frame • All the transformations are performed relative to the current local coordinate frame origin and axes

  5. Translate Coordinate Frame Translate (3,3)?

  6. Translate Coordinate Frame (2) Translate (3,3)?

  7. 30 degree Rotate Coordinate Frame Rotate 30 degree?

  8. Scale Coordinate Frame Scale (0.5,0.5)?

  9. Compose Transformations Transformations? • Answer: • Translate(7,9) • Rotate 45 • Scale (2,2) o 45 (7,9)

  10. o 60 (5,5) Another example How do you transform from C1 to C2? C1 C2 Translate (5,5) and then Rotate (60) OR Rotate (60) and then Translate (5,5) ??? Answer: Translate(5,5) and then Rotate (60)

  11. o o 60 60 Another example (cont’d) If you Rotate(60) and then Translate(5,5) … C2 C1 5 5 You will be translated (5,5) relative to C2!!

  12. Transform Objects • What does coordinate frame transformation have anything to do with object transformation? • You can view object transformation as fixing the object to the local coordinate frame and then move that coordinate frame

  13. o o 60 60 • Rotate ( ) • Translate (5,0) Example Old way: Transformation as moving the object relative to the origin of a global world coordinate frame (5,0)

  14. o o 60 60 (5,0) • Translate (5,0) • 2) Rotate ( ) Example (cont’d) If you think of transformations as moving the local coordinate frame Exact the opposite order compared to the previous slide!!

  15. o o 60 60 • Rotate ( ) - MR • Translate (5,0) - MT • P’ = MT x MR x P is the • Correct multiplication order So … If you think oftransformations as moving the object relative to the origin of a global world coordinate frame (5,0) However, OpenGL will do MR x MT x P if you call glRotate() first, and then glTranslate() because OpenGL does postmultiplication

  16. o o 60 60 So … (cont’d) If you think of transformations as moving the coordinate frame • Translate (5,0) - MT • 2) Rotate ( ) - MR (5,0) If you think in terms of moving coordinate frames, you will want to perform Translate first, and then Rotate (I.e., call glTranslate() first and then glRotate()) OpenGL will do MT x MR x P -> The correct multiplication order!!!

  17. Put it all together When you use OpenGL … • Think of transformation as moving the local coordinate frame • Call OpenGL transformation functions according to that order • OpenGL will actually perform the transformations in reverse order • Everything will be just right!!!

More Related