|
Rotate a bitmap |
Karamell Kungen
Member #4,179
December 2003
|
How to rotate a bitmap? |
Chris Katko
Member #1,881
January 2002
|
void rotate_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, fixed angle); Does just that. It's just like a normal sprite drawing function, but the angle argument will rotate it in "allegro degrees" (which are 0.0 to 255.0). (IIRC) Where 0 is up, 64 is right, 128 is down, and 192 is left. If you want to make it turn, all you need to do is increase/decrease a fixed (or "fix") variable.
A "fix" won't work if your using C (as opposed to C++). The difference is that fix does nessicary conversions between other variable types. I'd recommend reading the "Fixed point math routines" section of the Allegro Manual for more on that. If I forgot anything, feel free to ask. -----sig: |
Steve Terry
Member #1,989
March 2002
|
it's fixed angle; if(key[KEY_LEFT]){angle = angle - itofix(1);} rotate_sprite(screen, mysprite, 320, 240, angle); alternately int angle; if(key[KEY_LEFT]){angle--;} rotate_sprite(screen, mysprite, 320, 240, itofix(angle));
___________________________________ |
Karamell Kungen
Member #4,179
December 2003
|
thanks hmm this is a problem i should solve by myself but I can't :/ When I press left/right the angle var changes but if I want the car to move forward I press KEY_UP and then it should move in the angle direction. |
Chris Katko
Member #1,881
January 2002
|
Steve: fix is a C++ version of fixed with the operators overloaded, so conversion is done automatically. Karamell: For that you want sine ( sin(); ) and cosine ( cos(); ). Where it would be (IIRC):
-----sig: |
brain21
Member #1,208
December 2000
|
I'm lost. Is today "build a game for a newbie" day? I think it should be today. |
Chris Katko
Member #1,881
January 2002
|
I'm lost. Is what Steve and I wrote out suppost to be hard...? I took me about a minute tops to write my second post out. -----sig: |
akOOma
Member #3,850
September 2003
|
This code isn't right at all.. // angle to normal degrees (0 to 360) angle *= 1.40625; // angle to radians (0 to 2Pi) angle *= Pi / 180; // now you can use sin and cos
|
Chris Katko
Member #1,881
January 2002
|
Actually, I was (and still am) correct. Calling fsin and fcos on a fix, will give incorrect results, because fix (not fixed) automatically does type-conversions. Allegro 4.1.12 Manual said: You should not mix the fix class with the fixed typedef though, because the compiler will mistake the fixed values for regular integers and insert unnecessary conversions. For example, if x is an object of class fix, calling fixsqrt(x) will return the wrong result. You should use the overloaded sqrt(x) or x.sqrt() instead.
-----sig: |
|