Jump to content
  • Advertisement


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


rotating an object in world space

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

Hi there, I am writing an object editor/viewer and confused in rotation procedure. I would like to move mouse up and down so that object rotates. But not in object space, in world space. So usual glRotate calls;
glRotatef(rotateY, 1, 0, 0);
glRotatef(rotateX, 0, 1, 0);
do not work correctly. First glRotate call changes the view matrix so the second rotation is no more in X (world space). so I tried;
  glMatrixMode(GL_MODELVIEW);  // Select The Modelview Matrix

  glTranslatef(transX, transY, transZ);	
  glRotatef(rotateY, 1, 0, 0);
  float corrY = -rotateY * PI / 180.0f;
  glRotatef(rotateX, 0, cos(corrY), cos(PI / 2 - corrY));

But, it still does not work.. any ideas? thanks..

Share this post

Link to post
Share on other sites
Keep a matrix for your object and rotate that matrix yourself,
then after you have done all your camera transformations and rotations, you multiply the modelview matrix with the object''s matrix.

Also glRotatef(angle,1,0,0) rotate''s about the x-axis and glRotatef(angle,0,1,0) rotate''s about the y-axis.

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.

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!