Welcome to Eyes on FF!
>>> Click here to download Final Fantasy Ringtones
Oh no!
 

Post New Thread  Reply
 
LinkBack Thread Tools
Moon Rabbits
so gangsta it hurrrrts..
Moon Rabbits's Avatar
Location: Caaaaaaaanada.
#1
Default Rotating a Bitmap (C++ question)

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);
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?~
Old 03-28-2007, 04:36 AM
Reply With Quote
Moon Rabbits is offline  
Endless
Former Staff
Prinny God
Endless's Avatar
Location: Prinny Moon
Default

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).
Old 03-28-2007, 07:47 PM
Reply With Quote
Endless is offline  
Post New Thread  Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:44 AM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.0.0
Copyright ©2000 - 2007, Eyes on Final Fantasy.
Sean Robinson Design

Online Games | Scholarships | Tool Enhancers