master
ブランチ master
VulkanExample / dep / include / glm / gtx / dual_quaternion.hpp
10.9 KB、296行 生 Blame 履歴
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
16#pragma once
17
18// Dependency:
19#include "../glm.hpp"
20#include "../gtc/constants.hpp"
21#include "../gtc/quaternion.hpp"
22
23#ifndef GLM_ENABLE_EXPERIMENTAL
24# 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."
25#elif GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
26# pragma message("GLM: GLM_GTX_dual_quaternion extension included")
27#endif
28
29namespace glm
30{
31 /// @addtogroup gtx_dual_quaternion
32 /// @{
33
34 template<typename T, qualifier Q = defaultp>
35 struct tdualquat
36 {
37 // -- Implementation detail --
38
39 typedef T value_type;
40 typedef qua<T, Q> part_type;
41
42 // -- Data --
43
44 qua<T, Q> real, dual;
45
46 // -- Component accesses --
47
48 typedef length_t length_type;
49 /// Return the count of components of a dual quaternion
50 GLM_FUNC_DECL static constexpr length_type length(){return 2;}
51
52 GLM_FUNC_DECL GLM_CONSTEXPR part_type & operator[](length_type i) noexcept;
53 GLM_FUNC_DECL GLM_CONSTEXPR part_type const& operator[](length_type i) const noexcept;
54
55 // -- Implicit basic constructors --
56
57 GLM_DEFAULTED_DEFAULT_CTOR_DECL GLM_CONSTEXPR tdualquat() GLM_DEFAULT_CTOR;
58 GLM_CTOR_DECL tdualquat(tdualquat<T, Q> const& d) = default;
59 template<qualifier P>
60 GLM_CTOR_DECL tdualquat(tdualquat<T, P> const& d);
61
62 // -- Explicit basic constructors --
63
64 GLM_CTOR_DECL tdualquat(qua<T, Q> const& real);
65 GLM_CTOR_DECL tdualquat(qua<T, Q> const& orientation, vec<3, T, Q> const& translation);
66 GLM_CTOR_DECL tdualquat(qua<T, Q> const& real, qua<T, Q> const& dual);
67
68 // -- Conversion constructors --
69
70 template<typename U, qualifier P>
71 GLM_CTOR_DECL GLM_EXPLICIT tdualquat(tdualquat<U, P> const& q);
72
73 GLM_CTOR_DECL GLM_EXPLICIT tdualquat(mat<2, 4, T, Q> const& holder_mat);
74 GLM_CTOR_DECL GLM_EXPLICIT tdualquat(mat<3, 4, T, Q> const& aug_mat);
75
76 // -- Unary arithmetic operators --
77
78 GLM_FUNC_DISCARD_DECL tdualquat<T, Q> & operator=(tdualquat<T, Q> const& m) = default;
79
80 template<typename U>
81 GLM_FUNC_DISCARD_DECL tdualquat<T, Q> & operator=(tdualquat<U, Q> const& m);
82 template<typename U>
83 GLM_FUNC_DISCARD_DECL tdualquat<T, Q> & operator*=(U s);
84 template<typename U>
85 GLM_FUNC_DISCARD_DECL tdualquat<T, Q> & operator/=(U s);
86 };
87
88 // -- Unary bit operators --
89
90 template<typename T, qualifier Q>
91 GLM_FUNC_DECL tdualquat<T, Q> operator+(tdualquat<T, Q> const& q);
92
93 template<typename T, qualifier Q>
94 GLM_FUNC_DECL tdualquat<T, Q> operator-(tdualquat<T, Q> const& q);
95
96 // -- Binary operators --
97
98 template<typename T, qualifier Q>
99 GLM_FUNC_DECL tdualquat<T, Q> operator+(tdualquat<T, Q> const& q, tdualquat<T, Q> const& p);
100
101 template<typename T, qualifier Q>
102 GLM_FUNC_DECL tdualquat<T, Q> operator*(tdualquat<T, Q> const& q, tdualquat<T, Q> const& p);
103
104 template<typename T, qualifier Q>
105 GLM_FUNC_DECL vec<3, T, Q> operator*(tdualquat<T, Q> const& q, vec<3, T, Q> const& v);
106
107 template<typename T, qualifier Q>
108 GLM_FUNC_DECL vec<3, T, Q> operator*(vec<3, T, Q> const& v, tdualquat<T, Q> const& q);
109
110 template<typename T, qualifier Q>
111 GLM_FUNC_DECL vec<4, T, Q> operator*(tdualquat<T, Q> const& q, vec<4, T, Q> const& v);
112
113 template<typename T, qualifier Q>
114 GLM_FUNC_DECL vec<4, T, Q> operator*(vec<4, T, Q> const& v, tdualquat<T, Q> const& q);
115
116 template<typename T, qualifier Q>
117 GLM_FUNC_DECL tdualquat<T, Q> operator*(tdualquat<T, Q> const& q, T const& s);
118
119 template<typename T, qualifier Q>
120 GLM_FUNC_DECL tdualquat<T, Q> operator*(T const& s, tdualquat<T, Q> const& q);
121
122 template<typename T, qualifier Q>
123 GLM_FUNC_DECL tdualquat<T, Q> operator/(tdualquat<T, Q> const& q, T const& s);
124
125 // -- Boolean operators --
126
127 template<typename T, qualifier Q>
128 GLM_FUNC_DECL bool operator==(tdualquat<T, Q> const& q1, tdualquat<T, Q> const& q2);
129
130 template<typename T, qualifier Q>
131 GLM_FUNC_DECL bool operator!=(tdualquat<T, Q> const& q1, tdualquat<T, Q> const& q2);
132
133 /// Creates an identity dual quaternion.
134 ///
135 /// @see gtx_dual_quaternion
136 template <typename T, qualifier Q>
137 GLM_FUNC_DECL tdualquat<T, Q> dual_quat_identity();
138
139 /// Returns the normalized quaternion.
140 ///
141 /// @see gtx_dual_quaternion
142 template<typename T, qualifier Q>
143 GLM_FUNC_DECL tdualquat<T, Q> normalize(tdualquat<T, Q> const& q);
144
145 /// Returns the linear interpolation of two dual quaternion.
146 ///
147 /// @see gtc_dual_quaternion
148 template<typename T, qualifier Q>
149 GLM_FUNC_DECL tdualquat<T, Q> lerp(tdualquat<T, Q> const& x, tdualquat<T, Q> const& y, T const& a);
150
151 /// Returns the q inverse.
152 ///
153 /// @see gtx_dual_quaternion
154 template<typename T, qualifier Q>
155 GLM_FUNC_DECL tdualquat<T, Q> inverse(tdualquat<T, Q> const& q);
156
157 /// Converts a quaternion to a 2 * 4 matrix.
158 ///
159 /// @see gtx_dual_quaternion
160 template<typename T, qualifier Q>
161 GLM_FUNC_DECL mat<2, 4, T, Q> mat2x4_cast(tdualquat<T, Q> const& x);
162
163 /// Converts a quaternion to a 3 * 4 matrix.
164 ///
165 /// @see gtx_dual_quaternion
166 template<typename T, qualifier Q>
167 GLM_FUNC_DECL mat<3, 4, T, Q> mat3x4_cast(tdualquat<T, Q> const& x);
168
169 /// Converts a 2 * 4 matrix (matrix which holds real and dual parts) to a quaternion.
170 ///
171 /// @see gtx_dual_quaternion
172 template<typename T, qualifier Q>
173 GLM_FUNC_DECL tdualquat<T, Q> dualquat_cast(mat<2, 4, T, Q> const& x);
174
175 /// Converts a 3 * 4 matrix (augmented matrix rotation + translation) to a quaternion.
176 ///
177 /// @see gtx_dual_quaternion
178 template<typename T, qualifier Q>
179 GLM_FUNC_DECL tdualquat<T, Q> dualquat_cast(mat<3, 4, T, Q> const& x);
180
181
182 /// Dual-quaternion of low single-qualifier floating-point numbers.
183 ///
184 /// @see gtx_dual_quaternion
185 typedef tdualquat<float, lowp> lowp_dualquat;
186
187 /// Dual-quaternion of medium single-qualifier floating-point numbers.
188 ///
189 /// @see gtx_dual_quaternion
190 typedef tdualquat<float, mediump> mediump_dualquat;
191
192 /// Dual-quaternion of high single-qualifier floating-point numbers.
193 ///
194 /// @see gtx_dual_quaternion
195 typedef tdualquat<float, highp> highp_dualquat;
196
197
198 /// Dual-quaternion of low single-qualifier floating-point numbers.
199 ///
200 /// @see gtx_dual_quaternion
201 typedef tdualquat<float, lowp> lowp_fdualquat;
202
203 /// Dual-quaternion of medium single-qualifier floating-point numbers.
204 ///
205 /// @see gtx_dual_quaternion
206 typedef tdualquat<float, mediump> mediump_fdualquat;
207
208 /// Dual-quaternion of high single-qualifier floating-point numbers.
209 ///
210 /// @see gtx_dual_quaternion
211 typedef tdualquat<float, highp> highp_fdualquat;
212
213
214 /// Dual-quaternion of low double-qualifier floating-point numbers.
215 ///
216 /// @see gtx_dual_quaternion
217 typedef tdualquat<double, lowp> lowp_ddualquat;
218
219 /// Dual-quaternion of medium double-qualifier floating-point numbers.
220 ///
221 /// @see gtx_dual_quaternion
222 typedef tdualquat<double, mediump> mediump_ddualquat;
223
224 /// Dual-quaternion of high double-qualifier floating-point numbers.
225 ///
226 /// @see gtx_dual_quaternion
227 typedef tdualquat<double, highp> highp_ddualquat;
228
229
230#if(!defined(GLM_PRECISION_HIGHP_FLOAT) && !defined(GLM_PRECISION_MEDIUMP_FLOAT) && !defined(GLM_PRECISION_LOWP_FLOAT))
231 /// Dual-quaternion of floating-point numbers.
232 ///
233 /// @see gtx_dual_quaternion
234 typedef highp_fdualquat dualquat;
235
236 /// Dual-quaternion of single-qualifier floating-point numbers.
237 ///
238 /// @see gtx_dual_quaternion
239 typedef highp_fdualquat fdualquat;
240#elif(defined(GLM_PRECISION_HIGHP_FLOAT) && !defined(GLM_PRECISION_MEDIUMP_FLOAT) && !defined(GLM_PRECISION_LOWP_FLOAT))
241 typedef highp_fdualquat dualquat;
242 typedef highp_fdualquat fdualquat;
243#elif(!defined(GLM_PRECISION_HIGHP_FLOAT) && defined(GLM_PRECISION_MEDIUMP_FLOAT) && !defined(GLM_PRECISION_LOWP_FLOAT))
244 typedef mediump_fdualquat dualquat;
245 typedef mediump_fdualquat fdualquat;
246#elif(!defined(GLM_PRECISION_HIGHP_FLOAT) && !defined(GLM_PRECISION_MEDIUMP_FLOAT) && defined(GLM_PRECISION_LOWP_FLOAT))
247 typedef lowp_fdualquat dualquat;
248 typedef lowp_fdualquat fdualquat;
249#else
250# error "GLM error: multiple default precision requested for single-precision floating-point types"
251#endif
252
253
254#if(!defined(GLM_PRECISION_HIGHP_DOUBLE) && !defined(GLM_PRECISION_MEDIUMP_DOUBLE) && !defined(GLM_PRECISION_LOWP_DOUBLE))
255 /// Dual-quaternion of default double-qualifier floating-point numbers.
256 ///
257 /// @see gtx_dual_quaternion
258 typedef highp_ddualquat ddualquat;
259#elif(defined(GLM_PRECISION_HIGHP_DOUBLE) && !defined(GLM_PRECISION_MEDIUMP_DOUBLE) && !defined(GLM_PRECISION_LOWP_DOUBLE))
260 typedef highp_ddualquat ddualquat;
261#elif(!defined(GLM_PRECISION_HIGHP_DOUBLE) && defined(GLM_PRECISION_MEDIUMP_DOUBLE) && !defined(GLM_PRECISION_LOWP_DOUBLE))
262 typedef mediump_ddualquat ddualquat;
263#elif(!defined(GLM_PRECISION_HIGHP_DOUBLE) && !defined(GLM_PRECISION_MEDIUMP_DOUBLE) && defined(GLM_PRECISION_LOWP_DOUBLE))
264 typedef lowp_ddualquat ddualquat;
265#else
266# error "GLM error: Multiple default precision requested for double-precision floating-point types"
267#endif
268
269 /// @}
270} //namespace glm
271
272
273#if GLM_CONFIG_CTOR_INIT == GLM_DISABLE
274static_assert(std::is_trivially_default_constructible<glm::dualquat>::value);
275static_assert(std::is_trivially_default_constructible<glm::lowp_dualquat>::value);
276static_assert(std::is_trivially_default_constructible<glm::mediump_dualquat>::value);
277static_assert(std::is_trivially_default_constructible<glm::highp_dualquat>::value);
278#endif
279static_assert(std::is_trivially_copy_assignable<glm::dualquat>::value);
280static_assert(std::is_trivially_copy_assignable<glm::lowp_dualquat>::value);
281static_assert(std::is_trivially_copy_assignable<glm::mediump_dualquat>::value);
282static_assert(std::is_trivially_copy_assignable<glm::highp_dualquat>::value);
283static_assert(std::is_trivially_copyable<glm::dualquat>::value);
284static_assert(std::is_trivially_copyable<glm::lowp_dualquat>::value);
285static_assert(std::is_trivially_copyable<glm::mediump_dualquat>::value);
286static_assert(std::is_trivially_copyable<glm::highp_dualquat>::value);
287static_assert(std::is_copy_constructible<glm::dualquat>::value);
288static_assert(std::is_copy_constructible<glm::lowp_dualquat>::value);
289static_assert(std::is_copy_constructible<glm::mediump_dualquat>::value);
290static_assert(std::is_copy_constructible<glm::highp_dualquat>::value);
291static_assert(glm::dualquat::length() == 2);
292static_assert(glm::lowp_dualquat::length() == 2);
293static_assert(glm::mediump_dualquat::length() == 2);
294static_assert(glm::highp_dualquat::length() == 2);
295
296#include "dual_quaternion.inl"