# rotate around a point

This topic is 4998 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hey im writing a little sprite engine and i wanna rotate my sprite around an arbitrary point (in openGL, i only mention that because iirc the translation order for d3d and openGL is different) take for example this quad...

____________
|           |
|           |
|           |
|           |
|   x       |
|___________|


what if i wanted to rotate around that x rather than the true center of that quad? ugh i think im bein retarted... but anyways... how would i do this? thanks a lot my brains crapped out -Dan

##### Share on other sites
if (like in your diagram, for example) you want to rotate around the point (-0.5, -0.5), you translate all the points by (0.5, 0.5), then do the rotation with the same equation you use to rotate around the center. Then translate back by (-0.5, -0.5).

You can either do the transformations by pushing the Translate, Rotate, Translate (backwards) onto the gl matrix stack. Or you can do them by hand and just give the final coordinates to GL.

##### Share on other sites
:-/ its not working for me...
translating then rotating doesnt cut it, it simply rotates around its own origin

rotating then translating however, rotates it around the origin...

wierd huh? (i know thats why i mentioned the wonky order of translation thing)

-Dan

##### Share on other sites
Make sure you're translating the points of the quad.. not just calling glTranslate();

##### Share on other sites
Rotating a point (x, y) around a pivot point (px, py) can be done using these equations:

x' = px + (x-px)cos(theta) - (y-py)sin(theta)y' = py + (x-px)sin(theta) + (y-py)cos(theta)

It's basically your standard transformation equations with a few changes to rotate around an arbitrary point (px, py).

If you're interested, I got this information from Computer Graphics with OpenGL, third edition. It's a really good book and I totally recommend it.

-david-

##### Share on other sites
Do you have some point of referance to tell the differance? If all you do is draw the rotated quad then it is going to be hard to tell the differance between runs. You would pretty well need to do a screen capture of each so you could see them side by side. Rotating them continually makes it a little more obvious where you are rotating about. If you actually mark the objects origin and the point you want to rotate about it is a good deal more obvious which point is rotating about which.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631782
• Total Posts
3002324
×