rotating an object from any part of the page

Started by
1 comment, last by Medhatter 17 years, 5 months ago
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.
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);
- Bnty_HntrCome visit Triple Buffer, a great source for DirectX and other tutorials.Check out my Blog.Or, join Triple Buffer by checking out our Help Wanted post.
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.

This topic is closed to new replies.

Advertisement