Multiplying Matrices. The R C rule What happens when we do two translates? What happens when we do two scales? What happens when we translate and scale, or scale then translate (Commutative?) Exercise
Matrices in GL virtual machine OpenGL maintains a matrix stack glPushMatrix() creates pushes a new 4x4 matrix on the top of the stack containing a copy of the existing top of stack matrix. glTranslate, glScale and glRotate cause a new matrix to be contructed and post multiplied by the top of the stack.
Derive rotation about z Take notes Rotations about x and y.
Exercise: do it by drawing Given a square glRectf(-1,-1,1,1) glRotatef(-30.0,0,0,1); glScalef(2.0,1.0,1.0); gLTranslatef(2.0,0.0,0.0); glRectf (-1,-1,1,1); glTranslatef(0.0,2.0,0.0); glScalef(1.0,2.0,1.0); glRotatef(45,0.0,0.0, 1.0); glRectf (-1,-1,1,1);
The Scene window to viewport mapping Scene window box (Lsw, Rsw, Bsw, Tsw) Viewport box (Lvp, Rvp, Bvp, Tvp); Exercise specify open gl commands to accomplish this) If time construct the matrix (Just the top row)
Some basic linear algebra (CH 4) Dot and Cross Product. A dot product of unit vectors gives the cosine of the angle between two unit vectors a. b = (a 1 *b 1 + a 2 *b 2 + a 3 *b 3 ) = |a||b|cos( |a| = Sqrt(a 1 *a 1 + a 2 *a 2 + a 3 *a 3 ); a/|a| = a 1 /|a| + a 2/ |a| + a 3 /|a| // unit vector
Cross Product of two vectors a x b = (a 1, a 2, a 3 ) T x (b 1, b 2, b 3 ) The result is a vector = (a 2 * b 3 ) – (a 3 * b 2 ), (a 3 * b 1 ) – (a 1 * b 3 ), (a 1 * b 2 ) – (a 2 * b 1 ) If both vectors are unit vectors the result is at right angles to the plane running through the other two.