# Need help - Rotation problem

This topic is 4129 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites
to change the order of rotations
just change the order of the glRotate calls

##### Share on other sites
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 on other sites
use 'if()'
to select different glRotate calls?

##### Share on other sites
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 on other sites
Quote:
 Original post by srky982How 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 on other sites
P.S.
do not under any circumstances look at 'Quaternions' until you have mastered 'Matrices'

##### Share on other sites
Thanks a lot !!!
You just told me everything i hope to get.
Thanks really :)

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 13
• 9
• 12
• 9
• ### Forum Statistics

• Total Topics
631438
• Total Posts
3000073
×