![]() |
| | >>> Click
here to download Final Fantasy Ringtones |
| |
#1 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: Code: void pivot_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, int cx, int cy, fixed angle); 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?~ |
| | |
| |
| Former Staff | If your sprite is of length (x axis) n and height (y axis) m, then cx = n/2, cy = m/2, x = x_tank and y=y_tank are where you want the center of the tank to be on the big bitmap, and angle should be atan((x_tank-x_mouse)/(y_tank-y_mouse)). Don't forget to boundary check since you may divide by 0, which gives an infinite which actually makes sense (atan(infinity) = pi/2 radians). |
| | |