1 /// @ref gtx_dual_quaternion 2 /// @file glm/gtx/dual_quaternion.hpp 3 /// @author Maksim Vorobiev (msomeone@gmail.com) 4 /// 5 /// @see core (dependence) 6 /// @see gtc_half_float (dependence) 7 /// @see gtc_constants (dependence) 8 /// @see gtc_quaternion (dependence) 9 /// 10 /// @defgroup gtx_dual_quaternion GLM_GTX_dual_quaternion 11 /// @ingroup gtx 12 /// 13 /// @brief Defines a templated dual-quaternion type and several dual-quaternion operations. 14 /// 15 /// <glm/gtx/dual_quaternion.hpp> need to be included to use these functionalities. 16 17 #pragma once 18 19 // Dependency: 20 #include "../glm.hpp" 21 #include "../gtc/constants.hpp" 22 #include "../gtc/quaternion.hpp" 23 24 #if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED) 25 # pragma message("GLM: GLM_GTX_dual_quaternion extension included") 26 #endif 27 28 namespace glm 29 { 30 /// @addtogroup gtx_dual_quaternion 31 /// @{ 32 33 template <typename T, precision P = defaultp> 34 struct tdualquat 35 { 36 // -- Implementation detail -- 37 38 typedef T value_type; 39 typedef glm::tquat<T, P> part_type; 40 41 // -- Data -- 42 43 glm::tquat<T, P> real, dual; 44 45 // -- Component accesses -- 46 47 typedef length_t length_type; 48 /// Return the count of components of a dual quaternion lengthglm::tdualquat49 GLM_FUNC_DECL static length_type length(){return 2;} 50 51 GLM_FUNC_DECL part_type & operator[](length_type i); 52 GLM_FUNC_DECL part_type const & operator[](length_type i) const; 53 54 // -- Implicit basic constructors -- 55 56 GLM_FUNC_DECL GLM_CONSTEXPR tdualquat() GLM_DEFAULT_CTOR; 57 GLM_FUNC_DECL GLM_CONSTEXPR tdualquat(tdualquat<T, P> const & d) GLM_DEFAULT; 58 template <precision Q> 59 GLM_FUNC_DECL GLM_CONSTEXPR tdualquat(tdualquat<T, Q> const & d); 60 61 // -- Explicit basic constructors -- 62 63 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR explicit tdualquat(ctor); 64 GLM_FUNC_DECL GLM_CONSTEXPR tdualquat(tquat<T, P> const & real); 65 GLM_FUNC_DECL GLM_CONSTEXPR tdualquat(tquat<T, P> const & orientation, tvec3<T, P> const & translation); 66 GLM_FUNC_DECL GLM_CONSTEXPR tdualquat(tquat<T, P> const & real, tquat<T, P> const & dual); 67 68 // -- Conversion constructors -- 69 70 template <typename U, precision Q> 71 GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tdualquat(tdualquat<U, Q> const & q); 72 73 GLM_FUNC_DECL GLM_EXPLICIT tdualquat(tmat2x4<T, P> const & holder_mat); 74 GLM_FUNC_DECL GLM_EXPLICIT tdualquat(tmat3x4<T, P> const & aug_mat); 75 76 // -- Unary arithmetic operators -- 77 78 GLM_FUNC_DECL tdualquat<T, P> & operator=(tdualquat<T, P> const & m) GLM_DEFAULT; 79 80 template <typename U> 81 GLM_FUNC_DECL tdualquat<T, P> & operator=(tdualquat<U, P> const & m); 82 template <typename U> 83 GLM_FUNC_DECL tdualquat<T, P> & operator*=(U s); 84 template <typename U> 85 GLM_FUNC_DECL tdualquat<T, P> & operator/=(U s); 86 }; 87 88 // -- Unary bit operators -- 89 90 template <typename T, precision P> 91 GLM_FUNC_DECL tdualquat<T, P> operator+(tdualquat<T, P> const & q); 92 93 template <typename T, precision P> 94 GLM_FUNC_DECL tdualquat<T, P> operator-(tdualquat<T, P> const & q); 95 96 // -- Binary operators -- 97 98 template <typename T, precision P> 99 GLM_FUNC_DECL tdualquat<T, P> operator+(tdualquat<T, P> const & q, tdualquat<T, P> const & p); 100 101 template <typename T, precision P> 102 GLM_FUNC_DECL tdualquat<T, P> operator*(tdualquat<T, P> const & q, tdualquat<T, P> const & p); 103 104 template <typename T, precision P> 105 GLM_FUNC_DECL tvec3<T, P> operator*(tdualquat<T, P> const & q, tvec3<T, P> const & v); 106 107 template <typename T, precision P> 108 GLM_FUNC_DECL tvec3<T, P> operator*(tvec3<T, P> const & v, tdualquat<T, P> const & q); 109 110 template <typename T, precision P> 111 GLM_FUNC_DECL tvec4<T, P> operator*(tdualquat<T, P> const & q, tvec4<T, P> const & v); 112 113 template <typename T, precision P> 114 GLM_FUNC_DECL tvec4<T, P> operator*(tvec4<T, P> const & v, tdualquat<T, P> const & q); 115 116 template <typename T, precision P> 117 GLM_FUNC_DECL tdualquat<T, P> operator*(tdualquat<T, P> const & q, T const & s); 118 119 template <typename T, precision P> 120 GLM_FUNC_DECL tdualquat<T, P> operator*(T const & s, tdualquat<T, P> const & q); 121 122 template <typename T, precision P> 123 GLM_FUNC_DECL tdualquat<T, P> operator/(tdualquat<T, P> const & q, T const & s); 124 125 // -- Boolean operators -- 126 127 template <typename T, precision P> 128 GLM_FUNC_DECL bool operator==(tdualquat<T, P> const & q1, tdualquat<T, P> const & q2); 129 130 template <typename T, precision P> 131 GLM_FUNC_DECL bool operator!=(tdualquat<T, P> const & q1, tdualquat<T, P> const & q2); 132 133 /// Returns the normalized quaternion. 134 /// 135 /// @see gtx_dual_quaternion 136 template <typename T, precision P> 137 GLM_FUNC_DECL tdualquat<T, P> normalize(tdualquat<T, P> const & q); 138 139 /// Returns the linear interpolation of two dual quaternion. 140 /// 141 /// @see gtc_dual_quaternion 142 template <typename T, precision P> 143 GLM_FUNC_DECL tdualquat<T, P> lerp(tdualquat<T, P> const & x, tdualquat<T, P> const & y, T const & a); 144 145 /// Returns the q inverse. 146 /// 147 /// @see gtx_dual_quaternion 148 template <typename T, precision P> 149 GLM_FUNC_DECL tdualquat<T, P> inverse(tdualquat<T, P> const & q); 150 151 /// Converts a quaternion to a 2 * 4 matrix. 152 /// 153 /// @see gtx_dual_quaternion 154 template <typename T, precision P> 155 GLM_FUNC_DECL tmat2x4<T, P> mat2x4_cast(tdualquat<T, P> const & x); 156 157 /// Converts a quaternion to a 3 * 4 matrix. 158 /// 159 /// @see gtx_dual_quaternion 160 template <typename T, precision P> 161 GLM_FUNC_DECL tmat3x4<T, P> mat3x4_cast(tdualquat<T, P> const & x); 162 163 /// Converts a 2 * 4 matrix (matrix which holds real and dual parts) to a quaternion. 164 /// 165 /// @see gtx_dual_quaternion 166 template <typename T, precision P> 167 GLM_FUNC_DECL tdualquat<T, P> dualquat_cast(tmat2x4<T, P> const & x); 168 169 /// Converts a 3 * 4 matrix (augmented matrix rotation + translation) to a quaternion. 170 /// 171 /// @see gtx_dual_quaternion 172 template <typename T, precision P> 173 GLM_FUNC_DECL tdualquat<T, P> dualquat_cast(tmat3x4<T, P> const & x); 174 175 176 /// Dual-quaternion of low single-precision floating-point numbers. 177 /// 178 /// @see gtx_dual_quaternion 179 typedef tdualquat<float, lowp> lowp_dualquat; 180 181 /// Dual-quaternion of medium single-precision floating-point numbers. 182 /// 183 /// @see gtx_dual_quaternion 184 typedef tdualquat<float, mediump> mediump_dualquat; 185 186 /// Dual-quaternion of high single-precision floating-point numbers. 187 /// 188 /// @see gtx_dual_quaternion 189 typedef tdualquat<float, highp> highp_dualquat; 190 191 192 /// Dual-quaternion of low single-precision floating-point numbers. 193 /// 194 /// @see gtx_dual_quaternion 195 typedef tdualquat<float, lowp> lowp_fdualquat; 196 197 /// Dual-quaternion of medium single-precision floating-point numbers. 198 /// 199 /// @see gtx_dual_quaternion 200 typedef tdualquat<float, mediump> mediump_fdualquat; 201 202 /// Dual-quaternion of high single-precision floating-point numbers. 203 /// 204 /// @see gtx_dual_quaternion 205 typedef tdualquat<float, highp> highp_fdualquat; 206 207 208 /// Dual-quaternion of low double-precision floating-point numbers. 209 /// 210 /// @see gtx_dual_quaternion 211 typedef tdualquat<double, lowp> lowp_ddualquat; 212 213 /// Dual-quaternion of medium double-precision floating-point numbers. 214 /// 215 /// @see gtx_dual_quaternion 216 typedef tdualquat<double, mediump> mediump_ddualquat; 217 218 /// Dual-quaternion of high double-precision floating-point numbers. 219 /// 220 /// @see gtx_dual_quaternion 221 typedef tdualquat<double, highp> highp_ddualquat; 222 223 224 #if(!defined(GLM_PRECISION_HIGHP_FLOAT) && !defined(GLM_PRECISION_MEDIUMP_FLOAT) && !defined(GLM_PRECISION_LOWP_FLOAT)) 225 /// Dual-quaternion of floating-point numbers. 226 /// 227 /// @see gtx_dual_quaternion 228 typedef highp_fdualquat dualquat; 229 230 /// Dual-quaternion of single-precision floating-point numbers. 231 /// 232 /// @see gtx_dual_quaternion 233 typedef highp_fdualquat fdualquat; 234 #elif(defined(GLM_PRECISION_HIGHP_FLOAT) && !defined(GLM_PRECISION_MEDIUMP_FLOAT) && !defined(GLM_PRECISION_LOWP_FLOAT)) 235 typedef highp_fdualquat dualquat; 236 typedef highp_fdualquat fdualquat; 237 #elif(!defined(GLM_PRECISION_HIGHP_FLOAT) && defined(GLM_PRECISION_MEDIUMP_FLOAT) && !defined(GLM_PRECISION_LOWP_FLOAT)) 238 typedef mediump_fdualquat dualquat; 239 typedef mediump_fdualquat fdualquat; 240 #elif(!defined(GLM_PRECISION_HIGHP_FLOAT) && !defined(GLM_PRECISION_MEDIUMP_FLOAT) && defined(GLM_PRECISION_LOWP_FLOAT)) 241 typedef lowp_fdualquat dualquat; 242 typedef lowp_fdualquat fdualquat; 243 #else 244 # error "GLM error: multiple default precision requested for single-precision floating-point types" 245 #endif 246 247 248 #if(!defined(GLM_PRECISION_HIGHP_DOUBLE) && !defined(GLM_PRECISION_MEDIUMP_DOUBLE) && !defined(GLM_PRECISION_LOWP_DOUBLE)) 249 /// Dual-quaternion of default double-precision floating-point numbers. 250 /// 251 /// @see gtx_dual_quaternion 252 typedef highp_ddualquat ddualquat; 253 #elif(defined(GLM_PRECISION_HIGHP_DOUBLE) && !defined(GLM_PRECISION_MEDIUMP_DOUBLE) && !defined(GLM_PRECISION_LOWP_DOUBLE)) 254 typedef highp_ddualquat ddualquat; 255 #elif(!defined(GLM_PRECISION_HIGHP_DOUBLE) && defined(GLM_PRECISION_MEDIUMP_DOUBLE) && !defined(GLM_PRECISION_LOWP_DOUBLE)) 256 typedef mediump_ddualquat ddualquat; 257 #elif(!defined(GLM_PRECISION_HIGHP_DOUBLE) && !defined(GLM_PRECISION_MEDIUMP_DOUBLE) && defined(GLM_PRECISION_LOWP_DOUBLE)) 258 typedef lowp_ddualquat ddualquat; 259 #else 260 # error "GLM error: Multiple default precision requested for double-precision floating-point types" 261 #endif 262 263 /// @} 264 } //namespace glm 265 266 #include "dual_quaternion.inl" 267