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 /// @brief Extented quaternion types and functions 11 /// 12 /// <glm/gtx/quaternion.hpp> need to be included to use these functionalities. 13 14 #pragma once 15 16 // Dependency: 17 #include "../glm.hpp" 18 #include "../gtc/constants.hpp" 19 #include "../gtc/quaternion.hpp" 20 #include "../gtx/norm.hpp" 21 22 #if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED) 23 # pragma message("GLM: GLM_GTX_quaternion extension included") 24 #endif 25 26 namespace glm 27 { 28 /// @addtogroup gtx_quaternion 29 /// @{ 30 31 /// Compute a cross product between a quaternion and a vector. 32 /// 33 /// @see gtx_quaternion 34 template<typename T, precision P> 35 GLM_FUNC_DECL tvec3<T, P> cross( 36 tquat<T, P> const & q, 37 tvec3<T, P> const & v); 38 39 //! Compute a cross product between a vector and a quaternion. 40 /// 41 /// @see gtx_quaternion 42 template<typename T, precision P> 43 GLM_FUNC_DECL tvec3<T, P> cross( 44 tvec3<T, P> const & v, 45 tquat<T, P> const & q); 46 47 //! Compute a point on a path according squad equation. 48 //! q1 and q2 are control points; s1 and s2 are intermediate control points. 49 /// 50 /// @see gtx_quaternion 51 template<typename T, precision P> 52 GLM_FUNC_DECL tquat<T, P> squad( 53 tquat<T, P> const & q1, 54 tquat<T, P> const & q2, 55 tquat<T, P> const & s1, 56 tquat<T, P> const & s2, 57 T const & h); 58 59 //! Returns an intermediate control point for squad interpolation. 60 /// 61 /// @see gtx_quaternion 62 template<typename T, precision P> 63 GLM_FUNC_DECL tquat<T, P> intermediate( 64 tquat<T, P> const & prev, 65 tquat<T, P> const & curr, 66 tquat<T, P> const & next); 67 68 //! Returns a exp of a quaternion. 69 /// 70 /// @see gtx_quaternion 71 template<typename T, precision P> 72 GLM_FUNC_DECL tquat<T, P> exp( 73 tquat<T, P> const & q); 74 75 //! Returns a log of a quaternion. 76 /// 77 /// @see gtx_quaternion 78 template<typename T, precision P> 79 GLM_FUNC_DECL tquat<T, P> log( 80 tquat<T, P> const & q); 81 82 /// Returns x raised to the y power. 83 /// 84 /// @see gtx_quaternion 85 template<typename T, precision P> 86 GLM_FUNC_DECL tquat<T, P> pow( 87 tquat<T, P> const & x, 88 T const & y); 89 90 //! Returns quarternion square root. 91 /// 92 /// @see gtx_quaternion 93 //template<typename T, precision P> 94 //tquat<T, P> sqrt( 95 // tquat<T, P> const & q); 96 97 //! Rotates a 3 components vector by a quaternion. 98 /// 99 /// @see gtx_quaternion 100 template<typename T, precision P> 101 GLM_FUNC_DECL tvec3<T, P> rotate( 102 tquat<T, P> const & q, 103 tvec3<T, P> const & v); 104 105 /// Rotates a 4 components vector by a quaternion. 106 /// 107 /// @see gtx_quaternion 108 template<typename T, precision P> 109 GLM_FUNC_DECL tvec4<T, P> rotate( 110 tquat<T, P> const & q, 111 tvec4<T, P> const & v); 112 113 /// Extract the real component of a quaternion. 114 /// 115 /// @see gtx_quaternion 116 template<typename T, precision P> 117 GLM_FUNC_DECL T extractRealComponent( 118 tquat<T, P> const & q); 119 120 /// Converts a quaternion to a 3 * 3 matrix. 121 /// 122 /// @see gtx_quaternion 123 template<typename T, precision P> toMat3(tquat<T,P> const & x)124 GLM_FUNC_DECL tmat3x3<T, P> toMat3( 125 tquat<T, P> const & x){return mat3_cast(x);} 126 127 /// Converts a quaternion to a 4 * 4 matrix. 128 /// 129 /// @see gtx_quaternion 130 template<typename T, precision P> toMat4(tquat<T,P> const & x)131 GLM_FUNC_DECL tmat4x4<T, P> toMat4( 132 tquat<T, P> const & x){return mat4_cast(x);} 133 134 /// Converts a 3 * 3 matrix to a quaternion. 135 /// 136 /// @see gtx_quaternion 137 template<typename T, precision P> toQuat(tmat3x3<T,P> const & x)138 GLM_FUNC_DECL tquat<T, P> toQuat( 139 tmat3x3<T, P> const & x){return quat_cast(x);} 140 141 /// Converts a 4 * 4 matrix to a quaternion. 142 /// 143 /// @see gtx_quaternion 144 template<typename T, precision P> toQuat(tmat4x4<T,P> const & x)145 GLM_FUNC_DECL tquat<T, P> toQuat( 146 tmat4x4<T, P> const & x){return quat_cast(x);} 147 148 /// Quaternion interpolation using the rotation short path. 149 /// 150 /// @see gtx_quaternion 151 template<typename T, precision P> 152 GLM_FUNC_DECL tquat<T, P> shortMix( 153 tquat<T, P> const & x, 154 tquat<T, P> const & y, 155 T const & a); 156 157 /// Quaternion normalized linear interpolation. 158 /// 159 /// @see gtx_quaternion 160 template<typename T, precision P> 161 GLM_FUNC_DECL tquat<T, P> fastMix( 162 tquat<T, P> const & x, 163 tquat<T, P> const & y, 164 T const & a); 165 166 /// Compute the rotation between two vectors. 167 /// param orig vector, needs to be normalized 168 /// param dest vector, needs to be normalized 169 /// 170 /// @see gtx_quaternion 171 template<typename T, precision P> 172 GLM_FUNC_DECL tquat<T, P> rotation( 173 tvec3<T, P> const & orig, 174 tvec3<T, P> const & dest); 175 176 /// Returns the squared length of x. 177 /// 178 /// @see gtx_quaternion 179 template<typename T, precision P> 180 GLM_FUNC_DECL T length2(tquat<T, P> const & q); 181 182 /// @} 183 }//namespace glm 184 185 #include "quaternion.inl" 186