Mail Archives: djgpp/1998/10/08/18:17:23
Chris Brooker wrote in message <36147a32 DOT 10039817 AT ct-news DOT iafrica DOT com>...
>Hi,
>Sorry if my code sucks, I a mquite new to C.
>I am busy writing a Real Time Strategy ...
>double dir_degrees(int x1, int y1, int y2, int x2)
>{
> int v1, v2;
> double dir;
> v1 = y1 - y2;
> v2 = x1 - x2;
> if (v2 == 0)
> v2++; //Stops division by zero errors
> dir = 57 * atan(v1 / v2);
> return dir;
>}
I would rather do this:
double dir_degrees(...)
{
return atan2(y1-y2, x1-x2) * 180/M_PI;
}
--------------------\ Wojciech Piechowski /----------------------------
Student informatyki \ voyt AT ds2 DOT pg DOT gda DOT pl / Student of computer science
Politechnika Gdanska \________________/ Technical University of Gdansk
- Raw text -