Jump to content
  • Advertisement
Sign in to follow this  
ebody

Lesson #32 - why glPushMatrix?

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

Hi, could someone tell me why I should do glPushMatrix() before creating a pick matrix? what is the purpose of this action? I know that we save the current matrix on the stack but why? what would happen if I didn't push it there?

Share this post


Link to post
Share on other sites
Advertisement
quite simply because when you get access to the stack you aren't necessarily the first or last thing that needs it... therefore there may be data already in the memory you are about to trash.

It's a bit like jumping on a random computer and continuing to play a paused game from where it is without first saving the game and then restoring it back to where it was when you are finished.

The memory isn't "yours". you are one of many players who all need to share it so therefore to play nice and keep things working you need to "put things back the way you left them when your turn is over" which is why you should push it at the start, and pop it in the end to restore it.

Share this post


Link to post
Share on other sites
nb is very right.

In the case of Lesson 32, the glPushMatrix() saves the previous Projection Matrix. Then it selected the Pick. Operates the operations in the picking area. In this case, it chose the area of the mouse and the perspective matrix. Then draw the objects (MODELVIEW) and restricts them in the selection buffer. Therefore you can get the hit.

Then after doing everything u need to do in the Pick, you restore everything back to the previous, do everything else you wanted to do before Pick. But in this case, you only need to check the hit. Because the hit was triggered from a mouse action, you won't do other things. But in other cases, you might want to do something else. e.g. you could selection ur modelview matrix back and draw other things.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!