Sign in to follow this  
davinsamji

rotating an object from any part of the page

Recommended Posts

davinsamji    122
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
Bnty_Hntr    187
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
Medhatter    132
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

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