• Advertisement
Sign in to follow this  

Help On Push and Pop

This topic is 3734 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I did Push and Pop Matrix in my code, however, after some push and pop matrix, the object i wanted to push and pop has more effect on it,(e.g the leg becomes attached on the hand) why is this so? Thanks to anyone who can help me... Here is part of my code...
void DrawRobot()
{
	//head
	glPushMatrix();
	DrawHead();
	glPushMatrix();	
	//body
	glTranslatef(0.0, -10.0, 0.0);
	DrawBody();
	glPushMatrix();
	DrawBelt();
	glPopMatrix();
	//left arm
	glTranslatef(-22.0, 8.0, 0.0);
	glRotatef(90.0, 1, 0, 0);
	glRotatef(60.0, 0, 1, 0);
	DrawArm();
	glPushMatrix();
	//left hand
	DrawHand();
	glPopMatrix();
	glPopMatrix();
	//left leg
	glTranslatef(-7.0, -30.0, 0.0);
	DrawLeg();
	glPushMatrix();
	//left feet
	DrawFeet();
	glPopMatrix();
	glPopMatrix();
	//right arm
	glTranslatef(22.0, -2.0, 0.0);
	glRotatef(90.0, 1, 0, 0);
	glRotatef(-60.0, 0, 1, 0);
	DrawArm();
	glPushMatrix();

	//right hand
	DrawHand();
	glPopMatrix();
	glPopMatrix();
	//right leg
	glTranslatef(7.0, -20.0, 0.0);
	DrawLeg();
	glPushMatrix();
	//right feet
	DrawFeet();
	glPopMatrix();
	glPopMatrix();
}


[Edited by - SnowMoo on December 5, 2007 1:58:59 AM]

Share this post


Link to post
Share on other sites
Advertisement
Get into the habit of indenting, and maybe even strat a new code block, for every push and pop pair. The problem becomes pretty obvious.

glPushMatrix();
{
DrawHead();
glPushMatrix();
{
glTranslatef(0.0, -10.0, 0.0);
DrawBody();
glPushMatrix();
{
DrawBelt();
}
glPopMatrix();
glTranslatef(-22.0, 8.0, 0.0);
glRotatef(90.0, 1, 0, 0);
glRotatef(60.0, 0, 1, 0);
DrawArm();
glPushMatrix();
{
DrawHand();
}
glPopMatrix();
glPopMatrix();
glTranslatef(-7.0, -30.0, 0.0);
DrawLeg();
glPushMatrix();
{
DrawFeet();
}
glPopMatrix();
}
glPopMatrix();
glTranslatef(22.0, -2.0, 0.0);
glRotatef(90.0, 1, 0, 0);
glRotatef(-60.0, 0, 1, 0);
DrawArm();
glPushMatrix();
{
DrawHand();
}
glPopMatrix();
}
glPopMatrix();
glTranslatef(7.0, -20.0, 0.0);
DrawLeg();
glPushMatrix();
{
DrawFeet();
}
glPopMatrix();
}
glPopMatrix();

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement