[SDL] Best way to rotate a sprite?

Sami Näätänen sami.naatanen at kolumbus.fi
Tue Jan 28 17:16:01 PST 2003


On Wednesday 29 January 2003 00:55, Kentaro Fukuchi wrote:
> From: Sami Näätänen <sami.naatanen at kolumbus.fi>
> Subject: Re: [SDL] Best way to rotate a sprite?
> Date: Wed, 29 Jan 2003 00:30:14 +0200
>
> > > angle = (angle + 1) % 32;
> > > angle = (angle - 1) % 32;
> >
> > In fact the above thing doesn't work correctly, because the C
> > standard defines the %-operator as mathematically correct reminder
> > operation.
> >
> > So the  -1 % 32 = -1, but we want it to be 31.
>
> Use following code instead.
>
> angle = (angle + 1) % 32;
> angle = (angle + 31) % 32;

This is good if the divisor is not an exact power of two. How ever if it 
is the original example, which uses and is faster, so no reason to use 
this.





More information about the SDL mailing list