Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

math.h 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*!
  2. *
  3. * \file include/math/math.h
  4. * \brief Vector and Matrix math
  5. *
  6. * \author Mongoose
  7. * \author xythobuz
  8. */
  9. #include <math.h>
  10. #ifndef _MATH_MATH_H
  11. #define _MATH_MATH_H
  12. #ifndef M_PI
  13. #define M_PI 3.14159265358979323846
  14. #endif
  15. #define OR_PI ((float)M_PI) //!< pi
  16. #define OR_2_PI (OR_PI * 2.0f) //!< pi*2
  17. #define OR_PI_OVER_4 (OR_PI / 4.0f) //!< pi/4
  18. #define OR_PI_OVER_180 (OR_PI / 180.0f) //!< pi/180
  19. #define OR_180_OVER_PI (180.0f / OR_PI) //!< 180/pi
  20. #define OR_RAD_TO_DEG(x) ((x) * OR_180_OVER_PI) //!< Convert radians to degrees
  21. #define OR_DEG_TO_RAD(x) ((x) * OR_PI_OVER_180) //!< Convert degrees to radians
  22. typedef float vec_t; //!< 1D Vector, aka float
  23. typedef float vec2_t[2]; //!< 2D Vector
  24. typedef float vec3_t[3]; //!< 3D Vector
  25. typedef float vec4_t[4]; //!< 4D Vector
  26. typedef vec_t matrix_t[16]; //!< Used as _Column_major_ in every class now!
  27. /*!
  28. * \brief Compare two floats with an Epsilon.
  29. * \param a first float
  30. * \param b second float
  31. * \returns true if a and b are probably the same.
  32. */
  33. bool equalEpsilon(vec_t a, vec_t b);
  34. /*!
  35. * \brief Calculate Intersection of a line and a polygon
  36. * \param intersect Where the intersection is stored, if it exists
  37. * \param p1 First point of line segment
  38. * \param p2 Second point of line segment
  39. * \param polygon polygon vertex array (0 to 2 are used)
  40. * \returns 0 if there is no intersection
  41. */
  42. int intersectionLinePolygon(vec3_t intersect, vec3_t p1, vec3_t p2, vec3_t *polygon);
  43. /*!
  44. * \brief Calculate the length of a line segment / the distance between two points
  45. * \param a First point
  46. * \param b Second point
  47. * \returns distance/length
  48. */
  49. vec_t distance(const vec3_t a, const vec3_t b);
  50. /*!
  51. * \brief Calculates the midpoint between two points / of a line segment
  52. * \param a First point
  53. * \param b Second point
  54. * \param mid Midpoint will be stored here
  55. */
  56. void midpoint(const vec3_t a, const vec3_t b, vec3_t mid);
  57. /*!
  58. * \brief Calculates a pseudo-random number
  59. * \param from Lower bound of resulting number
  60. * \param to Upper bound
  61. * \returns random number
  62. */
  63. vec_t randomNum(vec_t from, vec_t to);
  64. #endif