ZoriaRPG

AngularDistance

Sep 2nd, 2018
100
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Returns the (signed) difference between angle a and b.
  2. //i.e., how far in degrees angle a must move to align with angle b.
  3. float AngularDistance(float a, float b)
  4. {
  5.     int s; int ret;
  6.     int d = (Abs(b-a)%360);
  7.     if ( d >= 0 )
  8.     {
  9.         if ( d <= 180 ) { s = -1; }
  10.     }
  11.     else if ( d <= -180 )
  12.     {
  13.         if ( d >= -360 ) { s = -1; }
  14.     }
  15.     else s = 1;
  16.    
  17.     if ( d > 180 )
  18.     {
  19.         return ((360 - d)*s);
  20.     }
  21.     else { return (d*s); }
  22. }
  23.  
  24.  
  25. float AngleDifference(float angle1, float angle2)
  26. {
  27.     int diff = Abs(angle1-angle2);
  28.     if ( angle1 < angle2 )  {    return WrapDegrees(diff)*-1; }
  29.     else return WrapDegrees(diff);
  30. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×