Mail Archives: djgpp/1999/05/05/09:07:04
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Unigni wrote:
<blockquote TYPE=CITE>The code used in QBasic is:
<p> Angle = ATN((x2 - x1) / (y2 - y1))
<p>where x1,y1 would be the co-ordinates of the enemy ship, and x2,y2 would</blockquote>
<p><br>I think
<p>Angle = atan2(x2 - x1, y2 - y1);
<p>should work for you.
<br>It returns in radians, and is definded in math.h. Also prevents you
from doing
<br>divisions by zero and works for all angles outside +/- pi/2, too.
<br>Maybe these functions are a bit slow for games (they use doubles),
there are
<br>also atan2f(x, y) an float version but I can't say if it's faster (haven't
tested).
<br>Do you really need the angle ? I think you could always use just the
cos(Angle)
<br>and sin(Angle) that you can get more directly:
<p>R = hypot(x2 - x1, y2 - y1); /* sqrt((x2-
x1)*(x2-x1)+(y2-y1)*(y2-y1)) */
<br>CosAngle = (x2 - x1) / R;
<br>SinAngle = (y2 - y1) / R;
<p>That are the values you may need for making one object move in the Angle
<br>direction...
<p>LRMS</html>
- Raw text -