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.

Quaternion.h 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*!
  2. * \file include/Quaternion.h
  3. * \brief Quaternion
  4. *
  5. * \author Mongoose
  6. */
  7. #ifndef _QUATERNION_H_
  8. #define _QUATERNION_H_
  9. #include "utils/math.h"
  10. /*!
  11. * \brief Quaternion
  12. */
  13. class Quaternion {
  14. public:
  15. /*!
  16. * \brief Constructs an object of Quaternion
  17. */
  18. Quaternion();
  19. /*!
  20. * \brief Constructs an object of Quaternion
  21. * \param w W part of new Quaternion
  22. * \param x X part of new Quaternion
  23. * \param y Y part of new Quaternion
  24. * \param z Z part of new Quaternion
  25. */
  26. Quaternion(vec_t w, vec_t x, vec_t y, vec_t z);
  27. /*!
  28. * \brief Constructs an object of Quaternion
  29. * \param v contents of new Quaternion
  30. */
  31. Quaternion(vec4_t v);
  32. /*!
  33. * \brief Get column order matrix equivalent of this quaternion
  34. * \param m where matrix will be stored
  35. */
  36. void getMatrix(matrix_t m);
  37. /*!
  38. * \brief Multiplies this quaternion.
  39. *
  40. * Use normalize() call for unit quaternion.
  41. *
  42. * \param q what to multiply this quaternion with
  43. * \returns resultant quaternion
  44. * \sa Quaternion::normalize()
  45. */
  46. Quaternion operator *(const Quaternion &q);
  47. /*!
  48. * \brief Divide from this quaternion
  49. * \param q what to divide from this quaternion
  50. * \returns resultant quaternion
  51. */
  52. Quaternion operator /(const Quaternion &q);
  53. /*!
  54. * \brief Add to this quaternion
  55. * \param q what to add to this quaternion
  56. * \returns resultant quaternion
  57. */
  58. Quaternion operator +(const Quaternion &q);
  59. /*!
  60. * \brief Subtract from this quaternion
  61. * \param q what to subtract from this quaternion
  62. * \returns resultant quaternion
  63. */
  64. Quaternion operator -(const Quaternion &q);
  65. /*!
  66. * \brief Compares q to this quaternion
  67. * \param q what to compare this quaternion to
  68. * \returns true if equal, false otherwise
  69. */
  70. bool operator ==(const Quaternion &q);
  71. /*!
  72. * \brief Conjugate this quaternion
  73. * \returns Conjugate of this quaternion
  74. */
  75. Quaternion conjugate();
  76. /*!
  77. * \brief Scale this quaternion
  78. * \param s scaling factor
  79. * \returns Scaled result of this quaternion
  80. */
  81. Quaternion scale(vec_t s);
  82. /*!
  83. * \brief Inverse this quaternion
  84. * \returns inverse of this quaternion
  85. */
  86. Quaternion inverse();
  87. /*!
  88. * \brief Dot Product of quaternions
  89. * \param a first argument to dot product
  90. * \param b second argument to dot product
  91. * \returns dot product between a and b quaternions
  92. */
  93. static vec_t dot(Quaternion a, Quaternion b);
  94. /*!
  95. * \brief Magnitude of this quaternion
  96. * \returns Magnitude of this quaternion
  97. */
  98. vec_t magnitude();
  99. /*!
  100. * \brief Interpolates between a and b rotations.
  101. *
  102. * Using spherical linear interpolation:
  103. * `I = (((B . A)^-1)^Time)A`
  104. *
  105. * \param a first argument for slerp
  106. * \param b second argument for slerp
  107. * \param time time argument for slerp
  108. * \returns resultant quaternion
  109. */
  110. static Quaternion slerp(Quaternion a, Quaternion b, vec_t time);
  111. /*!
  112. * \brief Sets this quaternion to identity
  113. */
  114. void setIdentity();
  115. /*!
  116. * \brief Sets this quaternion
  117. * \param angle new angle
  118. * \param x new X coordinate
  119. * \param y new Y coordinate
  120. * \param z new Z coordinate
  121. */
  122. void set(vec_t angle, vec_t x, vec_t y, vec_t z);
  123. /*!
  124. * \brief Normalize this quaternion
  125. */
  126. void normalize();
  127. /*!
  128. * \brief Set this quaternion
  129. * \param q will be copied into this quaternion
  130. */
  131. void copy(Quaternion q);
  132. /*!
  133. * \brief Sets matrix equivalent of this quaternion
  134. * \param m matrix in valid column order
  135. */
  136. void setByMatrix(matrix_t m);
  137. private:
  138. /*!
  139. * \brief Multiplies two quaternions
  140. * \param a first argument to multiplication
  141. * \param b second argument to multiplication
  142. * \returns resultant quaternion
  143. */
  144. static Quaternion multiply(Quaternion a, Quaternion b);
  145. /*!
  146. * \brief Divides B from A quaternion
  147. * \param a first argument to division
  148. * \param b second argument to division
  149. * \returns quotient quaternion
  150. */
  151. static Quaternion divide(Quaternion a, Quaternion b);
  152. /*!
  153. * \brief Adds A and B quaternions
  154. * \param a first argument to addition
  155. * \param b second argument to addition
  156. * \returns resultant quaternion
  157. */
  158. static Quaternion add(Quaternion a, Quaternion b);
  159. /*!
  160. * \brief Subtracts B from A quaternion
  161. * \param a first argument to subtraction
  162. * \param b second argument to subtraction
  163. * \returns resultant quaternion
  164. */
  165. static Quaternion subtract(Quaternion a, Quaternion b);
  166. vec_t mW; //!< Quaternion, W part
  167. vec_t mX; //!< Quaternion, X part
  168. vec_t mY; //!< Quaternion, Y part
  169. vec_t mZ; //!< Quaternion, Z part
  170. };
  171. #endif