source code is here
http://rapidshare.de/files/10311480/torso.c.html web page
some useful code is following:
/* tree node definination */
typedef struct treenode
{
GLfloat m[16];
void (*f)();
struct treenode *sibling;
struct treenode *child;
}treenode;
/* torso node */
treenode torso_node, head_node, lua_node, rua_node, lll_node, rll_node,lla_node, rla_node, rul_node, lul_node;
void traverse(treenode* root)
{
if(root==NULL) return;
glPushMatrix();
glMultMatrixf(root->m);
root->f();
if(root->child!=NULL) traverse(root->child);
glPopMatrix();
if(root->sibling!=NULL) traverse(root->sibling);
}
void torso()
{
glPushMatrix();
glRotatef(-90.0, 1.0, 0.0, 0.0);
gluCylinder(t,TORSO_RADIUS, TORSO_RADIUS, TORSO_HEIGHT,10,10);
glPopMatrix();
}
void head()
{
glPushMatrix();
glTranslatef(0.0, 0.5*HEAD_HEIGHT,0.0);
glScalef(HEAD_RADIUS, HEAD_HEIGHT, HEAD_RADIUS);
gluSphere(h,1.0,10,10);
glPopMatrix();
}
void
display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glColor3f(1.0, 0.0, 0.0);
gluLookAt(x,y,z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
traverse(&torso_node);
glutSwapBuffers();
}
void myInit(void)
{/* set up tree structure */
glLoadIdentity();
glRotatef(theta[0], 0.0, 1.0, 0.0);
glGetFloatv(GL_MODELVIEW_MATRIX,torso_node.m);
torso_node.f = torso;
torso_node.sibling = NULL;
torso_node.child = &head_node;
glLoadIdentity();
glTranslatef(0.0, TORSO_HEIGHT+0.5*HEAD_HEIGHT, 0.0);
// glTranslatef(x+0.0, y+TORSO_HEIGHT+0.5*HEAD_HEIGHT, z+0.0);
glRotatef(theta[1], 1.0, 0.0, 0.0);
glRotatef(theta[2], 0.0, 1.0, 0.0);
glTranslatef(0.0, -0.5*HEAD_HEIGHT, 0.0);
// glTranslatef(x+0.0, y-0.5*HEAD_HEIGHT, z+0.0);
glGetFloatv(GL_MODELVIEW_MATRIX,head_node.m);
head_node.f = head;
head_node.sibling = &lua_node;
head_node.child = NULL;
}