In my "skeleton poser" project, I needed an atan2 function and I had to write my own (using atan and some if blocks). atan2 is a standard function in most math libraries and is used to convert a 2d vector (dx, dy) to an angle in the full 360 degree range. I use atan2 to rotate a sprite by clicking and dragging on it and I can't just use point-towards-mouse because the rotation is relative to the current direction as well as where the sprite was grabbed.
Having a built-in atan2 function would make my project simpler. More importantly, it would make my sprites more portable (and understandable to other users) because the sprites wouldn't need to depend on the global atan2 script.
Offline
What is atan2?
Offline
Yeah, we already have some trig functions. Why not get the rest of them?
Offline
In a nutshell, if you have two points (call them x1,y1 and x2,y2), and you want to know what direction to go in to get from the first point to the second, atan2 will tell you:
direction = atan2(y2-y1, x2-x1)
Last edited by erbie (2009-01-08 21:59:51)
Offline
oh ok
Offline