Search code examples
c++spriteimage-rotationallegroc++98

rotate_sprite rotation is ~65625 times too small


I'm using c++98 and Allegro 4 and I'm attempting to use the rotate_sprite function. The documentation claims that in the angle parameter, 256 is a full circle and 64 is a right angle.

void rotate_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle);

When testing, I found that the sprite did not rotate, but also found when I significantly increased the parameter I was able to get rotation with the number 4200000 appearing to provide a right angle.

rotate_sprite(world, plane, plane_x, plane_y, 4200000 * plane_r);
//plane_r is an int 0 to 3

So my question is why does 4200000 yield a right angle when the documentation claims a 64 will yield a right angle? And what is the actual value of a right angle? 4200000 worked in this instance, but what is the exact number for the future?


Solution

  • The itofix function is used to turn the integer into a a fixed point 16.16 number, which is the type of the parameter. So a working version of the sample from above is:

    rotate_sprite(world, plane, plane_x, plane_y, itofix(plane_r * 64));