[gameprogrammer] Re: Diff Between 2 Angles

  • From: Robbert de Groot <zekaric@xxxxxxxx>
  • To: gameprogrammer@xxxxxxxxxxxxx
  • Date: Thu, 29 Sep 2005 11:49:23 -0400 (EDT)

if (angle < 0) {
   angle  = -angle;
   negate = -1;
}
else {
   negate = 1;
}

while (angle > 360) {
   angle -= 360;
}

if (angle > 180) {
   return negate * (angle - 180);
}
return negate * angle;


--- Stephen <stephen@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:

> I've got a really simple problem that I'm almost ashamed to ask
> about!  
> I've written a 3D pseudo-realtime strategy game called Lazer Squad
> 3D 
> (www.carlylesmith.karoo.net/lazersquad3d/).  One problem I always
> think 
> I've solved, but then comes back to bite me, is how to get the 
> difference between two angles.  This seems easy on the face of it,
> but 
> then along comes two angles and my formula gets it all wrong. 
> (This is 
> degrees, BTW, not rads).
> 
> The main problem is when dealing with negative angles, angles >
> 360, and 
> also getting the shortest distance (i.e. not the long way round). 
> For 
> example, the difference between -359 and 359 should be 2 degrees. 
> The 
> difference between 90 and -270 should be zero.  Etc.. etc.. Can
> anyone 
> help please?
> 
> Thanks in advance,
> 
> Steve Smith
> 
> 
> 
> 
> 
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
> 
> 
> 



        

        
                
__________________________________________________________ 
Find your next car at http://autos.yahoo.ca


---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: