Open Source Tomb Raider Engine
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

MatMath.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 ((float)M_PI) //!< pi
  12. #define HEL_2_PI (HEL_PI * 2.0f) //!< pi*2
  13. #define HEL_PI_OVER_4 (HEL_PI / 4.0f) //!< pi/4
  14. #define HEL_PI_OVER_180 (HEL_PI / 180.0f) //!< pi/180
  15. #define HEL_180_OVER_PI (180.0f / HEL_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 Compare two floats with an Epsilon.
  33. * \param a first float
  34. * \param b second float
  35. * \returns true if a and b are probably the same.
  36. */
  37. bool equalEpsilon(vec_t a, vec_t b);
  38. /*!
  39. * \brief Calculate Intersection of a line and a polygon
  40. * \param intersect Where the intersection is stored, if it exists
  41. * \param p1 First point of line segment
  42. * \param p2 Second point of line segment
  43. * \param polygon polygon vertex array (0 to 2 are used)
  44. * \returns 0 if there is no intersection
  45. */
  46. int helIntersectionLineAndPolygon(vec3_t intersect, vec3_t p1, vec3_t p2, vec3_t *polygon);
  47. /*!
  48. * \brief Calculate the distance from a sphere to a plane
  49. * \param center Center of sphere
  50. * \param radius Radius of sphere
  51. * \param plane Plane
  52. * \returns distance
  53. */
  54. vec_t helDistToSphereFromPlane3v(vec3_t center, vec_t radius, vec4_t plane);
  55. /*!
  56. * \brief Calculate the distance from a box to a plane
  57. * \param min Minimum Point of a bounding box
  58. * \param max Maximum Point of a bounding box
  59. * \param plane Plane
  60. * \returns distance
  61. */
  62. vec_t helDistToBboxFromPlane3v(vec3_t min, vec3_t max, vec4_t plane);
  63. /*!
  64. * \brief Calculate the length of a line segment / the distance between two points
  65. * \param a First point
  66. * \param b Second point
  67. * \returns distance/length
  68. */
  69. vec_t helDist3v(vec3_t a, vec3_t b);
  70. /*!
  71. * \brief Calculates the midpoint between two points / of a line segment
  72. * \param a First point
  73. * \param b Second point
  74. * \param mid Midpoint will be stored here
  75. */
  76. void helMidpoint3v(vec3_t a, vec3_t b, vec3_t mid);
  77. /*!
  78. * \brief Calculates a pseudo-random number
  79. * \param from Lower bound of resulting number
  80. * \param to Upper bound
  81. * \returns random number
  82. */
  83. vec_t helRandomNum(vec_t from, vec_t to);
  84. #endif