www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/08/18:17:23

Date: Thu, 8 Oct 1998 18:25:52 +0200 (MET DST)
From: Wojciech Piechowski <voyt AT ds2 DOT pg DOT gda DOT pl>
To: djgpp AT delorie DOT com
Subject: Re: Tank Movement
In-Reply-To: <6vh0su$5b7$1@ash.prod.itd.earthlink.net>
Message-ID: <Pine.GSO.3.96.981008180223.1620B-100000@delta.ds2.pg.gda.pl>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019