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
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
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
Composition of transformations example: rotate 90 degrees, then 180 degrees follow a vector do the matrix multiplication
reflection Come up with a matrix for reflection across the y axis
reflection as scaling reflection across the y axis is scaling by -1 in x and 1 in y.
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.
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 )
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
3D 3x3 matrices 3 coordinates for vectors and points
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
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!
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
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
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
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
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.
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.
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:
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!
Book has lots of experiments with composition - run them with understanding!
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
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);
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".
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);