home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / XenonSource.exe / gamesystem / includes / gs_maths.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-20  |  1.6 KB  |  77 lines

  1. //-------------------------------------------------------------
  2. //
  3. // File:    Maths functions
  4. //
  5. // Author:    John M Phillips
  6. //
  7. // Started:    13/05/00
  8. //
  9. //-------------------------------------------------------------
  10.  
  11. #ifndef _INCLUDE_GS_MATHS_H
  12. #define _INCLUDE_GS_MATHS_H
  13.  
  14. #include <math.h>
  15.  
  16. //-------------------------------------------------------------
  17. // Maths constants
  18.  
  19. const float gsPI = 3.141592654f;
  20.  
  21. //-------------------------------------------------------------
  22. // Radian to Degree conversion
  23.  
  24. inline float gsRad2Deg(float angle)
  25. {
  26.     return angle * (180.f / gsPI);
  27. }
  28.  
  29. //-------------------------------------------------------------
  30. // Degree to radian conversion
  31.  
  32. inline float gsDeg2Rad(float angle)
  33. {
  34.     return angle * (gsPI / 180.f);
  35. }
  36.  
  37. //-------------------------------------------------------------
  38. // Trig functions (using angles in degrees)
  39.  
  40. inline float gsSin(float angle)
  41. {
  42.     return (float) sin((double) gsDeg2Rad(angle));
  43. }
  44.  
  45. //-------------------------------------------------------------
  46.  
  47. inline float gsCos(float angle)
  48. {
  49.     return (float) cos((double) gsDeg2Rad(angle));
  50. }
  51.  
  52. //-------------------------------------------------------------
  53.  
  54. inline float gsArcTan(float y,float x)
  55. {
  56.     return gsRad2Deg((float) atan2((double) y,(double) x));
  57. }
  58.  
  59. //-------------------------------------------------------------
  60.  
  61. inline float gsAbs(float v)
  62. {
  63.     return v >= 0.f ? v : -v;
  64. }
  65.  
  66. //-------------------------------------------------------------
  67.  
  68. inline float gsSquareRoot(float a)
  69. {
  70.     return (float) sqrt((double) a);
  71. }
  72.  
  73. //-------------------------------------------------------------
  74.  
  75. #endif
  76.  
  77.