Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Problems with rotating co-ordinates

This thread is locked; no one can reply to it. rss feed Print
Problems with rotating co-ordinates
Moonsdescend
Member #4,087
December 2003
avatar

Hi All,

I'm trying to make a sprite rotate according to the mouse position, which I have working, however what I want to do is have a line drawn from a specific position to the mouse cursor.

For example my sprite is 32*32 and the point I want the line to start from is x=29,y=3. The line draws fine if the mouse is directly to the right of the sprite, but once the rotation starts it doesn't line up properly. Basically I want the start of the line to rotate with the sprite.

Any ideas on house this could work?

ngiacomelli
Member #5,114
October 2004

I'll point you towards this wonderful document: http://pixwiki.bafsoft.com/mags/5/articles/circle/sincos.htm

More specifically, this code snippet:

line (screen, fixtoi(x), fixtoi(y),
            fixtoi (x + 9 * fcos (angle)),
            fixtoi (y + 9 * fsin (angle)),
            makecol (255, 0, 0));

Where 9 is the length of the line. The rest is pretty self-explanatory. I hope this is what you wanted.

Jonatan Hedborg
Member #4,886
July 2004
avatar

You probably need to rotate 29,3 by whatever the sprite is rotated by.

Taken from some google result...

newpoint.x= xold*cos(angle)-yold*sin(angle);
newpoint.y= xold*sin(angle)+yold*cos(angle);

Angles in doubles (radians) (or fixed, if you want to use allegros functions. Don't use allegros functions btw =))

Moonsdescend
Member #4,087
December 2003
avatar

Quote:

You probably need to rotate 29,3 by whatever the sprite is rotated by.

I think so.
What I think I need to do is rotate X+29 by angle and Y+3 by angle. This area has never been my strong point :D
So far I've had no luck with the samples that have been posted. They have caused some interesting effects which I might use later on though :D

Jonatan Hedborg
Member #4,886
July 2004
avatar

The code that i posted does just that. What effects are you having? If you are using fixed format angles (which are 0-255, while radians are 0-PI*2), that might be the reason.

Post the relevant code and we can look at it :)

Go to: