
move a bmp by an angle 
evenzzz
Member #7,276
May 2006

Hello My BITMAP rotate left and right on keypress left and right, but this BITMAP don't go forward in the right angle on keypress up. I think the problem is in calculating coordonate of the bitmap here : x += 1 * cos(angle) ; someone can help the poor English speaker I'm please

deps
Member #3,858
September 2003

Steve Terry
Member #1,989
March 2002

And cos/sin are in 360 degrees, not 256. ___________________________________ 
evenzzz
Member #7,276
May 2006

ok I try this but it dont work : #define DEGREES(x) int((x)/360.0*0xFFFFFF) so i try this : x += 10 * (cos((angle * 360 / 256 )) * ( M_PI / 180)) ; both dont work 
CursedTyrant
Member #7,080
April 2006

Tell me something: angle * 360 / 256 What the hell does it do? Try this, but I'm not sure what do you want to do:
 
evenzzz
Member #7,276
May 2006

angle * 360 / 256 > because allegro d'ont rotate over 256° "Allegro uses a bizarre angle format for angles in all graphics commands" 
miran
Member #2,407
June 2002

It should be angle_in_degrees * 256 / 360 to turn degrees to Allegro degrees. It's not that Allegro doesn't rotate over 256°, Allegro's degrees are on a scale between 0 and 255. So a full circle in Allegro's functions is 256 units which is equivalent to 360 degrees. Sin and cos and other standard math functions of course work in radians. So basically you should keep you variables as radians and when you need to pass them to an Allegro function, convert them from radians to Allegro degrees: angle_in degrees = angle_in_radians * 180/M_PI; angle_in_allegro_degrees = angle_in_degrees * 256.0 / 360.0
 
evenzzz
Member #7,276
May 2006

Thank all i find the answer if (key[KEY_UP]){ rotate_sprite(buffer, enemy, xenemy, yenemy, itofix((angle/2/M_PI*256))); it work great ! 
gnolam
Member #2,030
March 2002

Steve Terry said: And cos/sin are in 360 degrees, not 256. Say what?  
