This is a simple example of object hierarchy. We can think of object hierarchy as a mode of representing a complex object composed of more simple ones related to each other. In this tutorial we'll learn two new GL commands: glPushMatrix() and glPopMatrix() to accomplish our goal, which is modeling a simple robot.
The robot structure
Note the relationships between objects: Leg is pelvis child and pelvis is bust's child, forearm is arm's child and arm is shoulder's child, shoulder is bust's child too, and so on. So, if we move bust for example, legs and arms move too. This is an object hierarchy.
Every piece of the robot is modeled into a function and stored in a display list so we'll have:
So, for example here is the code for left arm:
Note that in this example I'll use some GLUT commands to draw Spheres and Cubes so remember to link gl/glut.h in the headers section as indicated below
The most important function is DrawRobot() that draws all the parts of the robot and which uses the OpenGL commands glPushMatrix() and glPopMatrix() to estabilish the relationships between objects.