Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

math.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
  2. /*================================================================
  3. *
  4. * Project : Freyja
  5. * Author : Terry 'Mongoose' Hendrix II
  6. * Website : http://www.westga.edu/~stu7440/
  7. * Email : stu7440@westga.edu
  8. * Object :
  9. * License : No use w/o permission (C) 2002 Mongoose
  10. * Comments:
  11. *
  12. *
  13. * This file was generated using Mongoose's C++
  14. * template generator script. <stu7440@westga.edu>
  15. *
  16. *-- History ------------------------------------------------
  17. *
  18. * 2002.05.11:
  19. * Mongoose - Created
  20. ================================================================*/
  21. #ifndef __FREYJA_MONGOOSE_MATH_H
  22. #define __FREYJA_MONGOOSE_MATH_H
  23. #define HEL_PI 3.14159265358979323846 /* pi */
  24. #define HEL_PI_OVER_2 1.57079632679489661923 /* pi/2 */
  25. #define HEL_2_PI 6.28318530717958647692 /* pi*2 */
  26. #define HEL_PI_OVER_4 0.78539816339744830962 /* pi/4 */
  27. #define HEL_PI_OVER_180 0.017453292519943295 /* pi/180 */
  28. #define HEL_180_OVER_PI 57.295779513082323 /* 180/pi */
  29. #define HEL_RAD_TO_DEG(x) ((x) * HEL_180_OVER_PI)
  30. #define HEL_DEG_TO_RAD(x) ((x) * HEL_PI_OVER_180)
  31. typedef float vec_t;
  32. typedef float vec2_t[2];
  33. typedef float vec3_t[3];
  34. typedef float vec4_t[4];
  35. typedef vec_t matrix_t[16]; /* Used as _Column_major_ in every class now! */
  36. int helIntersectionLineAndPolygon(vec3_t intersect,
  37. vec3_t p1, vec3_t p2,
  38. unsigned int vertexCount, vec3_t *ploygon);
  39. /*------------------------------------------------------
  40. * Pre : Given P1 and P2 of line segment and
  41. * Vertex count and ploygon with count vertices
  42. *
  43. * Only supports triangles and coplanar quads
  44. *
  45. * Post : Returns intersect point or 0 if none
  46. *
  47. *-- History ------------------------------------------
  48. *
  49. * 2003.05.30:
  50. * Mongoose - Created
  51. ------------------------------------------------------*/
  52. vec_t helDistToSphereFromPlane3v(vec3_t center, vec_t radius, vec4_t plane);
  53. /*------------------------------------------------------
  54. * Pre : Given center and radius of sphere and a plane
  55. * Post : Returns distance from sphere to plane
  56. *
  57. *-- History ------------------------------------------
  58. *
  59. * 1999.06.14:
  60. * Mongoose - Created, from mtk3d
  61. ------------------------------------------------------*/
  62. vec_t helDistToBboxFromPlane3v(vec3_t min, vec3_t max, vec4_t plane);
  63. /*------------------------------------------------------
  64. * Pre : Given min and max points of a bounding box
  65. * and a plane
  66. *
  67. * Post : Returns distance from box to plane
  68. *
  69. *-- History ------------------------------------------
  70. *
  71. * 1999.06.14:
  72. * Mongoose - Created, from mtk3d
  73. ------------------------------------------------------*/
  74. vec_t helDist3v(vec3_t a, vec3_t b);
  75. /*------------------------------------------------------
  76. * Pre : Given point A and B
  77. * Post : Returns length of line segment
  78. *
  79. *-- History ------------------------------------------
  80. *
  81. * 1999.06.14:
  82. * Mongoose - Created, from mtk3d
  83. ------------------------------------------------------*/
  84. void helMidpoint3v(vec3_t a, vec3_t b, vec3_t mid);
  85. /*------------------------------------------------------
  86. * Pre : Given point A and B
  87. * Post : Returns midpoint of line segment
  88. *
  89. *-- History ------------------------------------------
  90. *
  91. * 1999.06.14:
  92. * Mongoose - Created, from mtk3d
  93. ------------------------------------------------------*/
  94. vec_t helDegToRad(vec_t degrees);
  95. /*------------------------------------------------------
  96. * Pre : Given angle in degrees
  97. * Post : Returns angle in radians
  98. *
  99. *-- History ------------------------------------------
  100. *
  101. * 1999.06.14:
  102. * Mongoose - Created, from mtk3d
  103. ------------------------------------------------------*/
  104. vec_t helRadToDeg(vec_t rad);
  105. /*------------------------------------------------------
  106. * Pre : Given angle in radians
  107. * Post : Returns angle in degrees
  108. *
  109. *-- History ------------------------------------------
  110. *
  111. * 1999.06.14:
  112. * Mongoose - Created, from mtk3d
  113. ------------------------------------------------------*/
  114. vec_t helRandomNum(vec_t from, vec_t to);
  115. /* Some cruft for ye olde mtk3d compatibility */
  116. void helVectorMatrixMult4dv(double v[4], matrix_t m, double result[4]);
  117. #endif