Sign in to follow this  
Ademan555

rotate around a point

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

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