Rotating to Mouse (using allegro, but not necessary)

Started by
1 comment, last by Mava_b 18 years, 9 months ago
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.
Advertisement
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

angleDeg = angleRad*(180/M_PI)

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


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

This topic is closed to new replies.

Advertisement