#### Archived

This topic is now archived and is closed to further replies.

# Rotating problems

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

## Recommended Posts

I am really new to opengl, just a few days so I''m having a few basic problems. Basically I got a sphere, and when I press the right/left buttons I want it to rotate it on the z axis, but I also have to rotate it along the x axis when I press up/down. My problem is that when I rotate it along one of the axis, the other rotation rotates along a weird axis. I''m having trouble describing it. Anyways what I think I''m saying is: how do i rotate an object without changing it''s axis

##### Share on other sites
Hi Chrono999,

I think the problem you''re having is due to the order which you perform the rotations. The correct order to rotate an object is:
rotate around X axis,
rotate around Y axis,
rotate around Z axis

... so in your case, your function calls would be like this:

...glRotatef(xAngle, 1.0, 0.0, 0.0);glRotatef(zAngle, 0.0, 0.0, 1.0);DrawSphere();...

If this doesn''t fix it, let me know
(I don''t want to be giving out incorrect advice)

NOTE: if you try to rotate around all three axes (like in a flight sim, etc), you''ll run into a problem called Gimbal Lock (do a search on it and quaternions if you want to know more). However, doing rotations this way is OK if you only want up to two degees of rotational freedom.

-------------
squirrels are a remarkable source of protein...

##### Share on other sites
I ran into some confusion when I first started doing this. Another problem that you may be having is that you are translating at the wrong point? But I could be wrong. I usually am.

##### Share on other sites
Hey Chrono999,

I think I know what you mean (I hope).
You probably want a rotation around the "origin-axis"?!

My OpenGL is getting a bit rusty, so I''m not sure I''m right...but it should look something like this:

float Matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, Matrix);
glRotatef(angle, 1,0,0);
glMultMatrixf(Matrix);
...

Hope it''s something usefull,
Bas.

• 10
• 13
• 52
• 11
• 15