dual_quaternion.hpp 9.2 KB

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