130 likes | 202 Views
CS770/870. Class 4. Translation. Scale. 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.
E N D
CS770/870 Class 4
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.
The matrix stack glLoadIdentity(); M1 I glRotatef(); M1 IR1 glTranslatef(); M1 IR1T1 glScalef(); M1 IR1T1S1 glPushMatrix(); M2 M1 glTranslatef(); M2 M1T2 glPushMatrix(); M3 M2 M1 M1 M2 M1
The view window to viewport transformation In open GL As a set of matrixes
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 = (a1*b1 + a2*b2 + a3*b3) = |a||b|cos(q); |a| = Sqrt(a1*a1+ a2*a2+ a3*a3); a/|a| = a1/|a| + a2/|a| + a3/|a| // unit vector
Cross Product of two vectors a xb = (a1, a2, a3)T x (b1, b2, b3) The result is a vector = (a2 * b3) – (a3 * b2), (a3 * b1) – (a1 * b3), (a1 * b2) – (a2 * b1) If both vectors are unit vectors the result is at right angles to the plane running through the other two.