Jump to content
  • Advertisement
Sign in to follow this  
davinsamji

rotating an object from any part of the page

This topic is 4272 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, i need help rotating an object from any part of the page. glTranslatef (xpos, ypos, 1.0); glRotatef(degrees, 0.0, 0.0, 1.0); glScalef(xshape, yshape, 1.0); above is the code that im using, at the moment the object rotates from the centre of the page, but i need it to rotate from the centre of the object.

Share this post


Link to post
Share on other sites
Advertisement
When you rotate an object, it will rotate around the origin.
So, if the center of the object is at the origin it will rotate around it's center.
If the object is not at the origin, it will rotate around the origin. You could think about it as orbiting.
So, if the sun were at the origin and the Earth weresome number of units away, rotating the Earth would orbit it around the sun.

Basically, you have to rotate before you translate.

glRotatef(degrees, 0.0, 0.0, 1.0);
glTranslatef (xpos, ypos, 1.0);
glScalef(xshape, yshape, 1.0);

Share this post


Link to post
Share on other sites
Also make sure that your object is set to rotate about its own origin and not the world origin.

Been a couple of years since I've done OpenGL and I can't remember the exact term for what needs to be used, but look up glPushMatrix and glPopMatrix, or something similar, it sets up a hierarchy that allows you to move things on screen independently of one another, and, in your case, revolve an object around its own origin as apposed to the world origin.

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!