quaternion.hpp 4.5 KB

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