As mentioned in class and labs the order of transformations are important. This example illustrates the differences in composing transformations. It also uses a display list (this is given below).
You should implement transformations and observe the difference in ordering them. Add one transformation at a time to observe cumulative effects.
glPushMatrix();
glRotatef(30, 0, 0, 1); //30 degrees around z
glTranslatef(-1.0, -0.5, 0.0);
glScalef(0.5, 0.5, 0.5);
glCallList( object ); //drawPattern
glPopMatrix();
glPushMatrix();
glRotatef(30, 0, 0, 1);
glScalef(0.5, 0.5, 0.5);
glTranslatef(-1.5, -0.5, 0.0);
glCallList( object ); //drawPattern
glPopMatrix();
glPushMatrix();
glTranslatef(-1.0, -0.5, 0.0);
glRotatef(30, 0, 0, 1); //30 degrees around z
glScalef(0.5, 0.5, 0.5);
glCallList( object ); //drawPattern
glPopMatrix();
glPushMatrix();
glTranslatef(-1.0, -0.5, 0.0);
glScalef(0.5, 0.5, 0.5);
glRotatef(30, 0, 0, 1);
glCallList( object ); //drawPattern
glPopMatrix();
glPushMatrix();
glScalef(0.5, 0.5, 0.5);
glTranslatef(-1.0, -0.5, 0.0);
glRotatef(30, 0, 0, 1); //30 degrees around z
glCallList( object ); //drawPattern
glPopMatrix();
glPushMatrix();
glScalef(0.5, 0.5, 0.5);
glRotatef(30, 0, 0, 1);
glTranslatef(-1.0, -0.5, 0.0);
glCallList( object ); //drawPattern
glPopMatrix();
GLuint GLBox::drawPattern()
{
GLuint list;
list = glGenLists( 1 );
glNewList( list, GL_COMPILE );
glPushMatrix();
glBegin(GL_LINE_LOOP);
glVertex3f(-1.3, 0.0, 0.0);
glVertex3f(-1.0, -1.0, 0.0);
glVertex3f(0.0, -1.3, 0.0);
glVertex3f(1.0, -1.0, 0.0);
glVertex3f(1.3, 0.0, 0.0);
glVertex3f(1.0, 1.0, 0.0);
glVertex3f(0.0, 1.3, 0.0);
glVertex3f(-1.0, 1.0, 0.0);
glEnd();
//This is where the object is defined and drawn.
GLfloat y_red = 1.0;
GLfloat y_green = 1.0;
GLfloat y_blue = 0.0;
GLfloat x = 0.1;
GLfloat y = 0.0;
GLfloat z = 0.0;
GLfloat rot = 0.0;
for(int ct = 0; ct < 100; ct++)
{
GLfloat mat_Y[] = {y_red, y_green, y_blue};
glPushMatrix();
glRotatef(rot, 0.0, 0.0, 1.0);
glTranslatef(x, y, z);
glBegin(GL_POLYGON);
glNormal3f(0.0, 0.0, -1.0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_Y);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.1, 0.1, 0.0);
glVertex3f(0.15, 0.0, 0.0);
glVertex3f(0.1, -0.1, 0.0);
glEnd();
glPopMatrix();
rot += 137.5; //phylotactic pattern
x += 0.01;
y_green -= 0.01;
}
glFlush();
glPopMatrix();
glEndList();
return list;
}
void GLBox::initializeGL()
{
object = drawPattern();
...
}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.