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.

275 lines
9.2KB

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