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 P = defaultp>
33 struct tquat
34 {
35 // -- Implementation detail --
36
37 typedef tquat<T, P> 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<P>::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, P> const& q) GLM_DEFAULT;
82 template<qualifier Q>
83 GLM_FUNC_DECL GLM_CONSTEXPR tquat(tquat<T, Q> const& q);
84
85 // -- Explicit basic constructors --
86
87 GLM_FUNC_DECL GLM_CONSTEXPR tquat(T s, vec<3, T, P> 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 Q>
93 GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tquat(tquat<U, Q> const& q);
94
96 # if GLM_HAS_EXPLICIT_CONVERSION_OPERATORS
97 GLM_FUNC_DECL explicit operator mat<3, 3, T, P>();
98 GLM_FUNC_DECL explicit operator mat<4, 4, T, P>();
99 # endif
100
107 GLM_FUNC_DECL tquat(vec<3, T, P> const & u, vec<3, T, P> const & v);
108
110 GLM_FUNC_DECL GLM_EXPLICIT tquat(vec<3, T, P> const& eulerAngles);
111 GLM_FUNC_DECL GLM_EXPLICIT tquat(mat<3, 3, T, P> const& q);
112 GLM_FUNC_DECL GLM_EXPLICIT tquat(mat<4, 4, T, P> const& q);
113
114 // -- Unary arithmetic operators --
115
116 GLM_FUNC_DECL tquat<T, P> & operator=(tquat<T, P> const& q) GLM_DEFAULT;
117
118 template<typename U>
119 GLM_FUNC_DECL tquat<T, P> & operator=(tquat<U, P> const& q);
120 template<typename U>
121 GLM_FUNC_DECL tquat<T, P> & operator+=(tquat<U, P> const& q);
122 template<typename U>
123 GLM_FUNC_DECL tquat<T, P> & operator-=(tquat<U, P> const& q);
124 template<typename U>
125 GLM_FUNC_DECL tquat<T, P> & operator*=(tquat<U, P> const& q);
126 template<typename U>
127 GLM_FUNC_DECL tquat<T, P> & operator*=(U s);
128 template<typename U>
129 GLM_FUNC_DECL tquat<T, P> & operator/=(U s);
130 };
131
132 // -- Unary bit operators --
133
134 template<typename T, qualifier P>
135 GLM_FUNC_DECL tquat<T, P> operator+(tquat<T, P> const& q);
136
137 template<typename T, qualifier P>
138 GLM_FUNC_DECL tquat<T, P> operator-(tquat<T, P> const& q);
139
140 // -- Binary operators --
141
142 template<typename T, qualifier P>
143 GLM_FUNC_DECL tquat<T, P> operator+(tquat<T, P> const & q, tquat<T, P> const & p);
144
145 template<typename T, qualifier P>
146 GLM_FUNC_DECL tquat<T, P> operator*(tquat<T, P> const & q, tquat<T, P> const & p);
147
148 template<typename T, qualifier P>
149 GLM_FUNC_DECL vec<3, T, P> operator*(tquat<T, P> const & q, vec<3, T, P> const & v);
150
151 template<typename T, qualifier P>
152 GLM_FUNC_DECL vec<3, T, P> operator*(vec<3, T, P> const & v, tquat<T, P> const & q);
153
154 template<typename T, qualifier P>
155 GLM_FUNC_DECL vec<4, T, P> operator*(tquat<T, P> const & q, vec<4, T, P> const & v);
156
157 template<typename T, qualifier P>
158 GLM_FUNC_DECL vec<4, T, P> operator*(vec<4, T, P> const & v, tquat<T, P> const & q);
159
160 template<typename T, qualifier P>
161 GLM_FUNC_DECL tquat<T, P> operator*(tquat<T, P> const & q, T const & s);
162
163 template<typename T, qualifier P>
164 GLM_FUNC_DECL tquat<T, P> operator*(T const & s, tquat<T, P> const & q);
165
166 template<typename T, qualifier P>
167 GLM_FUNC_DECL tquat<T, P> operator/(tquat<T, P> const & q, T const & s);
168
169 // -- Boolean operators --
170
171 template<typename T, qualifier P>
172 GLM_FUNC_DECL bool operator==(tquat<T, P> const & q1, tquat<T, P> const & q2);
173
174 template<typename T, qualifier P>
175 GLM_FUNC_DECL bool operator!=(tquat<T, P> const & q1, tquat<T, P> const & q2);
176
182 template<typename T, qualifier P>
183 GLM_FUNC_DECL T length(tquat<T, P> const & q);
184
190 template<typename T, qualifier P>
191 GLM_FUNC_DECL tquat<T, P> normalize(tquat<T, P> const & q);
192
198 template<typename T, qualifier P>
199 GLM_FUNC_DECL T dot(tquat<T, P> const & x, tquat<T, P> const & y);
200
212 template<typename T, qualifier P>
213 GLM_FUNC_DECL tquat<T, P> mix(tquat<T, P> const & x, tquat<T, P> const & y, T a);
214
224 template<typename T, qualifier P>
225 GLM_FUNC_DECL tquat<T, P> lerp(tquat<T, P> const & x, tquat<T, P> const & y, T a);
226
236 template<typename T, qualifier P>
237 GLM_FUNC_DECL tquat<T, P> slerp(tquat<T, P> const & x, tquat<T, P> const & y, T a);
238
244 template<typename T, qualifier P>
245 GLM_FUNC_DECL tquat<T, P> conjugate(tquat<T, P> const & q);
246
252 template<typename T, qualifier P>
253 GLM_FUNC_DECL tquat<T, P> inverse(tquat<T, P> const & q);
254
263 template<typename T, qualifier P>
264 GLM_FUNC_DECL tquat<T, P> rotate(tquat<T, P> const & q, T const & angle, vec<3, T, P> const & axis);
265
272 template<typename T, qualifier P>
273 GLM_FUNC_DECL vec<3, T, P> eulerAngles(tquat<T, P> const & x);
274
280 template<typename T, qualifier P>
281 GLM_FUNC_DECL T roll(tquat<T, P> const& x);
282
288 template<typename T, qualifier P>
289 GLM_FUNC_DECL T pitch(tquat<T, P> const& x);
290
296 template<typename T, qualifier P>
297 GLM_FUNC_DECL T yaw(tquat<T, P> const& x);
298
304 template<typename T, qualifier P>
305 GLM_FUNC_DECL mat<3, 3, T, P> mat3_cast(tquat<T, P> const& x);
306
312 template<typename T, qualifier P>
313 GLM_FUNC_DECL mat<4, 4, T, P> mat4_cast(tquat<T, P> const& x);
314
320 template<typename T, qualifier P>
321 GLM_FUNC_DECL tquat<T, P> quat_cast(mat<3, 3, T, P> const& x);
322
328 template<typename T, qualifier P>
329 GLM_FUNC_DECL tquat<T, P> quat_cast(mat<4, 4, T, P> const& x);
330
336 template<typename T, qualifier P>
337 GLM_FUNC_DECL T angle(tquat<T, P> const& x);
338
344 template<typename T, qualifier P>
345 GLM_FUNC_DECL vec<3, T, P> axis(tquat<T, P> const& x);
346
354 template<typename T, qualifier P>
355 GLM_FUNC_DECL tquat<T, P> angleAxis(T const& angle, vec<3, T, P> const& axis);
356
362 template<typename T, qualifier P>
363 GLM_FUNC_DECL vec<4, bool, P> lessThan(tquat<T, P> const& x, tquat<T, P> const& y);
364
370 template<typename T, qualifier P>
371 GLM_FUNC_DECL vec<4, bool, P> lessThanEqual(tquat<T, P> const& x, tquat<T, P> const& y);
372
378 template<typename T, qualifier P>
379 GLM_FUNC_DECL vec<4, bool, P> greaterThan(tquat<T, P> const& x, tquat<T, P> const& y);
380
386 template<typename T, qualifier P>
387 GLM_FUNC_DECL vec<4, bool, P> greaterThanEqual(tquat<T, P> const& x, tquat<T, P> const& y);
388
394 template<typename T, qualifier P>
395 GLM_FUNC_DECL vec<4, bool, P> equal(tquat<T, P> const& x, tquat<T, P> const& y);
396
402 template<typename T, qualifier P>
403 GLM_FUNC_DECL vec<4, bool, P> notEqual(tquat<T, P> const& x, tquat<T, P> const& y);
404
416 template<typename T, qualifier P>
417 GLM_FUNC_DECL vec<4, bool, P> isnan(tquat<T, P> const& x);
418
428 template<typename T, qualifier P>
429 GLM_FUNC_DECL vec<4, bool, P> isinf(tquat<T, P> const& x);
430
432 } //namespace glm
433
434 #include "quaternion.inl"
glm::angleAxis
GLM_FUNC_DECL tquat< T, P > angleAxis(T const &angle, vec< 3, T, P > const &axis)
Build a quaternion from an angle and a normalized axis.
glm::inverse
GLM_FUNC_DECL tquat< T, P > inverse(tquat< T, P > const &q)
Returns the q inverse.
glm::length
GLM_FUNC_DECL T length(tquat< T, P > const &q)
Returns the length of the quaternion.
glm::greaterThanEqual
GLM_FUNC_DECL vec< 4, bool, P > greaterThanEqual(tquat< T, P > const &x, tquat< T, P > const &y)
Returns the component-wise comparison of result x >= y.
glm
Definition: _noise.hpp:11
glm::lessThan
GLM_FUNC_DECL vec< 4, bool, P > lessThan(tquat< T, P > const &x, tquat< T, P > const &y)
Returns the component-wise comparison result of x < y.
glm::mix
GLM_FUNC_DECL tquat< T, P > mix(tquat< T, P > const &x, tquat< T, P > const &y, T a)
Spherical linear interpolation of two quaternions.
glm::mat3_cast
GLM_FUNC_DECL mat< 3, 3, T, P > mat3_cast(tquat< T, P > const &x)
Converts a quaternion to a 3 * 3 matrix.
glm::angle
GLM_FUNC_DECL T angle(tquat< T, P > const &x)
Returns the quaternion rotation angle.
glm::equal
GLM_FUNC_DECL vec< 4, bool, P > equal(tquat< T, P > const &x, tquat< T, P > const &y)
Returns the component-wise comparison of result x == y.
glm::axis
GLM_FUNC_DECL vec< 3, T, P > axis(tquat< T, P > const &x)
Returns the q rotation axis.
glm::notEqual
GLM_FUNC_DECL vec< 4, bool, P > notEqual(tquat< T, P > const &x, tquat< T, P > const &y)
Returns the component-wise comparison of result x != y.
glm::normalize
GLM_FUNC_DECL tquat< T, P > normalize(tquat< T, P > const &q)
Returns the normalized quaternion.
glm::isinf
GLM_FUNC_DECL vec< 4, bool, P > isinf(tquat< T, P > const &x)
Returns true if x holds a positive infinity or negative infinity representation in the underlying imp...
glm::pitch
GLM_FUNC_DECL T pitch(tquat< T, P > const &x)
Returns pitch value of euler angles expressed in radians.
glm::isnan
GLM_FUNC_DECL vec< 4, bool, P > isnan(tquat< T, P > 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, P > const &x)
Returns roll value of euler angles expressed in radians.
glm::lessThanEqual
GLM_FUNC_DECL vec< 4, bool, P > lessThanEqual(tquat< T, P > const &x, tquat< T, P > const &y)
Returns the component-wise comparison of result x <= y.
glm::quat_cast
GLM_FUNC_DECL tquat< T, P > quat_cast(mat< 4, 4, T, P > const &x)
Converts a 4 * 4 matrix to a quaternion.
glm::eulerAngles
GLM_FUNC_DECL vec< 3, T, P > eulerAngles(tquat< T, P > const &x)
Returns euler angles, pitch as x, yaw as y, roll as z.
glm::greaterThan
GLM_FUNC_DECL vec< 4, bool, P > greaterThan(tquat< T, P > const &x, tquat< T, P > const &y)
Returns the component-wise comparison of result x > y.
glm::mat4_cast
GLM_FUNC_DECL mat< 4, 4, T, P > mat4_cast(tquat< T, P > const &x)
Converts a quaternion to a 4 * 4 matrix.
glm::lerp
GLM_FUNC_DECL tquat< T, P > lerp(tquat< T, P > const &x, tquat< T, P > const &y, T a)
Linear interpolation of two quaternions.
glm::conjugate
GLM_FUNC_DECL tquat< T, P > conjugate(tquat< T, P > const &q)
Returns the q conjugate.
glm::rotate
GLM_FUNC_DECL tquat< T, P > rotate(tquat< T, P > const &q, T const &angle, vec< 3, T, P > const &axis)
Rotates a quaternion from a vector of 3 components axis and an angle.
glm::dot
GLM_FUNC_DECL T dot(tquat< T, P > const &x, tquat< T, P > 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, P > slerp(tquat< T, P > const &x, tquat< T, P > const &y, T a)
Spherical linear interpolation of two quaternions.
glm::yaw
GLM_FUNC_DECL T yaw(tquat< T, P > const &x)
Returns yaw value of euler angles expressed in radians.