Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapters 5/4 part2 understanding transformations working with matrices

Similar presentations


Presentation on theme: "Chapters 5/4 part2 understanding transformations working with matrices"— 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

12 operations on homogeneous coordinates
You can add vectors: [ ]T + [ ]T = [ ]T, a vector. You can NOT add points [ ]T + [ ]T = [ ]T, not a point!

13 operations on homogeneous coordinates cont.
You CAN add a vector to a point: [ ]T + [ ]T = [ ]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

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

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

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:

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


Download ppt "Chapters 5/4 part2 understanding transformations working with matrices"

Similar presentations


Ads by Google