pushing and popping

hi,
i’m trying to rotate the arm of my object and then move the whole object forward (along the x axis) but the following code produces some ‘interesting’ results:

glPushMatrix();
glTranslatef(hipx, shouldery, 0.0);
glRotatef(left_arm_angle, 0.0, 0.0, 1.0);
glTranslatef(-hipx, -shouldery, 0.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glCallList(leftarmList);
glPopMatrix();

i think that perhaps the use of extra glPushMatrix() and glPopMatrix() could fix this problem but i do not know where to place them.

can anyone help??

Well it depends upon what you are trying to do… I would assume that you want the leg to move, then have he figure move, right? Well, here is what your code is doing right now:

glPushMatrix();
//Begins new matrix in stack

glTranslatef(hipx, shouldery, 0.0);
//translates the drawing position to hipx, shouldery

glRotatef(left_arm_angle, 0.0, 0.0, 1.0);
//Rotates the drawing position

glTranslatef(-hipx, -shouldery, 0.0);
//translates back to the original drawing position

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
//Sets active polygon mode

glCallList(leftarmList);
//calls an arm to be drawn

glPopMatrix();
//end this matrix in stack

See what went wrong? Your translating, rotating, then just translating back to where you were.

I’m not sure what your trying to do, but it looks like you want the leg to go up, rotate then come back down (the negative direction of the first translation).

Some more input would help. =)

~Jesse

i’ve worked it out following your explanation…
i need to take the hip translation out of that part like so…

glPushMatrix();
glTranslatef(hipx, 0.0, 0.0);
glPushMatrix();
glTranslatef(0.0, shouldery, 0.0);
glRotatef(left_arm_angle, 0.0, 0.0, 1.0);
glTranslatef(0.0, -shouldery, 0.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glCallList(leftarmList);
glPopMatrix();
glPopMatrix();

thanks for the help!!