dual_quaternion.hpp 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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_constants (dependence)
  7. /// @see gtc_quaternion (dependence)
  8. ///
  9. /// @defgroup gtx_dual_quaternion GLM_GTX_dual_quaternion
  10. /// @ingroup gtx
  11. ///
  12. /// Include <glm/gtx/dual_quaternion.hpp> to use the features of this extension.
  13. ///
  14. /// Defines a templated dual-quaternion type and several dual-quaternion operations.
  15. #pragma once
  16. // Dependency:
  17. #include "../glm.hpp"
  18. #include "../gtc/constants.hpp"
  19. #include "../gtc/quaternion.hpp"
  20. #ifndef GLM_ENABLE_EXPERIMENTAL
  21. # error "GLM: GLM_GTX_dual_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_dual_quaternion extension included")
  24. #endif
  25. namespace glm
  26. {
  27. /// @addtogroup gtx_dual_quaternion
  28. /// @{
  29. template<typename T, qualifier Q = defaultp>
  30. struct tdualquat
  31. {
  32. // -- Implementation detail --
  33. typedef T value_type;
  34. typedef qua<T, Q> part_type;
  35. // -- Data --
  36. qua<T, Q> real, dual;
  37. // -- Component accesses --
  38. typedef length_t length_type;
  39. /// Return the count of components of a dual quaternion
  40. GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 2;}
  41. GLM_FUNC_DECL part_type & operator[](length_type i);
  42. GLM_FUNC_DECL part_type const& operator[](length_type i) const;
  43. // -- Implicit basic constructors --
  44. GLM_DEFAULTED_FUNC_DECL GLM_CONSTEXPR tdualquat() GLM_DEFAULT;
  45. GLM_DEFAULTED_FUNC_DECL GLM_CONSTEXPR tdualquat(tdualquat<T, Q> const& d) GLM_DEFAULT;
  46. template<qualifier P>
  47. GLM_CTOR_DECL tdualquat(tdualquat<T, P> const& d);
  48. // -- Explicit basic constructors --
  49. GLM_CTOR_DECL tdualquat(qua<T, Q> const& real);
  50. GLM_CTOR_DECL tdualquat(qua<T, Q> const& orientation, vec<3, T, Q> const& translation);
  51. GLM_CTOR_DECL tdualquat(qua<T, Q> const& real, qua<T, Q> const& dual);
  52. // -- Conversion constructors --
  53. template<typename U, qualifier P>
  54. GLM_CTOR_DECL GLM_EXPLICIT tdualquat(tdualquat<U, P> const& q);
  55. GLM_CTOR_DECL GLM_EXPLICIT tdualquat(mat<2, 4, T, Q> const& holder_mat);
  56. GLM_CTOR_DECL GLM_EXPLICIT tdualquat(mat<3, 4, T, Q> const& aug_mat);
  57. // -- Unary arithmetic operators --
  58. GLM_DEFAULTED_FUNC_DECL tdualquat<T, Q> & operator=(tdualquat<T, Q> const& m) GLM_DEFAULT;
  59. template<typename U>
  60. GLM_FUNC_DISCARD_DECL tdualquat<T, Q> & operator=(tdualquat<U, Q> const& m);
  61. template<typename U>
  62. GLM_FUNC_DISCARD_DECL tdualquat<T, Q> & operator*=(U s);
  63. template<typename U>
  64. GLM_FUNC_DISCARD_DECL tdualquat<T, Q> & operator/=(U s);
  65. };
  66. // -- Unary bit operators --
  67. template<typename T, qualifier Q>
  68. GLM_FUNC_DECL tdualquat<T, Q> operator+(tdualquat<T, Q> const& q);
  69. template<typename T, qualifier Q>
  70. GLM_FUNC_DECL tdualquat<T, Q> operator-(tdualquat<T, Q> const& q);
  71. // -- Binary operators --
  72. template<typename T, qualifier Q>
  73. GLM_FUNC_DECL tdualquat<T, Q> operator+(tdualquat<T, Q> const& q, tdualquat<T, Q> const& p);
  74. template<typename T, qualifier Q>
  75. GLM_FUNC_DECL tdualquat<T, Q> operator*(tdualquat<T, Q> const& q, tdualquat<T, Q> const& p);
  76. template<typename T, qualifier Q>
  77. GLM_FUNC_DECL vec<3, T, Q> operator*(tdualquat<T, Q> const& q, vec<3, T, Q> const& v);
  78. template<typename T, qualifier Q>
  79. GLM_FUNC_DECL vec<3, T, Q> operator*(vec<3, T, Q> const& v, tdualquat<T, Q> const& q);
  80. template<typename T, qualifier Q>
  81. GLM_FUNC_DECL vec<4, T, Q> operator*(tdualquat<T, Q> const& q, vec<4, T, Q> const& v);
  82. template<typename T, qualifier Q>
  83. GLM_FUNC_DECL vec<4, T, Q> operator*(vec<4, T, Q> const& v, tdualquat<T, Q> const& q);
  84. template<typename T, qualifier Q>
  85. GLM_FUNC_DECL tdualquat<T, Q> operator*(tdualquat<T, Q> const& q, T const& s);
  86. template<typename T, qualifier Q>
  87. GLM_FUNC_DECL tdualquat<T, Q> operator*(T const& s, tdualquat<T, Q> const& q);
  88. template<typename T, qualifier Q>
  89. GLM_FUNC_DECL tdualquat<T, Q> operator/(tdualquat<T, Q> const& q, T const& s);
  90. // -- Boolean operators --
  91. template<typename T, qualifier Q>
  92. GLM_FUNC_DECL bool operator==(tdualquat<T, Q> const& q1, tdualquat<T, Q> const& q2);
  93. template<typename T, qualifier Q>
  94. GLM_FUNC_DECL bool operator!=(tdualquat<T, Q> const& q1, tdualquat<T, Q> const& q2);
  95. /// Creates an identity dual quaternion.
  96. ///
  97. /// @see gtx_dual_quaternion
  98. template <typename T, qualifier Q>
  99. GLM_FUNC_DECL tdualquat<T, Q> dual_quat_identity();
  100. /// Returns the normalized quaternion.
  101. ///
  102. /// @see gtx_dual_quaternion
  103. template<typename T, qualifier Q>
  104. GLM_FUNC_DECL tdualquat<T, Q> normalize(tdualquat<T, Q> const& q);
  105. /// Returns the linear interpolation of two dual quaternion.
  106. ///
  107. /// @see gtc_dual_quaternion
  108. template<typename T, qualifier Q>
  109. GLM_FUNC_DECL tdualquat<T, Q> lerp(tdualquat<T, Q> const& x, tdualquat<T, Q> const& y, T const& a);
  110. /// Returns the q inverse.
  111. ///
  112. /// @see gtx_dual_quaternion
  113. template<typename T, qualifier Q>
  114. GLM_FUNC_DECL tdualquat<T, Q> inverse(tdualquat<T, Q> const& q);
  115. /// Converts a quaternion to a 2 * 4 matrix.
  116. ///
  117. /// @see gtx_dual_quaternion
  118. template<typename T, qualifier Q>
  119. GLM_FUNC_DECL mat<2, 4, T, Q> mat2x4_cast(tdualquat<T, Q> const& x);
  120. /// Converts a quaternion to a 3 * 4 matrix.
  121. ///
  122. /// @see gtx_dual_quaternion
  123. template<typename T, qualifier Q>
  124. GLM_FUNC_DECL mat<3, 4, T, Q> mat3x4_cast(tdualquat<T, Q> const& x);
  125. /// Converts a 2 * 4 matrix (matrix which holds real and dual parts) to a quaternion.
  126. ///
  127. /// @see gtx_dual_quaternion
  128. template<typename T, qualifier Q>
  129. GLM_FUNC_DECL tdualquat<T, Q> dualquat_cast(mat<2, 4, T, Q> const& x);
  130. /// Converts a 3 * 4 matrix (augmented matrix rotation + translation) to a quaternion.
  131. ///
  132. /// @see gtx_dual_quaternion
  133. template<typename T, qualifier Q>
  134. GLM_FUNC_DECL tdualquat<T, Q> dualquat_cast(mat<3, 4, T, Q> const& x);
  135. /// Dual-quaternion of low single-qualifier floating-point numbers.
  136. ///
  137. /// @see gtx_dual_quaternion
  138. typedef tdualquat<float, lowp> lowp_dualquat;
  139. /// Dual-quaternion of medium single-qualifier floating-point numbers.
  140. ///
  141. /// @see gtx_dual_quaternion
  142. typedef tdualquat<float, mediump> mediump_dualquat;
  143. /// Dual-quaternion of high single-qualifier floating-point numbers.
  144. ///
  145. /// @see gtx_dual_quaternion
  146. typedef tdualquat<float, highp> highp_dualquat;
  147. /// Dual-quaternion of low single-qualifier floating-point numbers.
  148. ///
  149. /// @see gtx_dual_quaternion
  150. typedef tdualquat<float, lowp> lowp_fdualquat;
  151. /// Dual-quaternion of medium single-qualifier floating-point numbers.
  152. ///
  153. /// @see gtx_dual_quaternion
  154. typedef tdualquat<float, mediump> mediump_fdualquat;
  155. /// Dual-quaternion of high single-qualifier floating-point numbers.
  156. ///
  157. /// @see gtx_dual_quaternion
  158. typedef tdualquat<float, highp> highp_fdualquat;
  159. /// Dual-quaternion of low double-qualifier floating-point numbers.
  160. ///
  161. /// @see gtx_dual_quaternion
  162. typedef tdualquat<double, lowp> lowp_ddualquat;
  163. /// Dual-quaternion of medium double-qualifier floating-point numbers.
  164. ///
  165. /// @see gtx_dual_quaternion
  166. typedef tdualquat<double, mediump> mediump_ddualquat;
  167. /// Dual-quaternion of high double-qualifier floating-point numbers.
  168. ///
  169. /// @see gtx_dual_quaternion
  170. typedef tdualquat<double, highp> highp_ddualquat;
  171. #if(!defined(GLM_PRECISION_HIGHP_FLOAT) && !defined(GLM_PRECISION_MEDIUMP_FLOAT) && !defined(GLM_PRECISION_LOWP_FLOAT))
  172. /// Dual-quaternion of floating-point numbers.
  173. ///
  174. /// @see gtx_dual_quaternion
  175. typedef highp_fdualquat dualquat;
  176. /// Dual-quaternion of single-qualifier floating-point numbers.
  177. ///
  178. /// @see gtx_dual_quaternion
  179. typedef highp_fdualquat fdualquat;
  180. #elif(defined(GLM_PRECISION_HIGHP_FLOAT) && !defined(GLM_PRECISION_MEDIUMP_FLOAT) && !defined(GLM_PRECISION_LOWP_FLOAT))
  181. typedef highp_fdualquat dualquat;
  182. typedef highp_fdualquat fdualquat;
  183. #elif(!defined(GLM_PRECISION_HIGHP_FLOAT) && defined(GLM_PRECISION_MEDIUMP_FLOAT) && !defined(GLM_PRECISION_LOWP_FLOAT))
  184. typedef mediump_fdualquat dualquat;
  185. typedef mediump_fdualquat fdualquat;
  186. #elif(!defined(GLM_PRECISION_HIGHP_FLOAT) && !defined(GLM_PRECISION_MEDIUMP_FLOAT) && defined(GLM_PRECISION_LOWP_FLOAT))
  187. typedef lowp_fdualquat dualquat;
  188. typedef lowp_fdualquat fdualquat;
  189. #else
  190. # error "GLM error: multiple default precision requested for single-precision floating-point types"
  191. #endif
  192. #if(!defined(GLM_PRECISION_HIGHP_DOUBLE) && !defined(GLM_PRECISION_MEDIUMP_DOUBLE) && !defined(GLM_PRECISION_LOWP_DOUBLE))
  193. /// Dual-quaternion of default double-qualifier floating-point numbers.
  194. ///
  195. /// @see gtx_dual_quaternion
  196. typedef highp_ddualquat ddualquat;
  197. #elif(defined(GLM_PRECISION_HIGHP_DOUBLE) && !defined(GLM_PRECISION_MEDIUMP_DOUBLE) && !defined(GLM_PRECISION_LOWP_DOUBLE))
  198. typedef highp_ddualquat ddualquat;
  199. #elif(!defined(GLM_PRECISION_HIGHP_DOUBLE) && defined(GLM_PRECISION_MEDIUMP_DOUBLE) && !defined(GLM_PRECISION_LOWP_DOUBLE))
  200. typedef mediump_ddualquat ddualquat;
  201. #elif(!defined(GLM_PRECISION_HIGHP_DOUBLE) && !defined(GLM_PRECISION_MEDIUMP_DOUBLE) && defined(GLM_PRECISION_LOWP_DOUBLE))
  202. typedef lowp_ddualquat ddualquat;
  203. #else
  204. # error "GLM error: Multiple default precision requested for double-precision floating-point types"
  205. #endif
  206. /// @}
  207. } //namespace glm
  208. #include "dual_quaternion.inl"