The light at the end of the tunnel is the headlight of an approaching train. Concept 1.11: Theory of Transformations ====================================== Idea: ===== OpenGL maintains two matrix stacks that it uses for rendering. These are the modelview and projection matrices. Shown above are the matrix modes (in red), the identity matrix and the transformation commands (in blue). glMatrixMode(GLenum mode); specifies whether the modelview or projection matrix is to be modified, using the arguement GL_MODELVIEW, GL_PROJECTION. We use the glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands. Typically, you will call this command before specifying projection or viewing transformations but you might also call it before specifying a modelling transformation. Effect of Transformations on Matrix Stacks ========================================== Look at the reshape() func where the projection matrix gets modified. Load Identity Matrix (I) I Load Projection Matrix (P0) I*P0 = P0 Now change the matrix mode to modelview by calling glMatrixMode(GL_MODELVIEW); Lets look at the display() func where the modelview matrix is further modified. Load Identity Matrix (I) I LookAt (M0) I*M0 = M0 Translate along the y axis (M1) M0*M1 Rotate about x axis (M2) M0*M1*M2 Translate along z axis (M3) M0*M1*M2*M3 Scale the object (M4) M0*M1*M2*M3*M4 draw vertex at [a, b, c] M0*M1*M2*M3*M4*[a,b,c] The matrices now get applied to the object in reverse order because of the rules of matrix multiplication. Final transformed object is obtained as follows M0 * (M1 * (M2 * (M3 * (M4 * [a b c] ) ) ) ) This gives the vertices of the object in 3D space. Our screen is 2D. Hence the mapping occurs by multiplying the object coordinates by the projection matrix P0 from above. 2D coordinates [a,b] = P*(M0*(M1*(M2*(M3*(M4[a,b,c]))))) We will discuss the gluLookAt() command and the projection command gluPerspective in future concepts.