0.9.9 API documenation: quaternion.hpp Source File

| 0.9.9 API documenation

- Main Page
- Modules
- Files

- File List

gtc/quaternion.hpp
Go to the documentation of this file.
1
14 #pragma once
15
16 // Dependency:
17 #include "../mat3x3.hpp"
18 #include "../mat4x4.hpp"
19 #include "../vec3.hpp"
20 #include "../vec4.hpp"
21 #include "../gtc/constants.hpp"
22
23 #if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED)
24 # pragma message("GLM: GLM_GTC_quaternion extension included")
25 #endif
26
27 namespace glm
28 {
31
32 template<typename T, qualifier Q = defaultp>
33 struct tquat
34 {
35 // -- Implementation detail --
36
37 typedef tquat<T, Q> type;
38 typedef T value_type;
39
40 // -- Data --
41
42 # if GLM_HAS_ALIGNED_TYPE
43 # if GLM_COMPILER & GLM_COMPILER_GCC
44 # pragma GCC diagnostic push
45 # pragma GCC diagnostic ignored "-Wpedantic"
46 # endif
47 # if GLM_COMPILER & GLM_COMPILER_CLANG
48 # pragma clang diagnostic push
49 # pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
50 # pragma clang diagnostic ignored "-Wnested-anon-types"
51 # endif
52
53 union
54 {
55 struct { T x, y, z, w;};
56 typename detail::storage<T, sizeof(T) * 4, detail::is_aligned<Q>::value>::type data;
57 };
58
59 # if GLM_COMPILER & GLM_COMPILER_CLANG
60 # pragma clang diagnostic pop
61 # endif
62 # if GLM_COMPILER & GLM_COMPILER_GCC
63 # pragma GCC diagnostic pop
64 # endif
65 # else
66 T x, y, z, w;
67 # endif
68
69 // -- Component accesses --
70
71 typedef length_t length_type;
73 GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 4;}
74
75 GLM_FUNC_DECL T & operator[](length_type i);
76 GLM_FUNC_DECL T const& operator[](length_type i) const;
77
78 // -- Implicit basic constructors --
79
80 GLM_FUNC_DECL GLM_CONSTEXPR tquat() GLM_DEFAULT_CTOR;
81 GLM_FUNC_DECL GLM_CONSTEXPR tquat(tquat<T, Q> const& q) GLM_DEFAULT;
82 template<qualifier P>
83 GLM_FUNC_DECL GLM_CONSTEXPR tquat(tquat<T, P> const& q);
84
85 // -- Explicit basic constructors --
86
87 GLM_FUNC_DECL GLM_CONSTEXPR tquat(T s, vec<3, T, Q> const& v);
88 GLM_FUNC_DECL GLM_CONSTEXPR tquat(T w, T x, T y, T z);
89
90 // -- Conversion constructors --
91
92 template<typename U, qualifier P>
93 GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tquat(tquat<U, P> const& q);
94
96 # if GLM_HAS_EXPLICIT_CONVERSION_OPERATORS
97 GLM_FUNC_DECL explicit operator mat<3, 3, T, Q>();
98 GLM_FUNC_DECL explicit operator mat<4, 4, T, Q>();
99 # endif
100
107 GLM_FUNC_DECL tquat(vec<3, T, Q> const& u, vec<3, T, Q> const& v);
108
110 GLM_FUNC_DECL GLM_EXPLICIT tquat(vec<3, T, Q> const& eulerAngles);
111 GLM_FUNC_DECL GLM_EXPLICIT tquat(mat<3, 3, T, Q> const& q);
112 GLM_FUNC_DECL GLM_EXPLICIT tquat(mat<4, 4, T, Q> const& q);
113
114 // -- Unary arithmetic operators --
115
116 GLM_FUNC_DECL tquat<T, Q> & operator=(tquat<T, Q> const& q) GLM_DEFAULT;
117
118 template<typename U>
119 GLM_FUNC_DECL tquat<T, Q> & operator=(tquat<U, Q> const& q);
120 template<typename U>
121 GLM_FUNC_DECL tquat<T, Q> & operator+=(tquat<U, Q> const& q);
122 template<typename U>
123 GLM_FUNC_DECL tquat<T, Q> & operator-=(tquat<U, Q> const& q);
124 template<typename U>
125 GLM_FUNC_DECL tquat<T, Q> & operator*=(tquat<U, Q> const& q);
126 template<typename U>
127 GLM_FUNC_DECL tquat<T, Q> & operator*=(U s);
128 template<typename U>
129 GLM_FUNC_DECL tquat<T, Q> & operator/=(U s);
130 };
131
132 // -- Unary bit operators --
133
134 template<typename T, qualifier Q>
135 GLM_FUNC_DECL tquat<T, Q> operator+(tquat<T, Q> const& q);
136
137 template<typename T, qualifier Q>
138 GLM_FUNC_DECL tquat<T, Q> operator-(tquat<T, Q> const& q);
139
140 // -- Binary operators --
141
142 template<typename T, qualifier Q>
143 GLM_FUNC_DECL tquat<T, Q> operator+(tquat<T, Q> const& q, tquat<T, Q> const& p);
144
145 template<typename T, qualifier Q>
146 GLM_FUNC_DECL tquat<T, Q> operator-(tquat<T, Q> const& q, tquat<T, Q> const& p);
147
148 template<typename T, qualifier Q>
149 GLM_FUNC_DECL tquat<T, Q> operator*(tquat<T, Q> const& q, tquat<T, Q> const& p);
150
151 template<typename T, qualifier Q>
152 GLM_FUNC_DECL vec<3, T, Q> operator*(tquat<T, Q> const& q, vec<3, T, Q> const& v);
153
154 template<typename T, qualifier Q>
155 GLM_FUNC_DECL vec<3, T, Q> operator*(vec<3, T, Q> const& v, tquat<T, Q> const& q);
156
157 template<typename T, qualifier Q>
158 GLM_FUNC_DECL vec<4, T, Q> operator*(tquat<T, Q> const& q, vec<4, T, Q> const& v);
159
160 template<typename T, qualifier Q>
161 GLM_FUNC_DECL vec<4, T, Q> operator*(vec<4, T, Q> const& v, tquat<T, Q> const& q);
162
163 template<typename T, qualifier Q>
164 GLM_FUNC_DECL tquat<T, Q> operator*(tquat<T, Q> const& q, T const& s);
165
166 template<typename T, qualifier Q>
167 GLM_FUNC_DECL tquat<T, Q> operator*(T const& s, tquat<T, Q> const& q);
168
169 template<typename T, qualifier Q>
170 GLM_FUNC_DECL tquat<T, Q> operator/(tquat<T, Q> const& q, T const& s);
171
172 // -- Boolean operators --
173
174 template<typename T, qualifier Q>
175 GLM_FUNC_DECL bool operator==(tquat<T, Q> const& q1, tquat<T, Q> const& q2);
176
177 template<typename T, qualifier Q>
178 GLM_FUNC_DECL bool operator!=(tquat<T, Q> const& q1, tquat<T, Q> const& q2);
179
185 template<typename T, qualifier Q>
186 GLM_FUNC_DECL T length(tquat<T, Q> const& q);
187
193 template<typename T, qualifier Q>
194 GLM_FUNC_DECL tquat<T, Q> normalize(tquat<T, Q> const& q);
195
201 template<typename T, qualifier Q>
202 GLM_FUNC_DECL T dot(tquat<T, Q> const& x, tquat<T, Q> const& y);
203
215 template<typename T, qualifier Q>
216 GLM_FUNC_DECL tquat<T, Q> mix(tquat<T, Q> const& x, tquat<T, Q> const& y, T a);
217
227 template<typename T, qualifier Q>
228 GLM_FUNC_DECL tquat<T, Q> lerp(tquat<T, Q> const& x, tquat<T, Q> const& y, T a);
229
239 template<typename T, qualifier Q>
240 GLM_FUNC_DECL tquat<T, Q> slerp(tquat<T, Q> const& x, tquat<T, Q> const& y, T a);
241
247 template<typename T, qualifier Q>
248 GLM_FUNC_DECL tquat<T, Q> conjugate(tquat<T, Q> const& q);
249
255 template<typename T, qualifier Q>
256 GLM_FUNC_DECL tquat<T, Q> inverse(tquat<T, Q> const& q);
257
266 template<typename T, qualifier Q>
267 GLM_FUNC_DECL tquat<T, Q> rotate(tquat<T, Q> const& q, T const& angle, vec<3, T, Q> const& axis);
268
275 template<typename T, qualifier Q>
276 GLM_FUNC_DECL vec<3, T, Q> eulerAngles(tquat<T, Q> const& x);
277
283 template<typename T, qualifier Q>
284 GLM_FUNC_DECL T roll(tquat<T, Q> const& x);
285
291 template<typename T, qualifier Q>
292 GLM_FUNC_DECL T pitch(tquat<T, Q> const& x);
293
299 template<typename T, qualifier Q>
300 GLM_FUNC_DECL T yaw(tquat<T, Q> const& x);
301
307 template<typename T, qualifier Q>
308 GLM_FUNC_DECL mat<3, 3, T, Q> mat3_cast(tquat<T, Q> const& x);
309
315 template<typename T, qualifier Q>
316 GLM_FUNC_DECL mat<4, 4, T, Q> mat4_cast(tquat<T, Q> const& x);
317
323 template<typename T, qualifier Q>
324 GLM_FUNC_DECL tquat<T, Q> quat_cast(mat<3, 3, T, Q> const& x);
325
331 template<typename T, qualifier Q>
332 GLM_FUNC_DECL tquat<T, Q> quat_cast(mat<4, 4, T, Q> const& x);
333
339 template<typename T, qualifier Q>
340 GLM_FUNC_DECL T angle(tquat<T, Q> const& x);
341
347 template<typename T, qualifier Q>
348 GLM_FUNC_DECL vec<3, T, Q> axis(tquat<T, Q> const& x);
349
357 template<typename T, qualifier Q>
358 GLM_FUNC_DECL tquat<T, Q> angleAxis(T const& angle, vec<3, T, Q> const& axis);
359
365 template<typename T, qualifier Q>
366 GLM_FUNC_DECL vec<4, bool, Q> lessThan(tquat<T, Q> const& x, tquat<T, Q> const& y);
367
373 template<typename T, qualifier Q>
374 GLM_FUNC_DECL vec<4, bool, Q> lessThanEqual(tquat<T, Q> const& x, tquat<T, Q> const& y);
375
381 template<typename T, qualifier Q>
382 GLM_FUNC_DECL vec<4, bool, Q> greaterThan(tquat<T, Q> const& x, tquat<T, Q> const& y);
383
389 template<typename T, qualifier Q>
390 GLM_FUNC_DECL vec<4, bool, Q> greaterThanEqual(tquat<T, Q> const& x, tquat<T, Q> const& y);
391
397 template<typename T, qualifier Q>
398 GLM_FUNC_DECL vec<4, bool, Q> equal(tquat<T, Q> const& x, tquat<T, Q> const& y);
399
405 template<typename T, qualifier Q>
406 GLM_FUNC_DECL vec<4, bool, Q> notEqual(tquat<T, Q> const& x, tquat<T, Q> const& y);
407
419 template<typename T, qualifier Q>
420 GLM_FUNC_DECL vec<4, bool, Q> isnan(tquat<T, Q> const& x);
421
431 template<typename T, qualifier Q>
432 GLM_FUNC_DECL vec<4, bool, Q> isinf(tquat<T, Q> const& x);
433
435 } //namespace glm
436
437 #include "quaternion.inl"
glm::lessThan
GLM_FUNC_DECL vec< 4, bool, Q > lessThan(tquat< T, Q > const &x, tquat< T, Q > const &y)
Returns the component-wise comparison result of x < y.
glm::angle
GLM_FUNC_DECL T angle(tquat< T, Q > const &x)
Returns the quaternion rotation angle.
glm::mix
GLM_FUNC_DECL tquat< T, Q > mix(tquat< T, Q > const &x, tquat< T, Q > const &y, T a)
Spherical linear interpolation of two quaternions.
glm::isinf
GLM_FUNC_DECL vec< 4, bool, Q > isinf(tquat< T, Q > const &x)
Returns true if x holds a positive infinity or negative infinity representation in the underlying imp...
glm::axis
GLM_FUNC_DECL vec< 3, T, Q > axis(tquat< T, Q > const &x)
Returns the q rotation axis.
glm::conjugate
GLM_FUNC_DECL tquat< T, Q > conjugate(tquat< T, Q > const &q)
Returns the q conjugate.
glm::pitch
GLM_FUNC_DECL T pitch(tquat< T, Q > const &x)
Returns pitch value of euler angles expressed in radians.
glm::rotate
GLM_FUNC_DECL tquat< T, Q > rotate(tquat< T, Q > const &q, T const &angle, vec< 3, T, Q > const &axis)
Rotates a quaternion from a vector of 3 components axis and an angle.
glm::yaw
GLM_FUNC_DECL T yaw(tquat< T, Q > const &x)
Returns yaw value of euler angles expressed in radians.
glm::equal
GLM_FUNC_DECL vec< 4, bool, Q > equal(tquat< T, Q > const &x, tquat< T, Q > const &y)
Returns the component-wise comparison of result x == y.
glm::quat_cast
GLM_FUNC_DECL tquat< T, Q > quat_cast(mat< 4, 4, T, Q > const &x)
Converts a pure rotation 4 * 4 matrix to a quaternion.
glm
Definition: common.hpp:20
glm::eulerAngles
GLM_FUNC_DECL vec< 3, T, Q > eulerAngles(tquat< T, Q > const &x)
Returns euler angles, pitch as x, yaw as y, roll as z.
glm::length
GLM_FUNC_DECL T length(tquat< T, Q > const &q)
Returns the length of the quaternion.
glm::lessThanEqual
GLM_FUNC_DECL vec< 4, bool, Q > lessThanEqual(tquat< T, Q > const &x, tquat< T, Q > const &y)
Returns the component-wise comparison of result x <= y.
glm::dot
GLM_FUNC_DECL T dot(tquat< T, Q > const &x, tquat< T, Q > const &y)
Returns dot product of q1 and q2, i.e., q1[0] * q2[0] + q1[1] * q2[1] + ...
glm::notEqual
GLM_FUNC_DECL vec< 4, bool, Q > notEqual(tquat< T, Q > const &x, tquat< T, Q > const &y)
Returns the component-wise comparison of result x != y.
glm::mat3_cast
GLM_FUNC_DECL mat< 3, 3, T, Q > mat3_cast(tquat< T, Q > const &x)
Converts a quaternion to a 3 * 3 matrix.
glm::slerp
GLM_FUNC_DECL tquat< T, Q > slerp(tquat< T, Q > const &x, tquat< T, Q > const &y, T a)
Spherical linear interpolation of two quaternions.
glm::isnan
GLM_FUNC_DECL vec< 4, bool, Q > isnan(tquat< T, Q > const &x)
Returns true if x holds a NaN (not a number) representation in the underlying implementation's set of...
glm::lerp
GLM_FUNC_DECL tquat< T, Q > lerp(tquat< T, Q > const &x, tquat< T, Q > const &y, T a)
Linear interpolation of two quaternions.
glm::roll
GLM_FUNC_DECL T roll(tquat< T, Q > const &x)
Returns roll value of euler angles expressed in radians.
glm::inverse
GLM_FUNC_DECL tquat< T, Q > inverse(tquat< T, Q > const &q)
Returns the q inverse.
glm::angleAxis
GLM_FUNC_DECL tquat< T, Q > angleAxis(T const &angle, vec< 3, T, Q > const &axis)
Build a quaternion from an angle and a normalized axis.
glm::normalize
GLM_FUNC_DECL tquat< T, Q > normalize(tquat< T, Q > const &q)
Returns the normalized quaternion.
glm::greaterThanEqual
GLM_FUNC_DECL vec< 4, bool, Q > greaterThanEqual(tquat< T, Q > const &x, tquat< T, Q > const &y)
Returns the component-wise comparison of result x >= y.
glm::mat4_cast
GLM_FUNC_DECL mat< 4, 4, T, Q > mat4_cast(tquat< T, Q > const &x)
Converts a quaternion to a 4 * 4 matrix.
glm::greaterThan
GLM_FUNC_DECL vec< 4, bool, Q > greaterThan(tquat< T, Q > const &x, tquat< T, Q > const &y)
Returns the component-wise comparison of result x > y.