Sign in to follow this  

OpenGL rotation problem

Recommended Posts


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:


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.


Share this post

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

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