quaternion.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /// @ref gtx_quaternion
  2. /// @file glm/gtx/quaternion.hpp
  3. ///
  4. /// @see core (dependence)
  5. /// @see gtx_extented_min_max (dependence)
  6. ///
  7. /// @defgroup gtx_quaternion GLM_GTX_quaternion
  8. /// @ingroup gtx
  9. ///
  10. /// Include <glm/gtx/quaternion.hpp> to use the features of this extension.
  11. ///
  12. /// Extented quaternion types and functions
  13. #pragma once
  14. // Dependency:
  15. #include "../glm.hpp"
  16. #include "../gtc/constants.hpp"
  17. #include "../gtc/quaternion.hpp"
  18. #include "../ext/quaternion_exponential.hpp"
  19. #include "../gtx/norm.hpp"
  20. #ifndef GLM_ENABLE_EXPERIMENTAL
  21. # error "GLM: GLM_GTX_quaternion is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
  22. #endif
  23. #if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
  24. # pragma message("GLM: GLM_GTX_quaternion extension included")
  25. #endif
  26. namespace glm
  27. {
  28. /// @addtogroup gtx_quaternion
  29. /// @{
  30. /// Create an identity quaternion.
  31. ///
  32. /// @see gtx_quaternion
  33. template<typename T, qualifier Q>
  34. GLM_FUNC_DECL qua<T, Q> quat_identity();
  35. /// Compute a cross product between a quaternion and a vector.
  36. ///
  37. /// @see gtx_quaternion
  38. template<typename T, qualifier Q>
  39. GLM_FUNC_DECL vec<3, T, Q> cross(
  40. qua<T, Q> const& q,
  41. vec<3, T, Q> const& v);
  42. //! Compute a cross product between a vector and a quaternion.
  43. ///
  44. /// @see gtx_quaternion
  45. template<typename T, qualifier Q>
  46. GLM_FUNC_DECL vec<3, T, Q> cross(
  47. vec<3, T, Q> const& v,
  48. qua<T, Q> const& q);
  49. //! Compute a point on a path according squad equation.
  50. //! q1 and q2 are control points; s1 and s2 are intermediate control points.
  51. ///
  52. /// @see gtx_quaternion
  53. template<typename T, qualifier Q>
  54. GLM_FUNC_DECL qua<T, Q> squad(
  55. qua<T, Q> const& q1,
  56. qua<T, Q> const& q2,
  57. qua<T, Q> const& s1,
  58. qua<T, Q> const& s2,
  59. T const& h);
  60. //! Returns an intermediate control point for squad interpolation.
  61. ///
  62. /// @see gtx_quaternion
  63. template<typename T, qualifier Q>
  64. GLM_FUNC_DECL qua<T, Q> intermediate(
  65. qua<T, Q> const& prev,
  66. qua<T, Q> const& curr,
  67. qua<T, Q> const& next);
  68. //! Returns quarternion square root.
  69. ///
  70. /// @see gtx_quaternion
  71. //template<typename T, qualifier Q>
  72. //qua<T, Q> sqrt(
  73. // qua<T, Q> const& q);
  74. //! Rotates a 3 components vector by a quaternion.
  75. ///
  76. /// @see gtx_quaternion
  77. template<typename T, qualifier Q>
  78. GLM_FUNC_DECL vec<3, T, Q> rotate(
  79. qua<T, Q> const& q,
  80. vec<3, T, Q> const& v);
  81. /// Rotates a 4 components vector by a quaternion.
  82. ///
  83. /// @see gtx_quaternion
  84. template<typename T, qualifier Q>
  85. GLM_FUNC_DECL vec<4, T, Q> rotate(
  86. qua<T, Q> const& q,
  87. vec<4, T, Q> const& v);
  88. /// Extract the real component of a quaternion.
  89. ///
  90. /// @see gtx_quaternion
  91. template<typename T, qualifier Q>
  92. GLM_FUNC_DECL T extractRealComponent(
  93. qua<T, Q> const& q);
  94. /// Converts a quaternion to a 3 * 3 matrix.
  95. ///
  96. /// @see gtx_quaternion
  97. template<typename T, qualifier Q>
  98. GLM_FUNC_DECL mat<3, 3, T, Q> toMat3(
  99. qua<T, Q> const& x){return mat3_cast(x);}
  100. /// Converts a quaternion to a 4 * 4 matrix.
  101. ///
  102. /// @see gtx_quaternion
  103. template<typename T, qualifier Q>
  104. GLM_FUNC_DECL mat<4, 4, T, Q> toMat4(
  105. qua<T, Q> const& x){return mat4_cast(x);}
  106. /// Converts a 3 * 3 matrix to a quaternion.
  107. ///
  108. /// @see gtx_quaternion
  109. template<typename T, qualifier Q>
  110. GLM_FUNC_DECL qua<T, Q> toQuat(
  111. mat<3, 3, T, Q> const& x){return quat_cast(x);}
  112. /// Converts a 4 * 4 matrix to a quaternion.
  113. ///
  114. /// @see gtx_quaternion
  115. template<typename T, qualifier Q>
  116. GLM_FUNC_DECL qua<T, Q> toQuat(
  117. mat<4, 4, T, Q> const& x){return quat_cast(x);}
  118. /// Quaternion interpolation using the rotation short path.
  119. ///
  120. /// @see gtx_quaternion
  121. template<typename T, qualifier Q>
  122. GLM_FUNC_DECL qua<T, Q> shortMix(
  123. qua<T, Q> const& x,
  124. qua<T, Q> const& y,
  125. T const& a);
  126. /// Quaternion normalized linear interpolation.
  127. ///
  128. /// @see gtx_quaternion
  129. template<typename T, qualifier Q>
  130. GLM_FUNC_DECL qua<T, Q> fastMix(
  131. qua<T, Q> const& x,
  132. qua<T, Q> const& y,
  133. T const& a);
  134. /// Compute the rotation between two vectors.
  135. /// param orig vector, needs to be normalized
  136. /// param dest vector, needs to be normalized
  137. ///
  138. /// @see gtx_quaternion
  139. template<typename T, qualifier Q>
  140. GLM_FUNC_DECL qua<T, Q> rotation(
  141. vec<3, T, Q> const& orig,
  142. vec<3, T, Q> const& dest);
  143. /// Returns the squared length of x.
  144. ///
  145. /// @see gtx_quaternion
  146. template<typename T, qualifier Q>
  147. GLM_FUNC_DECL T length2(qua<T, Q> const& q);
  148. /// @}
  149. }//namespace glm
  150. #include "quaternion.inl"