Public Group

Object Rotation

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

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 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 on other sites
so simple i feel like an idiot for not figuring it out :P

//Thx

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 11
• 11
• 9
• Forum Statistics

• Total Topics
631773
• Total Posts
3002265
×