Jump to content
  • Advertisement

Archived

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

Chrono999

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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);
glLoadIdentity();
glRotatef(angle, 1,0,0);
glMultMatrixf(Matrix);
...

Hope it''s something usefull,
Bas.


(Demo & GameDev: www.baskuenen.myweb.nl)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!