Sign in to follow this  

Object Rotation

This topic is 2637 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

I'm looking at the theory behind rotating a 2D object right now (using rotation matrices).

Wondering if it is usable in code.

Rotation matrix being:

cosθ -sinθ
sinθ cosθ


So (1,0) rotated 90 degrees about (0,0) would become:

(cosθ,-sinθ), θ=90
(0,-1)

Problem that I think might occur is that if we were to rotate by something that wasnt a multiple of 90 degrees (take 32 degrees or 45 degrees for example)
We would get
{(1/root(2), -1/root(2)} which a computer would round to .7071067812 (non exact).

If i were to rotate by 45 degrees say 16 times, that error would propagate through. causing it to not be a 720 degree rotation anymore.

(Maybe I'm over-thinking it // If not, are there any other rotation methods?)

Share this post


Link to post
Share on other sites
Rotating sprites are common.

What people normally do is call the 'non-rotated' sprite, the one that is in its usual position on the sprite sheet, 0o. Anytime you wish to display a rotated version of this sprite on screen, you should rotate the original 'non-rotated' sprite by the correct amount.

So for example, if a sprite should be displayed at 33o one frame and 67o the next. You would first use the 'non-rotated' sprite, in its original orientation and then rotate it 33o and then display it. Then, the next frame, you'd use the 'non-rotated' sprite, in its original orientation and then rotate it 67o and then display it.

That way rounding errors, etc., do not build up.

Share this post


Link to post
Share on other sites

This topic is 2637 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.

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