|
Forgotten mana... |
Don Freeman
Member #5,110
October 2004
|
Ok...this topic has been punished enough, but I can't find it using allegro/forums/search at the moment. Questions is: I am rotating a sprite using allegro's rotate_sprite(...) function. I want the image to move in the same direction as the angle is. I've done this before, but it's been a long time ago. I know it's got something to do with converting radians to degrees...converting degrees to allegro degrees...conjuring magical dragons...and all that, but I can't remember. //////////////////////////////////////////////////////////////// // in the update routine: xVel = cos( angle ) * vel; yVel = sin( angle ) * vel; x += xVel; y += yVel; //////////////////////////////////////////////////////////////// // then in drawing routine: rotate_sprite(pDest,pBmp,x+pBmp->w/2,y+pBmp->h/2,ftofix(angle)); ////////////////////////////////////////////////////////////////
-- |
ReyBrujo
Moderator
January 2001
|
Sin & Cos: The Programmer's Pals!, see the Using atan2(): homing missiles section. -- |
Don Freeman
Member #5,110
October 2004
|
Here is my code sample: The image is a simple triangle with a white line facing north.
I know I am just doing a conversion wrong somewhere... -- |
Arthur Kalliokoski
Second in Command
February 2005
|
angle = 1.0; //radians That should work, money back guarantee They all watch too much MSNBC... they get ideas. |
amarillion
Member #940
January 2001
|
Arthur: that doesn't work. rotate_sprite needs a value between 0 and 255. These functions take radians, not degrees. Assuming angle is in radians (can't deduce that from the code), you can use it directly here without converting. And you can use this (shorter) code: rotate_sprite(pDest,pBmp,x+pBmp->w/2,y+pBmp->h/2, ftofix(angle * 128 / PI));
edit:
-- |
OICW
Member #4,069
November 2003
|
But you need to convert radians into the fixed angle. Fixed angle is number between 0-255 and therefore you must multiple angle in radians by radtofix() constant. I advice you to have angle in fixed format because it will remove you many headaches. [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
amarillion
Member #940
January 2001
|
OICW: Only one conversion is necessary in the code above, i.e. when using rotate_sprite. All the other functions use radians. -- |
|