Jump to content
  • Advertisement
Sign in to follow this  
CrimsonMemory

Need help clarifying something about matrix stack manipulation

This topic is 4050 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

Ok, the best way for me to show what I'm asking is through an example: Let's say that I want to display a wall clock. Therefore, it's just a circle with three lines, each line rotating a different amount from the origin point (which, in this case, will be when it is pointing to the 15). Simple so far, yes? Okay, well, what I'd like to do now is to rotate the ENTIRE clock about the y-axis as the hands are still rotating themselves. Well, I figured that all I would need to do is to rotate the clock, then push the matrix, rotate the second hand, pop matrix, push again, rotate minute hand, pop matrix, push once more, rotate hour hand, and pop matrix in order for it to display correctly. Lemme show you some sample code just to clarify:
glLoadIdentity();

glRotatef(clockTheta, 0.0, 1.0, 0.0);
drawClock();

glPushMatrix();
glRotatef(secondsTheta, 0.0, 0.0, 1.0);
drawHand();
glPopMatrix();

glPushMatrix();
glRotatef(minutesTheta, 0.0, 0.0, 1.0);
drawHand();
glPopMatrix();

glPushMatrix();
glRotatef(hoursTheta, 0.0, 0.0, 1.0);
drawHand();
glPopMatrix;


It seems logical to me that the above should do what I wanted. However, when I run the program, only the clock circle and the seconds hand rotate correctly. The minute and hour hands turn as if the entire clock wasn't rotating at all! So, I messed with my code to see if I could get it to work correctly. I decided to comment out every call for pushMatrix() after the first call and see what happens. And, lo and behold, it worked! But does that make any sense?! How can I be popping 3 times when I push only once? Am I missing something here?

Share this post


Link to post
Share on other sites
Advertisement
Oh, and I apologize, I mixed something up at the end of my post, but it's now edited. This is just in case someone saw it before the edit.

Share this post


Link to post
Share on other sites
OKAY, I actually found the answer. It seems that I had left out that VERY LAST popMatrix() call - that fixed everything. Funny that I typed it correctly in the sample code and not in the actual code. Thanks anyway, guys!

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!