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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*!
  2. *
  3. * \file include/MatMath.h
  4. * \brief Vector and Matrix math
  5. *
  6. * \author Mongoose
  7. */
  8. #include <math.h>
  9. #ifndef _MATMATH_H
  10. #define _MATMATH_H
  11. #define HEL_PI M_PI //!< pi
  12. #define HEL_2_PI (M_PI * 2.0) //!< pi*2
  13. #define HEL_PI_OVER_4 M_PI_4 //!< pi/4
  14. #define HEL_PI_OVER_180 (M_PI / 180.0) //!< pi/180
  15. #define HEL_180_OVER_PI (180.0 / M_PI) //!< 180/pi
  16. #define HEL_RAD_TO_DEG(x) ((x) * HEL_180_OVER_PI) //!< Convert radians to degrees
  17. #define HEL_DEG_TO_RAD(x) ((x) * HEL_PI_OVER_180) //!< Convert degrees to radians
  18. typedef float vec_t; //!< 1D Vector, aka float
  19. typedef float vec2_t[2]; //!< 2D Vector
  20. typedef float vec3_t[3]; //!< 3D Vector
  21. typedef float vec4_t[4]; //!< 4D Vector
  22. typedef vec_t matrix_t[16]; //!< Used as _Column_major_ in every class now!
  23. /*!
  24. * \fixme Add Documentation or remove, as it is unused?
  25. */
  26. vec_t helIntersectionOfAbstractSpheres(vec3_t centerA, vec_t radiusA, vec3_t centerB, vec_t radiusB);
  27. /*!
  28. * \fixme Add Documentation or remove, as it is unused?
  29. */
  30. int helIntersectionOfAbstractSphereAndLine(vec3_t center, vec_t radius, vec3_t posA, vec3_t posB, vec3_t intersectionA, vec3_t intersectionB);
  31. /*!
  32. * \brief Calculate Intersection of a line and a polygon
  33. * \param intersect Where the intersection is stored, if it exists
  34. * \param p1 First point of line segment
  35. * \param p2 Second point of line segment
  36. * \param polygon polygon vertex array (0 to 2 are used)
  37. * \returns 0 if there is no intersection
  38. */
  39. int helIntersectionLineAndPolygon(vec3_t intersect, vec3_t p1, vec3_t p2, vec3_t *polygon);
  40. /*!
  41. * \brief Calculate the distance from a sphere to a plane
  42. * \param center Center of sphere
  43. * \param radius Radius of sphere
  44. * \param plane Plane
  45. * \returns distance
  46. */
  47. vec_t helDistToSphereFromPlane3v(vec3_t center, vec_t radius, vec4_t plane);
  48. /*!
  49. * \brief Calculate the distance from a box to a plane
  50. * \param min Minimum Point of a bounding box
  51. * \param max Maximum Point of a bounding box
  52. * \param plane Plane
  53. * \returns distance
  54. */
  55. vec_t helDistToBboxFromPlane3v(vec3_t min, vec3_t max, vec4_t plane);
  56. /*!
  57. * \brief Calculate the length of a line segment / the distance between two points
  58. * \param a First point
  59. * \param b Second point
  60. * \returns distance/length
  61. */
  62. vec_t helDist3v(vec3_t a, vec3_t b);
  63. /*!
  64. * \brief Calculates the midpoint between two points / of a line segment
  65. * \param a First point
  66. * \param b Second point
  67. * \param mid Midpoint will be stored here
  68. */
  69. void helMidpoint3v(vec3_t a, vec3_t b, vec3_t mid);
  70. /*!
  71. * \brief Calculates a pseudo-random number
  72. * \param from Lower bound of resulting number
  73. * \param to Upper bound
  74. * \returns random number
  75. */
  76. vec_t helRandomNum(vec_t from, vec_t to);
  77. #endif