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.

MatMath.h 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. * \brief Calculate Intersection of a line and a polygon
  25. * \param intersect Where the intersection is stored, if it exists
  26. * \param p1 First point of line segment
  27. * \param p2 Second point of line segment
  28. * \param vertexCount number of vertices in polygon
  29. * \param polygon polygon vertex array
  30. * \returns 0 if there is no intersection
  31. */
  32. int helIntersectionLineAndPolygon(vec3_t intersect, vec3_t p1, vec3_t p2, unsigned int vertexCount, vec3_t *polygon);
  33. /*!
  34. * \brief Calculate the distance from a sphere to a plane
  35. * \param center Center of sphere
  36. * \param radius Radius of sphere
  37. * \param plane Plane
  38. * \returns distance
  39. */
  40. vec_t helDistToSphereFromPlane3v(vec3_t center, vec_t radius, vec4_t plane);
  41. /*!
  42. * \brief Calculate the distance from a box to a plane
  43. * \param min Minimum Point of a bounding box
  44. * \param max Maximum Point of a bounding box
  45. * \param plane Plane
  46. * \returns distance
  47. */
  48. vec_t helDistToBboxFromPlane3v(vec3_t min, vec3_t max, vec4_t plane);
  49. /*!
  50. * \brief Calculate the length of a line segment / the distance between two points
  51. * \param a First point
  52. * \param b Second point
  53. * \returns distance/length
  54. */
  55. vec_t helDist3v(vec3_t a, vec3_t b);
  56. /*!
  57. * \brief Calculates the midpoint between two points / of a line segment
  58. * \param a First point
  59. * \param b Second point
  60. * \param mid Midpoint will be stored here
  61. */
  62. void helMidpoint3v(vec3_t a, vec3_t b, vec3_t mid);
  63. /*!
  64. * \brief Calculates a pseudo-random number
  65. * \param from Lower bound of resulting number
  66. * \param to Upper bound
  67. * \returns random number
  68. */
  69. vec_t helRandomNum(vec_t from, vec_t to);
  70. #endif