| 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;
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 vec<3, T, Q> operator*(tquat<T, Q> const& q, vec<3, T, Q> const& v);
150
151 template<typename T, qualifier Q>
152 GLM_FUNC_DECL vec<3, T, Q> operator*(vec<3, T, Q> const& v, tquat<T, Q> const& q);
153
154 template<typename T, qualifier Q>
155 GLM_FUNC_DECL vec<4, T, Q> operator*(tquat<T, Q> const& q, vec<4, T, Q> const& v);
156
157 template<typename T, qualifier Q>
158 GLM_FUNC_DECL vec<4, T, Q> operator*(vec<4, T, Q> const& v, tquat<T, Q> const& q);
159
160 template<typename T, qualifier Q>
161 GLM_FUNC_DECL tquat<T, Q> operator*(tquat<T, Q> const& q, T const& s);
162
163 template<typename T, qualifier Q>
164 GLM_FUNC_DECL tquat<T, Q> operator*(T const& s, tquat<T, Q> const& q);
165
166 template<typename T, qualifier Q>
167 GLM_FUNC_DECL tquat<T, Q> operator/(tquat<T, Q> const& q, T const& s);
168
169 // -- Boolean operators --
170
171 template<typename T, qualifier Q>
172 GLM_FUNC_DECL bool operator==(tquat<T, Q> const& q1, tquat<T, Q> const& q2);
173
174 template<typename T, qualifier Q>
175 GLM_FUNC_DECL bool operator!=(tquat<T, Q> const& q1, tquat<T, Q> const& q2);
176
182 template<typename T, qualifier Q>
183 GLM_FUNC_DECL T length(tquat<T, Q> const& q);
184
190 template<typename T, qualifier Q>
191 GLM_FUNC_DECL tquat<T, Q> normalize(tquat<T, Q> const& q);
192
198 template<typename T, qualifier Q>
199 GLM_FUNC_DECL T dot(tquat<T, Q> const& x, tquat<T, Q> const& y);
200
212 template<typename T, qualifier Q>
213 GLM_FUNC_DECL tquat<T, Q> mix(tquat<T, Q> const& x, tquat<T, Q> const& y, T a);
214
224 template<typename T, qualifier Q>
225 GLM_FUNC_DECL tquat<T, Q> lerp(tquat<T, Q> const& x, tquat<T, Q> const& y, T a);
226
236 template<typename T, qualifier Q>
237 GLM_FUNC_DECL tquat<T, Q> slerp(tquat<T, Q> const& x, tquat<T, Q> const& y, T a);
238
244 template<typename T, qualifier Q>
245 GLM_FUNC_DECL tquat<T, Q> conjugate(tquat<T, Q> const& q);
246
252 template<typename T, qualifier Q>
253 GLM_FUNC_DECL tquat<T, Q> inverse(tquat<T, Q> const& q);
254
263 template<typename T, qualifier Q>
264 GLM_FUNC_DECL tquat<T, Q> rotate(tquat<T, Q> const& q, T const& angle, vec<3, T, Q> const& axis);
265
272 template<typename T, qualifier Q>
273 GLM_FUNC_DECL vec<3, T, Q> eulerAngles(tquat<T, Q> const& x);
274
280 template<typename T, qualifier Q>
281 GLM_FUNC_DECL T roll(tquat<T, Q> const& x);
282
288 template<typename T, qualifier Q>
289 GLM_FUNC_DECL T pitch(tquat<T, Q> const& x);
290
296 template<typename T, qualifier Q>
297 GLM_FUNC_DECL T yaw(tquat<T, Q> const& x);
298
304 template<typename T, qualifier Q>
305 GLM_FUNC_DECL mat<3, 3, T, Q> mat3_cast(tquat<T, Q> const& x);
306
312 template<typename T, qualifier Q>
313 GLM_FUNC_DECL mat<4, 4, T, Q> mat4_cast(tquat<T, Q> const& x);
314
320 template<typename T, qualifier Q>
321 GLM_FUNC_DECL tquat<T, Q> quat_cast(mat<3, 3, T, Q> const& x);
322
328 template<typename T, qualifier Q>
329 GLM_FUNC_DECL tquat<T, Q> quat_cast(mat<4, 4, T, Q> const& x);
330
336 template<typename T, qualifier Q>
337 GLM_FUNC_DECL T angle(tquat<T, Q> const& x);
338
344 template<typename T, qualifier Q>
345 GLM_FUNC_DECL vec<3, T, Q> axis(tquat<T, Q> const& x);
346
354 template<typename T, qualifier Q>
355 GLM_FUNC_DECL tquat<T, Q> angleAxis(T const& angle, vec<3, T, Q> const& axis);
356
362 template<typename T, qualifier Q>
363 GLM_FUNC_DECL vec<4, bool, Q> lessThan(tquat<T, Q> const& x, tquat<T, Q> const& y);
364
370 template<typename T, qualifier Q>
371 GLM_FUNC_DECL vec<4, bool, Q> lessThanEqual(tquat<T, Q> const& x, tquat<T, Q> const& y);
372
378 template<typename T, qualifier Q>
379 GLM_FUNC_DECL vec<4, bool, Q> greaterThan(tquat<T, Q> const& x, tquat<T, Q> const& y);
380
386 template<typename T, qualifier Q>
387 GLM_FUNC_DECL vec<4, bool, Q> greaterThanEqual(tquat<T, Q> const& x, tquat<T, Q> const& y);
388
394 template<typename T, qualifier Q>
395 GLM_FUNC_DECL vec<4, bool, Q> equal(tquat<T, Q> const& x, tquat<T, Q> const& y);
396
402 template<typename T, qualifier Q>
403 GLM_FUNC_DECL vec<4, bool, Q> notEqual(tquat<T, Q> const& x, tquat<T, Q> const& y);
404
416 template<typename T, qualifier Q>
417 GLM_FUNC_DECL vec<4, bool, Q> isnan(tquat<T, Q> const& x);
418
428 template<typename T, qualifier Q>
429 GLM_FUNC_DECL vec<4, bool, Q> isinf(tquat<T, Q> const& x);
430
432 } //namespace glm
433
434 #include "quaternion.inl"
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
Definition: common.hpp:20
glm::inverse
GLM_FUNC_DECL tquat< T, Q > inverse(tquat< T, Q > const &q)
Returns the q inverse.
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::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::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::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::axis
GLM_FUNC_DECL vec< 3, T, Q > axis(tquat< T, Q > const &x)
Returns the q rotation axis.
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::angle
GLM_FUNC_DECL T angle(tquat< T, Q > const &x)
Returns the quaternion rotation angle.
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::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::conjugate
GLM_FUNC_DECL tquat< T, Q > conjugate(tquat< T, Q > const &q)
Returns the q conjugate.
glm::quat_cast
GLM_FUNC_DECL tquat< T, Q > quat_cast(mat< 4, 4, T, Q > const &x)
Converts a 4 * 4 matrix to a quaternion.
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.
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::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::yaw
GLM_FUNC_DECL T yaw(tquat< T, Q > const &x)
Returns yaw value of euler angles expressed in radians.
glm::length
GLM_FUNC_DECL T length(tquat< T, Q > const &q)
Returns the length of the quaternion.
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::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::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::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::roll
GLM_FUNC_DECL T roll(tquat< T, Q > const &x)
Returns roll value of euler angles expressed in radians.