Moon Rabbits
03-28-2007, 03:36 AM
I'm making a Missile Defense type clone in C++ with the Allegro library.
A tank is drawn at the bottom of the screen, and right now I want to make a cannon on the tank rotate so that the nozzle faces the current coordinates of the mouse (mouse_x, mouse_y).
A function in Allegro called pivot_sprite() is what I want to use:
void pivot_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, int cx, int cy, fixed angle);
Where *bmp is the bitmap being drawn to, *sprite is the sprite being drawn to *bmp, (x, y) is the location to draw *sprite at on *bmp, (cx, cy) is the point that the bitmap will pivot around, and angle is the angle of rotation.
Now I, lacking math skills, can't figure out how I would go about rotating a BITMAP (*cannon) to face the mouse. The pivot point (cx, cy) would be the center of the tank.
Help?~
A tank is drawn at the bottom of the screen, and right now I want to make a cannon on the tank rotate so that the nozzle faces the current coordinates of the mouse (mouse_x, mouse_y).
A function in Allegro called pivot_sprite() is what I want to use:
void pivot_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, int cx, int cy, fixed angle);
Where *bmp is the bitmap being drawn to, *sprite is the sprite being drawn to *bmp, (x, y) is the location to draw *sprite at on *bmp, (cx, cy) is the point that the bitmap will pivot around, and angle is the angle of rotation.
Now I, lacking math skills, can't figure out how I would go about rotating a BITMAP (*cannon) to face the mouse. The pivot point (cx, cy) would be the center of the tank.
Help?~