Sign in to follow this  

glRotatef problem

This topic is 3475 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 All I'm trying to rotate an object in my game scene around the y-axis which I can get it to do that but... It does not rotate it from centre of the object, more left position to the object in which the object also moves backwards as it's turning. Is there anyway that I can use glRotatef to rotate my object from its very centre? My end aim is to rotate the object 360 degrees (motion) left and right. As it does not rotate from centre of object it is a bit fustrating. Thank you in advance. Andrew

Share this post


Link to post
Share on other sites
glRotatef rotates from the center of the current space. This means that you have to check the order of your transformations to make sure that you are rotating your object before it gets translated to what ever position in the world you have it at.
It sounds like your current ordering is translating it out into the world, then you rotate it, this making it orbit the origin.

Share this post


Link to post
Share on other sites
a usual stategy is to move you object's very centre to the origin, rotate it, and move it back e.g.

void Rotate(Vector3 pivotpoint)//lets say pivot point is object's very centre
{
gltranslatef(-pivotpoint.x, -pivotpoint.y, -pivotpoint.z);//move to origin
glRotatef(m_yrotationangle,0,0,1);
gltranslatef(pivotpoint.x, pivotpoint.y, pivotpoint.z);//move back
}

You will see that type of thing in much opengl tranformations literature for beginners.


Share this post


Link to post
Share on other sites
Sign in to follow this