Hey rrybody,
Im trying to simulate a tank right now and the problem i have is that every rotate method i find uses degrees, not radians, so how would i be able to convert it ?
My current code is
al_draw_rotated_bitmap(Tank, 32, 32, TankX, TankY, TankRotation*(ALLEGRO_PI/180), NULL);
EDIT: Updated code
Every Allegro function uses radians, not degrees. Also, ALLEGRO_PI / 180 is not 0.017453277777.
Soooo how do i fix it ?
Just define something like that:
#define DEGTORAD (ALLEGRO_PI/180.0)
Multiply by DEGTORAD value if you convert degrees to radians and divide by it if it's radians to degrees. It can also be a function-like, if that's more convenient to you:
#define DEGTORAD(x) ((x)*(ALLEGRO_PI/180.0))
#define RADTODEG(x) ((x)/(ALLEGRO_PI*180.0))
Already 4000 years, and no other solution yet.
Okay i think i got a handle on whats happening now, but still its not working properly. It only moves if its facing directly up down right or left, it doesnt move diagonally at all.
Make sure your tank coordinates are't of integral type.
Explain?
EDIT: Never mind i got it I just put it as a float and it started to work. Could you explain why that happens though?
Integer variables can only store integral values themselves. That's why they called that, obviously.
Result of any operation on integer is rounded so one could store it. For you that means that if you add too small value, no change will even happen at all. And on top of that, discarded decimal digits are not accumulated. So if you expect your integer to increase by 1 after you add 0.4 three times, you wrong: nothing will change because decimal part is always discarded.
That's a basics of integral types, actually. I am surprised you didn't knew that.