Sign in to follow this  
srky982

Need help - Rotation problem

Recommended Posts

srky982    122
If i have 3 rotations: glRotatef(x,1.0f,0.0f,0.0f); glRotatef(y,0.0f,1.0f,0.0f); glRotatef(z,0.0f,0.0f,1.0f); Object(); 1.step x=90; 2.step z=90; but it wont be z-rotation because z axis is rotated by the first one. I save perspective with glPushMatrix() do glLoadidentity and recall it with glPopMatrix() but still it contains my first rotation.How to clean matrix after glPushMatrix and before glPopmatrix so it contains no rotation but contains perspective that i can recall. In fact i want to do a real z rotation after x rotation. Thanks!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
to change the order of rotations
just change the order of the glRotate calls

Share this post


Link to post
Share on other sites
srky982    122
I know that but i have all three in loop sometimes i need one sometimes another how to handle it?Can i do it by loading a new matrix (glLoadMatrix()) ?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
use 'if()'
to select different glRotate calls?

Share this post


Link to post
Share on other sites
srky982    122
Lets say:
a=0;
loop starts:
----------------------
if (a==1) rotatex(); -> LOOP
if (a==2) rotatey(); -> LOOP
----------------------
(a) become 1 so rotatex happened in loop.
But now (a) become 2 the second rotation hapened but it is not y rotation.Get it?
How to remove the first rotation from matrix,so the second one can be y rotation,but at the same time to save the first one?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Quote:
Original post by srky982
How to remove the first rotation from matrix,so the second one can be y rotation,but at the same time to save the [orientation change from] first one?


What you ask cannot be achieved using glrotate and associated functions alone.
Free Rotation as you describe, must be calculated yourself with your own matrix or vector math.
This is because opengl transforms affect Rendering Only; they do not actually change your object or coordinate system, thus they cannot accumulate changes as you wish.

ie, you cant 'remove' the previous rotation axis and select a new one; because doing so changes the transformation stack thus also eliminating that rotated viewpoint.
Don't think of glRotate calls as actual rotations of your object; they are only transforms added to the stack of operations inbetween your model and screen.


as I said, you need to implement your own matrices; this will require learning how they work on your part as well as a number of concepts:
learn 'rotation matrix' and 'coordinate system transformation' and 'local vs absolute coordinate system'

Once you have all that, use GlMultMatrix() to insert your own calculated matrices into opengl.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
P.S.
do not under any circumstances look at 'Quaternions' until you have mastered 'Matrices'

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this