Rotating about a centre.

I am rendering a 2D Triangle and want to rotate it around its centre. I have worked out the centre co-ordinates and i know i have to do a translation then a rotation but i’m not sure how to do this.

Please help me. I’m really really stuck.

Mark.

Thanks alot for you help. I really appreciate it.

This will rotate around an arbitrary point:

glTranslatef( cx, cy, cz ); // Translate to center of rotation
glRotatef( angle, ax, ay, az ); // Rotate
glTranslatef( -cx, -cy, -cz ); // Translate back
Draw();

Note: in 2D, cz = 0 and (ax,ay,az) = (0,0,1)

Note: as you can see, when rotating a model around its origin, the translations are not needed

[This message has been edited by Jambolo (edited 03-31-2002).]

Mark,

Do the translation and then the rotation. That way it will rotate the triangle around it’s center (doing rotation and then translation would rotate the triangle around the viewport).
Be sure to load the matrix identity at the end of whatever function you are using to display the triangle!

Hope that helps!

  • = TEFLON DRAGON = -