quaternion.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. /// Extended 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. #elif GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
  23. # pragma message("GLM: GLM_GTX_quaternion extension included")
  24. #endif
  25. namespace glm
  26. {
  27. /// @addtogroup gtx_quaternion
  28. /// @{
  29. /// Create an identity quaternion.
  30. ///
  31. /// @see gtx_quaternion
  32. template<typename T, qualifier Q>
  33. GLM_FUNC_DECL GLM_CONSTEXPR qua<T, Q> quat_identity();
  34. /// Compute a cross product between a quaternion and a vector.
  35. ///
  36. /// @see gtx_quaternion
  37. template<typename T, qualifier Q>
  38. GLM_FUNC_DECL GLM_CONSTEXPR vec<3, T, Q> cross(
  39. qua<T, Q> const& q,
  40. vec<3, T, Q> const& v);
  41. //! Compute a cross product between a vector and a quaternion.
  42. ///
  43. /// @see gtx_quaternion
  44. template<typename T, qualifier Q>
  45. GLM_FUNC_DECL GLM_CONSTEXPR vec<3, T, Q> cross(
  46. vec<3, T, Q> const& v,
  47. qua<T, Q> const& q);
  48. //! Compute a point on a path according squad equation.
  49. //! q1 and q2 are control points; s1 and s2 are intermediate control points.
  50. ///
  51. /// @see gtx_quaternion
  52. template<typename T, qualifier Q>
  53. GLM_FUNC_DECL qua<T, Q> squad(
  54. qua<T, Q> const& q1,
  55. qua<T, Q> const& q2,
  56. qua<T, Q> const& s1,
  57. qua<T, Q> const& s2,
  58. T const& h);
  59. //! Returns an intermediate control point for squad interpolation.
  60. ///
  61. /// @see gtx_quaternion
  62. template<typename T, qualifier Q>
  63. GLM_FUNC_DECL qua<T, Q> intermediate(
  64. qua<T, Q> const& prev,
  65. qua<T, Q> const& curr,
  66. qua<T, Q> const& next);
  67. //! Returns quarternion square root.
  68. ///
  69. /// @see gtx_quaternion
  70. //template<typename T, qualifier Q>
  71. //qua<T, Q> sqrt(
  72. // qua<T, Q> const& q);
  73. //! Rotates a 3 components vector by a quaternion.
  74. ///
  75. /// @see gtx_quaternion
  76. template<typename T, qualifier Q>
  77. GLM_FUNC_DECL vec<3, T, Q> rotate(
  78. qua<T, Q> const& q,
  79. vec<3, T, Q> const& v);
  80. /// Rotates a 4 components vector by a quaternion.
  81. ///
  82. /// @see gtx_quaternion
  83. template<typename T, qualifier Q>
  84. GLM_FUNC_DECL vec<4, T, Q> rotate(
  85. qua<T, Q> const& q,
  86. vec<4, T, Q> const& v);
  87. /// Extract the real component of a quaternion.
  88. ///
  89. /// @see gtx_quaternion
  90. template<typename T, qualifier Q>
  91. GLM_FUNC_DECL T extractRealComponent(
  92. qua<T, Q> const& q);
  93. /// Converts a quaternion to a 3 * 3 matrix.
  94. ///
  95. /// @see gtx_quaternion
  96. template<typename T, qualifier Q>
  97. GLM_FUNC_QUALIFIER mat<3, 3, T, Q> toMat3(
  98. qua<T, Q> const& x){return mat3_cast(x);}
  99. /// Converts a quaternion to a 4 * 4 matrix.
  100. ///
  101. /// @see gtx_quaternion
  102. template<typename T, qualifier Q>
  103. GLM_FUNC_QUALIFIER mat<4, 4, T, Q> toMat4(
  104. qua<T, Q> const& x){return mat4_cast(x);}
  105. /// Converts a 3 * 3 matrix to a quaternion.
  106. ///
  107. /// @see gtx_quaternion
  108. template<typename T, qualifier Q>
  109. GLM_FUNC_QUALIFIER qua<T, Q> toQuat(
  110. mat<3, 3, T, Q> const& x){return quat_cast(x);}
  111. /// Converts a 4 * 4 matrix to a quaternion.
  112. ///
  113. /// @see gtx_quaternion
  114. template<typename T, qualifier Q>
  115. GLM_FUNC_QUALIFIER qua<T, Q> toQuat(
  116. mat<4, 4, T, Q> const& x){return quat_cast(x);}
  117. /// Quaternion interpolation using the rotation short path.
  118. ///
  119. /// @see gtx_quaternion
  120. template<typename T, qualifier Q>
  121. GLM_FUNC_DECL qua<T, Q> shortMix(
  122. qua<T, Q> const& x,
  123. qua<T, Q> const& y,
  124. T const& a);
  125. /// Quaternion normalized linear interpolation.
  126. ///
  127. /// @see gtx_quaternion
  128. template<typename T, qualifier Q>
  129. GLM_FUNC_DECL qua<T, Q> fastMix(
  130. qua<T, Q> const& x,
  131. qua<T, Q> const& y,
  132. T const& a);
  133. /// Compute the rotation between two vectors.
  134. /// @param orig vector, needs to be normalized
  135. /// @param dest vector, needs to be normalized
  136. ///
  137. /// @see gtx_quaternion
  138. template<typename T, qualifier Q>
  139. GLM_FUNC_DECL qua<T, Q> rotation(
  140. vec<3, T, Q> const& orig,
  141. vec<3, T, Q> const& dest);
  142. /// Returns the squared length of x.
  143. ///
  144. /// @see gtx_quaternion
  145. template<typename T, qualifier Q>
  146. GLM_FUNC_DECL GLM_CONSTEXPR T length2(qua<T, Q> const& q);
  147. /// @}
  148. }//namespace glm
  149. #include "quaternion.inl"