Rotating object around moving object/player in 2D

Posted by Boston on Game Development See other posts from Game Development or by Boston
Published on 2013-11-02T02:25:25Z Indexed on 2013/11/02 4:11 UTC
Read the original article Hit count: 177

Filed under:
|
|
|

I am trying to implement a camera which rotates around the world around the player. I have found many solutions online to the task of rotating an object about the origin, or about an arbitrary point. The procedure seems to be to translate the point to be rotated about to the origin, perform the rotation, translate back, then draw. I have gotten this working for rotation around the origin as well as for a fixed point. Rotation of objects around the player works as well, provided the player does not move. However, if the objects are rotated around the player by some non-zero degree, if the player moves after the rotation it causes the rotated objects to move as well. I probably have done a poor job explaining this so here's an image: http://i.imgur.com/1n63iWR.gif

And here's the code for the behavior:

renderx = (Ox - Px)*cos(camAngle) - (Oy - Py)*sin(camAngle) + Px;

rendery = (Ox - Px)*sin(camAngle) + (Oy - Py)*cos(camAngle) + Py;

Where (Ox,Oy) is the actual position of the object to be rotated and (Px,Py) is the actual position of the player. Any ideas? I am using C++ with SDL2.0.

© Game Development or respective owner

Related posts about c++

Related posts about 2d