Object Rotation

Started by
1 comment, last by Frggr 13 years, 7 months ago
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?)
Advertisement
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.
so simple i feel like an idiot for not figuring it out :P

//Thx

This topic is closed to new replies.

Advertisement