Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

223 lines
6.0KB

  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 "../gtx/norm.hpp"
  19. #ifndef GLM_ENABLE_EXPERIMENTAL
  20. # 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."
  21. #endif
  22. #if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !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 tquat<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 vec<3, T, Q> cross(
  39. tquat<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 vec<3, T, Q> cross(
  46. vec<3, T, Q> const& v,
  47. tquat<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 tquat<T, Q> squad(
  54. tquat<T, Q> const& q1,
  55. tquat<T, Q> const& q2,
  56. tquat<T, Q> const& s1,
  57. tquat<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 tquat<T, Q> intermediate(
  64. tquat<T, Q> const& prev,
  65. tquat<T, Q> const& curr,
  66. tquat<T, Q> const& next);
  67. //! Returns a exp of a quaternion.
  68. ///
  69. /// @see gtx_quaternion
  70. template<typename T, qualifier Q>
  71. GLM_FUNC_DECL tquat<T, Q> exp(
  72. tquat<T, Q> const& q);
  73. //! Returns a log of a quaternion.
  74. ///
  75. /// @see gtx_quaternion
  76. template<typename T, qualifier Q>
  77. GLM_FUNC_DECL tquat<T, Q> log(
  78. tquat<T, Q> const& q);
  79. /// Returns x raised to the y power.
  80. ///
  81. /// @see gtx_quaternion
  82. template<typename T, qualifier Q>
  83. GLM_FUNC_DECL tquat<T, Q> pow(
  84. tquat<T, Q> const& x,
  85. T const& y);
  86. //! Returns quarternion square root.
  87. ///
  88. /// @see gtx_quaternion
  89. //template<typename T, qualifier Q>
  90. //tquat<T, Q> sqrt(
  91. // tquat<T, Q> const& q);
  92. //! Rotates a 3 components vector by a quaternion.
  93. ///
  94. /// @see gtx_quaternion
  95. template<typename T, qualifier Q>
  96. GLM_FUNC_DECL vec<3, T, Q> rotate(
  97. tquat<T, Q> const& q,
  98. vec<3, T, Q> const& v);
  99. /// Rotates a 4 components vector by a quaternion.
  100. ///
  101. /// @see gtx_quaternion
  102. template<typename T, qualifier Q>
  103. GLM_FUNC_DECL vec<4, T, Q> rotate(
  104. tquat<T, Q> const& q,
  105. vec<4, T, Q> const& v);
  106. /// Extract the real component of a quaternion.
  107. ///
  108. /// @see gtx_quaternion
  109. template<typename T, qualifier Q>
  110. GLM_FUNC_DECL T extractRealComponent(
  111. tquat<T, Q> const& q);
  112. /// Converts a quaternion to a 3 * 3 matrix.
  113. ///
  114. /// @see gtx_quaternion
  115. template<typename T, qualifier Q>
  116. GLM_FUNC_DECL mat<3, 3, T, Q> toMat3(
  117. tquat<T, Q> const& x){return mat3_cast(x);}
  118. /// Converts a quaternion to a 4 * 4 matrix.
  119. ///
  120. /// @see gtx_quaternion
  121. template<typename T, qualifier Q>
  122. GLM_FUNC_DECL mat<4, 4, T, Q> toMat4(
  123. tquat<T, Q> const& x){return mat4_cast(x);}
  124. /// Converts a 3 * 3 matrix to a quaternion.
  125. ///
  126. /// @see gtx_quaternion
  127. template<typename T, qualifier Q>
  128. GLM_FUNC_DECL tquat<T, Q> toQuat(
  129. mat<3, 3, T, Q> const& x){return quat_cast(x);}
  130. /// Converts a 4 * 4 matrix to a quaternion.
  131. ///
  132. /// @see gtx_quaternion
  133. template<typename T, qualifier Q>
  134. GLM_FUNC_DECL tquat<T, Q> toQuat(
  135. mat<4, 4, T, Q> const& x){return quat_cast(x);}
  136. /// Quaternion interpolation using the rotation short path.
  137. ///
  138. /// @see gtx_quaternion
  139. template<typename T, qualifier Q>
  140. GLM_FUNC_DECL tquat<T, Q> shortMix(
  141. tquat<T, Q> const& x,
  142. tquat<T, Q> const& y,
  143. T const& a);
  144. /// Quaternion normalized linear interpolation.
  145. ///
  146. /// @see gtx_quaternion
  147. template<typename T, qualifier Q>
  148. GLM_FUNC_DECL tquat<T, Q> fastMix(
  149. tquat<T, Q> const& x,
  150. tquat<T, Q> const& y,
  151. T const& a);
  152. /// Compute the rotation between two vectors.
  153. /// param orig vector, needs to be normalized
  154. /// param dest vector, needs to be normalized
  155. ///
  156. /// @see gtx_quaternion
  157. template<typename T, qualifier Q>
  158. GLM_FUNC_DECL tquat<T, Q> rotation(
  159. vec<3, T, Q> const& orig,
  160. vec<3, T, Q> const& dest);
  161. /// Build a look at quaternion based on the default handedness.
  162. ///
  163. /// @param direction Desired forward direction. Needs to be normalized.
  164. /// @param up Up vector, how the camera is oriented. Typically (0, 1, 0).
  165. template<typename T, qualifier Q>
  166. GLM_FUNC_DECL tquat<T, Q> quatLookAt(
  167. vec<3, T, Q> const& direction,
  168. vec<3, T, Q> const& up);
  169. /// Build a right-handed look at quaternion.
  170. ///
  171. /// @param direction Desired forward direction onto which the -z-axis gets mapped. Needs to be normalized.
  172. /// @param up Up vector, how the camera is oriented. Typically (0, 1, 0).
  173. template<typename T, qualifier Q>
  174. GLM_FUNC_DECL tquat<T, Q> quatLookAtRH(
  175. vec<3, T, Q> const& direction,
  176. vec<3, T, Q> const& up);
  177. /// Build a left-handed look at quaternion.
  178. ///
  179. /// @param direction Desired forward direction onto which the +z-axis gets mapped. Needs to be normalized.
  180. /// @param up Up vector, how the camera is oriented. Typically (0, 1, 0).
  181. template<typename T, qualifier Q>
  182. GLM_FUNC_DECL tquat<T, Q> quatLookAtLH(
  183. vec<3, T, Q> const& direction,
  184. vec<3, T, Q> const& up);
  185. /// Returns the squared length of x.
  186. ///
  187. /// @see gtx_quaternion
  188. template<typename T, qualifier Q>
  189. GLM_FUNC_DECL T length2(tquat<T, Q> const& q);
  190. /// @}
  191. }//namespace glm
  192. #include "quaternion.inl"