From Ohm

Open GL Matrix Stack

Supposed we have a procedure drawObject() that renders a particular object.

To render multiple objects of the same type with different transformations we use the matrix stack via glPushMatrix() and glPopMatrix():

glPushMatrix();
   glTranslatef(-10,0,0);
   glRotatef(90,0,1,0);
   drawObject();
glPopMatrix();

glPushMatrix();
   glTranslatef(10,0,0);
   glRotatef(-90,0,1,0);
   drawObject();
glPopMatrix();

The glPushMatrix command saves the actual transformation state. Later on the state can be restored with glPopMatrix().

With the matrix stack we can construct objects hierarchically from parts which in turn can be made up from sub-parts and so on.

void drawObject()
{
   glPushMatrix();
      glTranslatef(-1,0,0);
      drawPart();
   glPopMatrix();

   glPushMatrix();
      glTranslatef(1,0,0);
      drawPart();
   glPopMatrix();
}

void drawPart()
{
   glBegin();
      ...
   glEnd();
}

This is called hierarchical modeling. Here, the scene corresponds to a graph with parent-child relationships between the objects and their respective parts. This graph is called the scene graph.

Retrieved from http://schorsch.efi.fh-nuernberg.de/roettger/index.php/MedicalVisualization/OpenGLMatrixStack

Page last modified on November 14, 2016, at 06:33 PM