Lesson #32 - why glPushMatrix?
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?
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.
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.
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.
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.
/*----------------------------------------------------------------------------------------------------------------------------------*/Enthusiastic and wild about game development. Any opportunity would get me sink into any fantastic game-revolution era.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement