OpenGL Object Hierarchy

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: [font="Courier New"][color="#000080"]glPushMatrix()[/color][/font] and [font="Courier New"][color="#000080"]glPopMatrix()[/color][/font] to accomplish our goal, which is modeling a simple robot.
[size="5"]The robot structure
[table][tr][td][/td][td][/td][td][/td][/tr][tr][td]Fig. 1a - Object Hierarchy[/td][td]1b - GL model[/td][td]1c - GL light model[/td][/tr][/table]
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:

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

...
#include
...

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.
[size="5"]Pseudocode

void DrawRobot()
{
glPushMatrix(); /* all objects are bust's son
that is if we move bust all other parts move too */
/*-------------------- DRAW HEAD AND BUST -----------------------*/
glPushMatrix();
/* Draw head */
/* Draw bust */
glPopMatrix();