1 / 25

Exploring Matrix Transformations for 2D and 3D Graphics

Learn about composition of transformations, homogeneous coordinates, operations on vectors, and matrix multiplication for rotations, scaling, and translations in 2D and 3D graphics with examples and experiments.

yeagerm
Download Presentation

Exploring Matrix Transformations for 2D and 3D Graphics

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. Chapters 5/4 part2 understanding transformations working with matrices composition of transformations homogeneous coordinates operations on points and vectors rotation, scaling, and translation as matrices

  2. Multiplying matrices • on the board 2d • two 2x2 square matrices • a 2x2 matrix times a vector • figuring out matrices for rotation and scaling • figure out matrix for translation

  3. Multiplying matrices • on the board 2d • two 2x2 square matrices • a 2x2 matrix times a vector • figuring out matrices for rotation and scaling • no 2x2 matrix for translation

  4. Composition of transformations • example: rotate 90 degrees, then 180 degrees • follow a vector • do the matrix multiplication

  5. reflection • Come up with a matrix for reflection across the y axis

  6. reflection as scaling • reflection across the y axis is scaling by -1 in x and 1 in y.

  7. Rotation and reflection experiment • work in pairs: • On paper, draw axes and vector (2, 1)T • Person 1, rotate 90 degrees, then reflect across y axis. • Person 2, reflect across y axis, then rotate 90 degrees. • Compare.

  8. Figure out order of multiplication • F is reFlection across y axis • T is roTation of 90 degrees • Person 1, compute FT, • Person 2, compute TF • Which one is rotation followed by reflection? (Apply to (2,1)T )

  9. Figure out order of multiplication • F is reFlection across y axis • T is roTation of 90 degrees • Person 1, compute FT, • Person 2, compute TF • Which one is rotation followed by reflection? (Apply to (2,1)T ) • Answer: FT

  10. 3D • 3x3 matrices • 3 coordinates for vectors and points

  11. homogeneous coordinates x y z 1 • [ x y z 1]T = for a point. • [ x y z 0]T = for a vector. x y z 0

  12. operations on homogeneous coordinates • You can add vectors: [ 2 3 4 0 ]T + [ 1 1 1 0]T = [ 3 4 5 0]T, a vector. • You can NOT add points [ 2 3 4 1 ]T + [ 1 1 1 1]T = [ 3 4 5 2]T, not a point!

  13. operations on homogeneous coordinates cont. • You CAN add a vector to a point: [ 2 3 4 1 ]T + [ 1 1 1 0]T = [ 3 4 5 1]T, another point. p+v v p

  14. rotation in homogeneous coordinates: Rotation about the z-axis: cos(θ) -sin(θ) 0 0 sin(θ) cos(θ) 0 0 0 0 1 0 0 0 0 1

  15. scaling in homogeneous coordinates: Scaling 3 in x, 2 in y, 4 in z; 3 0 0 0 0 2 0 0 0 0 4 0 0 0 0 1

  16. TRANSLATING in homogeneous coordinates: moving 3 in x, 2 in y, 4 in z directions; 1 0 0 3 a a+3 0 1 0 2 b = b+2 0 0 1 4 c c+4 0 0 0 1 1 1

  17. 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.

  18. PROJECTION and MODELVIEW Matrices • Both matrices are alway active and being used. • A point (vertex) is multiplied by the MODELVIEW matrix to place it in our scene • then the result is multiplied by the PROJECTION matrix to project it to the front of the viewing box.

  19. Composing Transformations • run boxV5.cpp • 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);

  20. Why reversed? • key input t: • Model view matrix starts as I • Call translate multiplies IT • Call rotate multiplies ITR • Draw cube multiplies ITRv for every point v of the cube. • This applies R first, not T!

  21. Book has lots of experiments with composition - run them with understanding!

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

  23. PROJECTION and MODELVIEW Matrices • 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);

  24. PROJECTION and MODELVIEW Matrices • To make sure we start with a clean slate: glLoadIdentity(); - this sets it to the identity matrix. • Any new changes are made to the matrix that is currently "in Mode".

  25. 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);

More Related