# Rotating to Mouse (using allegro, but not necessary)

This topic is 4866 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all, needing some help rotating my sprite using allegro (this is my first post). But first of all, I'm not a newbie. I can make some decent arcade side and top scrollers and do tile mapping stuff as well as basic particle effects. Right, onto my prob. I want to make a sprite rotate to the direction of the mouse. I can get the mouse coords, sprite coords, then subtract accordingly to get the centre of the sprite which I want to act as the 'origin' at all times. This is to allow the sprite to move around while still being able to turn to the mouse pointer. Then I go onto using atan2 on the coords to get my angle which i believe is in radians, then convert it using the routine used in the Allegro Quick Reference guide by connellybarnes@yahoo.com . Which is (x/2/M_PI*0xFFFFFF) (x being the angle from atan2) Then i fire it into the draw rotate sprite function but the sprite doesnt correctly follow the mouse pointer. Depending on the location of the cursor, the image rotates slowly or quickly or makes several 360 degree turns just from moving 100 or so pixels. Have tried with and without itofix. Any help will be greatly appreciated. Be it psuedo or source. Will credit any sources in my current project. Thanks alot ppl. Mava.

##### Share on other sites
I am not familiar with Allegro but I think I understand the problem.

atan2 and all std:: math functions use radians and I'm assuming allegro uses degrees?

I don't understand where the formula (x/2/M_PI*0xFFFFFF) came from

1 radian = 180/pi = 57.2957795 degrees

let's say you have your mouseX and mouseY and you use atan2 to find the angle in radians

sorry if this wasn't your problem, I'm not familiar enough with allegro to fully understand your problem

##### Share on other sites
Allegro uses 1-255 for 0-360 degress rotation. And the formula i mentioned converts it to that (i think :)

but...

It seems as though i wasnt using it properly. Now i've got it working!
Thanks, i checked over the formula again coz u mentioned it. Newbie mistake really..

Many Thanks again.
Mava

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
633346
• Total Posts
3011452
• ### Who's Online (See full list)

There are no registered users currently online

×