Jump to content
  • Advertisement
Sign in to follow this  
Harnz

OpenGL rotation problem

This topic is 2810 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

Hello,

I am very new to OpenGL and I have a little problem with a rotation.

I want to rotate an object of which I have computed the center (correctly).

So here is what I do:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glTranslatef(-centerX,-centerY,-centerZ); //move the objects center to the origin
glRotatef(xRot,1.0f,0.0f,0.0f); //rotate around x-axis
glTranslatef(0,0,-2); //translate the object so it becomes visible

Unfortunately it is not working as I expected it to...
Instead of rotating the object the object stays fixed and the direction of the camera is changing.

Do you have any suggestions?

Thank you.

Harnz

Share this post


Link to post
Share on other sites
Advertisement
I think your final rotate and translate are out of order.

When you call final translate, you are translating in it's local coordinate space, so it will translate in the direction that you have rotated it. If you rotate it by some degree, it will move (0,0,-2) along the direction it is pointing. This is why it will appear to orbit around the camera instead of staying fixed, because it is ending up in a different position based on the rotation angle.

Share this post


Link to post
Share on other sites
swap the calls, The very last call is applied first.

You want to rotate the object around its own center, and then move it to its final position.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!