1  /********************************************************************** <BR>


2  This file is part of Crack dot Com's free source code release of


3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for


4  information about compiling & licensing issues visit this URL</a>


5  <PRE> If that doesn't help, contact Jonathan Clark at


6  golgotha_source@usa.net (Subject should have "GOLG" in it)


7  ***********************************************************************/


8 


9  #ifndef I4_ANGLE_HH


10  #define I4_ANGLE_HH


11 


12  #include "math/num_type.hh"


13  #include "math/pi.hh"


14 


15  // returns the absolute difference between two angles


16  // this will always be between 0 and 180 degrees


17  inline i4_angle i4_angle_diff(i4_angle angle1, i4_angle angle2)


18  {


19  i4_angle d;


20  if (angle1>angle2)


21  d=angle1angle2;


22  else


23  d=angle2angle1;


24  if (d>i4_pi())


25  return 2*i4_pi()d;


26  else


27  return d;


28  }


29 


30  // returns the clockwise distance from angle2 to angle1, this may be over 180 degrees


31  inline i4_angle i4_angle_minus(i4_angle angle1, i4_angle angle2)


32  {


33  if (angle1>angle2)


34  return angle1angle2;


35  else


36  return angle1+2*i4_pi()angle2;


37  }


38 


39  inline i4_angle i4_interpolate_angle(i4_angle from, i4_angle to, i4_float fraction)


40  {


41  i4_angle diff=i4_angle_diff(from, to) * fraction;


42  if (i4_angle_minus(to, from)>=i4_pi())


43  return fromdiff;


44  else


45  return from+diff;


46  }


47 


48  inline void i4_normalize_angle(i4_float &angle)


49  {


50  while (angle<0) angle += (i4_2pi());


51  while (angle>=i4_2pi()) angle = (i4_2pi());


52  }


53 


54  inline i4_float i4_rotate_to(i4_float &from, i4_float to, i4_float speed)


55  {


56  i4_float dangle;


57  sw8 rot_dir = 0;


58 


59  dangle = (tofrom);


60  if (dangle>i4_pi())


61  dangle = 2*i4_pi();


62  else if (dangle<i4_pi())


63  dangle += 2*i4_pi();


64 


65  if (dangle>speed) dangle = speed;


66  else if (dangle<speed) dangle = speed;


67 


68  from += dangle;


69  i4_normalize_angle(from);


70 


71  return dangle;


72  }


73 


74 


75  #endif

