Suppose we wish to setup the following transformation:
M = trans(2,1,0) rot(z,-90) scale(2,2,2)One way of doing this:
glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glTranslatef(2.0, 1.0, 0.0); glRotatef( -90, 0.0, 0.0, 1.0); glScalef(2.0, 2.0, 2.0);Another way:
glMatrixMode( GL_MODELVIEW ); M[0][0] = 2; M[0][[1]= -1; ... glLoadMatrixf( M );Applying the transformation:
glBegin(GL_POLYGON); glVertex3fv( vertex_list[i] ); glVertex3f( x,y,z ); glVertex2f( x,y ); glEnd();
road with respect to the city car with respect to the road front left wheel with respect to the car front rt wheel with respect to the car rear left wheel with respect to the car rear rt wheel with respect to the car hub caps with respect to wheelsThese form a hierarchy of transformations, often called the scene graph. Going down the scene graph is simple -- performing a transformation relative to the current coordinate system simply requires postmultiplication of the current transformation matrix. However, we need a mechanism to return to previous coordinate systems. This is done in OpenGL with the help of a matrix stack and the commands glPushMatrix() and glPopMatrix().