PDA

View Full Version : clearing the matrix stack



jwlee
11-02-2000, 09:46 AM
Hi

I'm trying to find a easy way to clear the matrix stack. Basically I'm loading my model and adding transforms according to user input. I would like to enable the user to reset the model to its original position. Rather than Popping matrices off the stack as many times as it's been modified, is there a easier more elegant way?

thanks
James

zed
11-02-2000, 11:41 AM
glLoadIdentity()
that'll clear it
but u prolly wanna save the original matrix in a var and just reload it so glLoadMatrix..(originalmatrix)

jwlee
11-02-2000, 12:38 PM
Thanks. I tried glLoadMatrix, but didn't get the effect I wanted. I'll try adding code to save the original matrix and reload it as necessary.

thanks again.



Originally posted by zed:
glLoadIdentity()
that'll clear it
but u prolly wanna save the original matrix in a var and just reload it so glLoadMatrix..(originalmatrix)

11-02-2000, 01:51 PM
glPushMatrix()
glLoadIdentity()
do what you need
glPopMatrix()

or
float mat[16];
glGetfv(GL_MODELVIEW_MATRIX, mat);
glLoadIdentity();
do what you need;
glLoadMatrix(mat);

jwlee
11-20-2000, 07:32 PM
I tried this and it works partially. When the user begins to rotate, translate or zoom the model again, it seems to pick up where the last matrix before the glLoadMatrix left off. In other words the same view before the reset. Any clues why this is happening?


Originally posted by mr x:
float mat[16];
glGetfv(GL_MODELVIEW_MATRIX, mat);
glLoadIdentity();
do what you need;
glLoadMatrix(mat);[/B]

jwlee
11-20-2000, 08:08 PM
Nevermind! =)

I'm such a goofball. I forgot to reset some global values such as:
-zoomAmount
-moveAmount
-rotationAngle

I created these variables to maintain degrees of movement or rotation. Silly me, I fogot about them.

Thanks for everyones help.

best
James


Originally posted by jwlee:
I tried this and it works partially. When the user begins to rotate, translate or zoom the model again, it seems to pick up where the last matrix before the glLoadMatrix left off. In other words the same view before the reset. Any clues why this is happening?





[This message has been edited by jwlee (edited 11-20-2000).]