You should read the book and lecture notes on matrix manipulation then go through this exercise.
The transformation matrices were covered in the lecture. Generally, they are 4x4 matrices that repersent the transformations (translations, scaling or rotations). The transformation matrix is multiplied by the co-ordinates of the vertices of the objects in the scene to achieve the transformation.
The lecture notes detail the construction of the transormation matrices and the homogenous co-ordinate that makes them 4x4. If you have any questions about this, please ask.
This exercise is aimed at getting you used to the effects of transformations and how they are achieved within OpenGL
//red triangle in upper right
glBegin(GL_POLYGON);
glColor3f( red, green, blue );
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glVertex3f(1.5, 1.0, 0.0);
glEnd();
//red triangle in upper right
//It has the same coordinate values as the basic triangle in
//the above drawTriangle() function. The drawTriangle(r, g, b)
//function takes the rgb values as parameters.
drawTriangle(1, 0, 0);
//green triangle in upper left
//need to translate this 1.5 units
// to the left of the red triangle
glTranslatef(-1.5, 0.0, 0.0);
drawTriangle(0, 1, 0);
//blue triangle in lower left
//need to translate this 1.5 units
// down from the green triangle
glTranslatef(0.0, -1.5, 0.0);
drawTriangle(0, 0, 1);
//yellow triangle in lower right
//need to translate this 1.5 units
// right from the blue triangle
glTranslatef(1.5, 0.0, 0.0);
drawTriangle(1, 1, 0);
//load the identity matrix onto the current matrix in the
//stack to ensure all transformations are relative to the origin.
glLoadIdentity();
//red triangle in upper right
// - which has it's lower vertex at the origin
glPushMatrix();
drawTriangle(1, 0, 0);
glPopMatrix();
//green triangle in upper left
//need to translate this 1.5 units
// to the left of the red triangle/origin
glPushMatrix();
glTranslatef(-1.5, 0.0, 0.0);
drawTriangle( 0, 1, 0 );
glPopMatrix();
//blue triangle in lower left
//need to translate this 1.5 units down
// and 1.5 units left of the red triangle/origin
glPushMatrix();
glTranslatef(-1.5, -1.5, 0.0);
drawTriangle( 0, 0, 1 );
glPopMatrix();
//yellow triangle in lower right
//need to translate this 1.5 units down
// from the red triangle/origin
glPushMatrix();
glTranslatef(0.0, -1.5, 0.0);
drawTriangle( 1, 1, 0 );
glPopMatrix();
Useful References
OpenGL Programming Guide
(The Red Book).
OpenGL Index in Alphabetic Order
(This is pretty long)
The OpenGL Website - tutorials
Contact me
email: pj@cpsc.ucalgary.ca
Tel: (403) 220 7041.