Jump to content
  • Advertisement
Sign in to follow this  
irdalama

OpenGL cant get it to rotate right

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

Hey, im trying to rotate objects from the center of their body. I am using visual c++ with the opengl, its rotating from the bottom left corner of the front face (+z normal - righthand coord system) of a cube. I used the glBegin(Gl_QUAD) and drew six faces that ended up as a cube. How can i get my rotate functions to rotate from the center of cube's body instead of rotating from the front face corner(+z normal - right hand coord system)? thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
i posted over in the opengl section, so if you have any advice please post there, i cant seem to find the place to delete my post....

Share this post


Link to post
Share on other sites
make sure one corner of your cube is not sitting at 0,0,0. that would cause a problem. if it is, translate your cube so that 0,0,0 is at the center of your cube and then try rotating it.

Share this post


Link to post
Share on other sites
You need not change the model's data if it's difficult - you can effectively change the model's orientation with a conjugate-translation:

The point about which a model rotates is the origin of the current space's coordinates. In your case, it looks like this is at the corner of the cube. In order to rotate about its centre, you need to translate the object so that it is centred about the origin. Supposing that the centre of the object is at (x0, y0, z0) wrt the current coordinates; call glTranslatef(-x0, -y0, -z0), rotate, then finally translate back. The whole operation goes from

glRotatef(angle, x_axis_component, y_axis_component, z_axis_component);

to

(Edit:)
glTranslatef(x0, y0, z0);
glRotatef(angle, x_axis_component, y_axis_component, z_axis_component);
glTranslatef(-x0, -y0, -z0);

Sorry if any of my syntax is wrong: OpenGL isn't my native tongue and I haven't used it in a while.

Regards
Admiral

[Edited by - TheAdmiral on September 28, 2006 2:26:26 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by TheAdmiral
glTranslatef(-x0, -y0, -z0);
glRotatef(angle, x_axis_component, y_axis_component, z_axis_component);
glTranslatef(x0, y0, z0);

Not quite. To rotate around an arbitrary point T in OpenGL, you do this:
    glTranslatef( T.x, T.y, T.z );
glRotatef( angle, x, y, z );
glTranslatef( -T.x, -T.y, -T.z );
In math form, it corresponds to v' = TRT-1v. Using D3D's row vector notation, it would be written as v' = vT-1RT.

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!