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.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #define OR_PI ((float)M_PI) //!< pi
  13. #define OR_2_PI (OR_PI * 2.0f) //!< pi*2
  14. #define OR_PI_OVER_4 (OR_PI / 4.0f) //!< pi/4
  15. #define OR_PI_OVER_180 (OR_PI / 180.0f) //!< pi/180
  16. #define OR_180_OVER_PI (180.0f / OR_PI) //!< 180/pi
  17. #define OR_RAD_TO_DEG(x) ((x) * OR_180_OVER_PI) //!< Convert radians to degrees
  18. #define OR_DEG_TO_RAD(x) ((x) * OR_PI_OVER_180) //!< Convert degrees to radians
  19. typedef float vec_t; //!< 1D Vector, aka float
  20. typedef float vec2_t[2]; //!< 2D Vector
  21. typedef float vec3_t[3]; //!< 3D Vector
  22. typedef float vec4_t[4]; //!< 4D Vector
  23. typedef vec_t matrix_t[16]; //!< Used as _Column_major_ in every class now!
  24. /*!
  25. * \brief Compare two floats with an Epsilon.
  26. * \param a first float
  27. * \param b second float
  28. * \returns true if a and b are probably the same.
  29. */
  30. bool equalEpsilon(vec_t a, vec_t b);
  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 intersectionLinePolygon(vec3_t intersect, vec3_t p1, vec3_t p2, vec3_t *polygon);
  40. /*!
  41. * \brief Calculate the length of a line segment / the distance between two points
  42. * \param a First point
  43. * \param b Second point
  44. * \returns distance/length
  45. */
  46. vec_t distance(vec3_t a, vec3_t b);
  47. /*!
  48. * \brief Calculates the midpoint between two points / of a line segment
  49. * \param a First point
  50. * \param b Second point
  51. * \param mid Midpoint will be stored here
  52. */
  53. void midpoint(vec3_t a, vec3_t b, vec3_t mid);
  54. /*!
  55. * \brief Calculates a pseudo-random number
  56. * \param from Lower bound of resulting number
  57. * \param to Upper bound
  58. * \returns random number
  59. */
  60. vec_t randomNum(vec_t from, vec_t to);
  61. #endif