SH4ZAM! 0.7.0
Fast math library for the Sega Dreamcast's SH4 CPU
Loading...
Searching...
No Matches
shz_quat.hpp
Go to the documentation of this file.
1/*! \file
2 \brief C++ routines for operating upon quaternions.
3 \ingroup quat
4
5 \todo
6 - overload arithmetic operators
7
8 \author 2025, 2026 Falco Girgis
9 \copyright MIT License
10*/
11
12#ifndef SHZ_QUAT_HPP
13#define SHZ_QUAT_HPP
14
15#include <compare>
16#include <tuple>
17
18#include "shz_quat.h"
19#include "shz_vector.hpp"
20
21namespace shz {
22
23 /*! C++ structure representing a quaternion.
24
25 A quaternion represents a rotation about an arbitrary axis in 3D space.
26
27 \warning
28 The SH4ZAM internal quaternion representation puts the W or angle component
29 first, followed by the X, Y, Z components for the axis!
30
31 \note
32 shz::quat is the C++ extension of shz_quat_t, which adds member functions,
33 convenience operators, and still retains backwards compatibility with the
34 C API.
35
36 \sa shz_quat_t, shz::mat4x4, shz::vec3
37 */
38 struct quat: public shz_quat_t {
39
40 /*! \name Initialization
41 \brief Routines for creating and initializing quaternions.
42 @{
43 */
44
45 //! Default constructor: does nothing.
46 quat() noexcept = default;
47
48 //! Default copy constructor.
49 quat(const quat& other) noexcept = default;
50
51 //! Value constructor: initializes a quaternion with the given values for each component.
52 SHZ_FORCE_INLINE quat(float w, float x, float y, float z) noexcept:
53 shz_quat_t({w, x, y, z}) {}
54
55 //! C Converting constructor: constructs a C++ shz::quat from a C shz_quat_t.
56 SHZ_FORCE_INLINE quat(const shz_quat_t& q) noexcept:
57 shz_quat_t(q) {}
58
59 //! Converting constructor from existing volatile C instance.
60 SHZ_FORCE_INLINE quat(const volatile shz_quat_t& other) noexcept:
61 shz_quat_t(const_cast<const shz_quat_t&>(other)) {}
62
63 //! Returns an identity quaternion.
64 SHZ_FORCE_INLINE static quat identity() noexcept {
66 }
67
68 //! C++ convenience wrapper for shz_quat_from_angles_xyz().
69 SHZ_FORCE_INLINE static quat from_angles_xyz(float x, float y, float z) noexcept {
71 }
72
73 //! Initializes a quaternion which is a rotation in \p angle radians about the given \p axis.
74 SHZ_FORCE_INLINE static quat from_axis_angle(vec3 axis, float angle) noexcept {
75 return shz_quat_from_axis_angle(axis, angle);
76 }
77
78 //! Creates a quaternion looking in the given direction with the given reference direction.
79 SHZ_FORCE_INLINE static quat from_look_axis(vec3 forward, vec3 up) noexcept {
80 return shz_quat_from_look_axis(forward, up);
81 }
82
83 //! Returns the quaternion representing the rotation from the \p start to the \p end axes.
84 SHZ_FORCE_INLINE static quat from_rotated_axis(vec3 start, vec3 end) noexcept {
85 return shz_quat_from_rotated_axis(start, end);
86 }
87
88 //! Returns the quaternion that is linearly interpolating \p q to \p p, by a t factor of `0.0f-1.0f`.
89 SHZ_FORCE_INLINE static quat lerp(quat q, quat p, float t) noexcept {
90 return shz_quat_lerp(q, p, t);
91 }
92
93 //! Equivalent to lerp(), except that the resulting quaternion is normalized.
94 SHZ_FORCE_INLINE static quat nlerp(quat q, quat p, float t) noexcept {
95 return shz_quat_nlerp(q, p, t);
96 }
97
98 //! Returns the quaternion that is spherically linearly interpolating \p q to \p p, by a \p t factor of `0.0f-1.0f`.
99 SHZ_FORCE_INLINE static quat slerp(quat q, quat p, float t) noexcept {
100 return shz_quat_slerp(q, p, t);
101 }
102
103 //! Evaluates the smooth cubic spherical interpolation (SQUAD) at parameter \p t.
104 SHZ_FORCE_INLINE static quat squad(quat q1, quat q2, quat s1, quat s2, float t) noexcept {
105 return shz_quat_squad(q1, q2, s1, s2, t);
106 }
107
108 //! @}
109
110#ifdef SHZ_CPP23
111
112 /*! \name Component Accessors
113 \brief Routines for iterating and accessing components.
114 @{
115 */
116
117 //! Overloaded subscript operator for indexing into the quaternion like an array.
118 SHZ_FORCE_INLINE auto&& operator[](this auto&& self, size_t index) noexcept {
119 return std::forward<decltype(self)>(self).e[index];
120 }
121
122 //! Returns an iterator to the first element within the quaternion -- For STL support.
123 SHZ_FORCE_INLINE auto begin(this auto&& self) noexcept {
124 return &self[0];
125 }
126
127 //! Returns an iterator to the end of the quaternion -- For STL support.
128 SHZ_FORCE_INLINE auto end(this auto&& self) noexcept {
129 return &self[4];
130 }
131
132 //! @}
133
134 /*! \name Relational Operators
135 \brief Overloaded comparison operators
136 @{
137 */
138
139 //! Overloaded space-ship operator for auto-generating lexicographical comparison operators.
140 friend auto operator<=>(quat lhs, quat rhs) noexcept {
142 }
143
144 //! Returns true if \p lhs is lexicographically less than \p rhs.
145 friend auto operator<(quat lhs, quat rhs) noexcept {
147 rhs.begin(), rhs.end());
148 }
149#endif
150 //! Overloaded comparison operator, checks for quaternion equality.
151 friend bool operator==(quat lhs, quat rhs) noexcept {
152 return shz_quat_equal(lhs, rhs);
153 }
154
155 //! Overloaded operator for assigning volatile reference to base C type.
156 volatile quat& operator=(volatile shz_quat_t other) volatile noexcept {
157 *static_cast<quat*>(const_cast<quat*>(this)) = quat(const_cast<shz_quat_t&>(other));
158 return *static_cast<volatile quat*>(this);
159 }
160
161 //! @}
162
163 /*! \name Properties
164 \brief Routines for accessing or extracting values.
165 @{
166 */
167
168 //! Returns the angle of rotation represented by the given quaternion.
169 SHZ_FORCE_INLINE float angle() const noexcept {
170 return shz_quat_angle(*this);
171 }
172
173 //! Returns the axis of rotation represented by the given quaternion.
174 SHZ_FORCE_INLINE vec3 axis() const noexcept {
175 return shz_quat_axis(*this);
176 }
177
178 //! Returns the angle of rotation about the X axis represented by the given quaternion.
179 SHZ_FORCE_INLINE float angle_x() const noexcept {
180 return shz_quat_angle_x(*this);
181 }
182
183 //! Returns the angle of rotation about the Y axis represented by the given quaternion.
184 SHZ_FORCE_INLINE float angle_y() const noexcept {
185 return shz_quat_angle_y(*this);
186 }
187
188 //! Returns the angle of rotation about the Z axis represented by the given quaternion.
189 SHZ_FORCE_INLINE float angle_z() const noexcept {
190 return shz_quat_angle_z(*this);
191 }
192
193 //! Returns the magnitude of the quaternion squared.
194 SHZ_FORCE_INLINE float magnitude_sqr() const noexcept {
195 return shz_quat_magnitude_sqr(*this);
196 }
197
198 //! Returns the magnitude of the quaternion.
199 SHZ_FORCE_INLINE float magnitude() const noexcept {
200 return shz_quat_magnitude(*this);
201 }
202
203 //! Returns the inverse of the magnitude of the quaternion.
204 SHZ_FORCE_INLINE float magnitude_inv() const noexcept {
205 return shz_quat_magnitude_inv(*this);
206 }
207
208 //! @}
209
210 /*! \name Conversions
211 \brief Routines for converting to other types.
212 @{
213 */
214
215 //! Returns the tait-bryan rotation angles about the X, Y, then Z axes which are represented by the given quaternion.
216 SHZ_FORCE_INLINE vec3 to_angles_xyz() const noexcept {
217 return shz_quat_to_angles_xyz(*this);
218 }
219
220 //! Returns both the axis and angle of rotation through the pointer arguments.
221 SHZ_FORCE_INLINE void to_axis_angle(shz_vec3_t* axis, float* angle) const noexcept {
222 shz_quat_to_axis_angle(*this, axis, angle);
223 }
224
225 //! Returns both the axis and angle of rotation as a std::pair.
226 SHZ_FORCE_INLINE auto to_axis_angle() const noexcept -> std::pair<vec3, float> {
227 std::pair<vec3, float> aa;
228 shz_quat_to_axis_angle(*this, &std::get<0>(aa), &std::get<1>(aa));
229 return aa;
230 }
231
232 //! @}
233
234 /*! \name Modifiers
235 \brief Routines for applying modifiers to an existing quaternion.
236 @{
237 */
238
239 //! Returns the given quaternion as a unit quaternion.
240 SHZ_FORCE_INLINE quat normalized() const noexcept {
241 return shz_quat_normalize(*this);
242 }
243
244 //! Normalizes the given quaternion.
245 SHZ_FORCE_INLINE void normalize() noexcept {
246 *this = normalized();
247 }
248
249 //! Returns a safely normalized quaternion from the given quaternion, protecting against division-by-zero.
250 SHZ_FORCE_INLINE quat normalized_safe() const noexcept {
251 return shz_quat_normalize_safe(*this);
252 }
253
254 //! Safely normalizes the given quaternion by protecting against division-by-zero.
255 SHZ_FORCE_INLINE void normalize_safe() noexcept {
256 *this = normalized_safe();
257 }
258
259 //! Returns a quaternion that is the conjugate of the given quaternion.
260 SHZ_FORCE_INLINE quat conjugated() const noexcept {
261 return shz_quat_conjugate(*this);
262 }
263
264 //! Conjugates the given quaternion.
265 SHZ_FORCE_INLINE void conjugate() noexcept {
266 *this = conjugated();
267 }
268
269 //! Returns the inverse of the given quaternion.
270 SHZ_FORCE_INLINE quat inverse() const noexcept {
271 return shz_quat_inv(*this);
272 }
273
274 //! Inverts the given quaternion.
275 SHZ_FORCE_INLINE void invert() noexcept {
276 *this = inverse();
277 }
278
279 //! Returns a new quaternion whose components are the negated values of the given quaternion.
280 SHZ_FORCE_INLINE quat negated() const noexcept {
281 return shz_quat_neg(*this);
282 }
283
284 //! Negates the components of the given quaternion.
285 SHZ_FORCE_INLINE void negate() noexcept {
286 *this = negated();
287 }
288
289 //! @}
290
291 /*! \name Arithmetic
292 \brief Routines performing calculations with quaternions.
293 @{
294 */
295
296 //! Returns a new quaternion from adding the given quaterion to \p rhs.
297 SHZ_FORCE_INLINE quat add(quat rhs) const noexcept {
298 return shz_quat_add(*this, rhs);
299 }
300
301 //! Returns a new quaternion from adding \p rhs from the given quaternion.
302 SHZ_FORCE_INLINE quat sub(quat rhs) const noexcept {
303 return shz_quat_sub(*this, rhs);
304 }
305
306 //! Returns a new quaternion from scaling the given quaterion by \p s.
307 SHZ_FORCE_INLINE quat scaled(float s) const noexcept {
308 return shz_quat_scale(*this, s);
309 }
310
311 //! Multiplies each component of the given quaternion by \p s.
312 SHZ_FORCE_INLINE void scale(float s) noexcept {
313 *this = scaled(s);
314 }
315
316 //! Returns the dot product between the given quaternion and another.
317 SHZ_FORCE_INLINE float dot(quat other) const noexcept {
318 return shz_quat_dot(*this, other);
319 }
320
321 //! Returns the dot product of the given quaternion against two others.
322 SHZ_FORCE_INLINE vec2 dot(quat q1, quat q2) const noexcept {
323 return shz_quat_dot2(*this, q1, q2);
324 }
325
326 //! Returns the dot product of the given quaternion against three others.
327 SHZ_FORCE_INLINE vec3 dot(quat q1, quat q2, quat q3) const noexcept {
328 return shz_quat_dot3(*this, q1, q2, q3);
329 }
330
331 //! Returns a new quaterion from multiplying the given quaternion by another.
332 SHZ_FORCE_INLINE quat mult(quat rhs) const noexcept {
333 return shz_quat_mult(*this, rhs);
334 }
335
336 //! Returns a new quaterion from dividing the given quaternion by another (or multiplying the given quaternion by the inverse of another).
337 SHZ_FORCE_INLINE quat div(quat rhs) const noexcept {
338 return shz_quat_div(*this, rhs);
339 }
340
341 //! @}
342
343 /*! \name Miscellaneous
344 \brief Other types of quaternion operations.
345 @{
346 */
347
348 //! Returns the angle in radians between the rotations represented by quaternions \p q and \p p.
349 SHZ_FORCE_INLINE float angle_between(quat p) const noexcept {
350 return shz_quat_angle_between(*this, p);
351 }
352
353 //! Rotates quaternion \p from towards quaternion \p to by at most \p max_angle radians.
354 SHZ_FORCE_INLINE quat rotate_towards(shz_quat_t to, float max_angle) const noexcept {
355 return shz_quat_rotate_towards(*this, to, max_angle);
356 }
357
358 //! @}
359
360 /*! \name Transformations
361 \brief Routines for applying quaternion transforms.
362 @{
363 */
364
365 //! Returns a new shz::vec3 from transforming \p in by the given quaternion.
366 SHZ_FORCE_INLINE vec3 transform(vec3 in) const noexcept {
367 return shz_quat_transform_vec3(*this, in);
368 }
369
370 //! @}
371
372 //! Overloaded unary negation operator, returns the negation of the given quaternion.
373 SHZ_FORCE_INLINE quat operator-() const noexcept {
374 return negated();
375 }
376
377 //! Adds and accumulates \p rhs onto the given quaternion.
378 SHZ_FORCE_INLINE quat operator+=(quat rhs) noexcept {
379 return *this = add(rhs);
380 }
381
382 //! Subtracts \p rhs from the given quaternion.
383 SHZ_FORCE_INLINE quat operator-=(quat rhs) noexcept {
384 return *this = sub(rhs);
385 }
386
387 //! Multiplies and accumulates \p rhs into the given quaternion.
388 SHZ_FORCE_INLINE quat operator*=(quat rhs) noexcept {
389 return *this = mult(rhs);
390 }
391
392 //! Divides the given quaternion by \p rhs.
393 SHZ_FORCE_INLINE quat operator/=(quat rhs) noexcept {
394 return *this = div(rhs);
395 }
396
397 //! Multiplies and accumulates each component of the given quaternion by \p rhs.
398 SHZ_FORCE_INLINE quat operator*=(float rhs) noexcept {
399 scale(rhs);
400 return *this;
401 }
402
403 //! Divides each component of the given quaternion by \p rhs.
404 SHZ_FORCE_INLINE quat operator/=(float rhs) noexcept {
406 return *this;
407 }
408 };
409
410 //! Alternate C++ alias for quat, for those who like POSIX style.
411 using quat_t = quat;
412
413 //! Overloaded operator for adding two quaternions and returning the result.
414 SHZ_FORCE_INLINE quat operator+(quat lhs, quat rhs) noexcept {
415 return lhs.add(rhs);
416 }
417
418 //! Overloaded operator for subtracting two quaternions and returning the result.
419 SHZ_FORCE_INLINE quat operator-(quat lhs, quat rhs) noexcept {
420 return lhs.sub(rhs);
421 }
422
423 //! Overloaded operator for multiplying two quaternions and returning the result.
424 SHZ_FORCE_INLINE quat operator*(quat lhs, quat rhs) noexcept {
425 return lhs.mult(rhs);
426 }
427
428 //! Overloaded operator for dividing \p lhs by \p rhs (or multiplying by the reciprocal of \p rhs) and returning the result.
429 SHZ_FORCE_INLINE quat operator/(quat lhs, quat rhs) noexcept {
430 return lhs.div(rhs);
431 }
432
433 //! Overloaded operator for scaling each component of \p lhs by \p rhs and returning the result.
434 SHZ_FORCE_INLINE quat operator*(quat lhs, float rhs) noexcept {
435 return lhs.scaled(rhs);
436 }
437
438 //! Overloaded operator for scaling each component of \p rhs by \p lhs and returning the result.
439 SHZ_FORCE_INLINE quat operator*(float lhs, quat rhs) noexcept {
440 return rhs.scaled(lhs);
441 }
442
443 //! Overloaded operator for dividing each element of \p lhs by \p rhs and returning the result.
444 SHZ_FORCE_INLINE quat operator/(quat lhs, float rhs) noexcept {
445 return lhs.scaled(shz_invf(rhs));
446 }
447
448 //! Overloaded operator for dividing each component of \p rhs by \p lhs.
449 SHZ_FORCE_INLINE quat operator/(float lhs, quat rhs) noexcept {
450 return rhs.scaled(shz_invf(lhs));
451 }
452
453 //! Overloaded operator for transforming/rotating a vec3, \p rhs, by a quaternion, \p lhs.
454 SHZ_FORCE_INLINE vec3 operator*(quat lhs, vec3 rhs) noexcept {
455 return lhs.transform(rhs);
456 }
457}
458
459#endif
Namespace enclosing the SH4ZAM C++ API.
Definition shz_cdefs.hpp:21
quat operator*(quat lhs, float rhs) noexcept
Overloaded operator for scaling each component of lhs by rhs and returning the result.
Definition shz_quat.hpp:434
quat operator/(quat lhs, float rhs) noexcept
Overloaded operator for dividing each element of lhs by rhs and returning the result.
Definition shz_quat.hpp:444
quat operator/(quat lhs, quat rhs) noexcept
Overloaded operator for dividing lhs by rhs (or multiplying by the reciprocal of rhs) and returning t...
Definition shz_quat.hpp:429
quat operator*(quat lhs, quat rhs) noexcept
Overloaded operator for multiplying two quaternions and returning the result.
Definition shz_quat.hpp:424
quat operator-(quat lhs, quat rhs) noexcept
Overloaded operator for subtracting two quaternions and returning the result.
Definition shz_quat.hpp:419
vec3 operator*(quat lhs, vec3 rhs) noexcept
Overloaded operator for transforming/rotating a vec3, rhs, by a quaternion, lhs.
Definition shz_quat.hpp:454
quat operator*(float lhs, quat rhs) noexcept
Overloaded operator for scaling each component of rhs by lhs and returning the result.
Definition shz_quat.hpp:439
quat operator/(float lhs, quat rhs) noexcept
Overloaded operator for dividing each component of rhs by lhs.
Definition shz_quat.hpp:449
quat operator+(quat lhs, quat rhs) noexcept
Overloaded operator for adding two quaternions and returning the result.
Definition shz_quat.hpp:414
float shz_quat_magnitude_sqr(shz_quat_t quat) SHZ_NOEXCEPT
Returns the squared magnitude of the given quaternion.
float shz_quat_magnitude(shz_quat_t quat) SHZ_NOEXCEPT
Returns the magnitude of the given quaternion.
shz_vec3_t shz_quat_axis(shz_quat_t q) SHZ_NOEXCEPT
Returns the axis of rotation from the given quaternion.
shz_quat_t shz_quat_inv(shz_quat_t quat) SHZ_NOEXCEPT
Returns the inverse of the given quaternion.
shz_quat_t shz_quat_nlerp(shz_quat_t a, shz_quat_t b, float t) SHZ_NOEXCEPT
Equivalent to shz_quat_lerp(), except that the resulting quaternion is normalized.
shz_quat_t shz_quat_neg(shz_quat_t quat) SHZ_NOEXCEPT
Returns the negation of the given quaternion.
shz_quat_t shz_quat_scale(shz_quat_t q, float f) SHZ_NOEXCEPT
Scales the components of the given quaternion by the given factor.
bool shz_quat_equal(shz_quat_t a, shz_quat_t b) SHZ_NOEXCEPT
Returns true if the two given quaternions are considered equal based on either absolute or relative t...
float shz_quat_angle_between(shz_quat_t q, shz_quat_t p) SHZ_NOEXCEPT
Returns the angle in radians between the rotations represented by quaternions q and p.
shz_quat_t shz_quat_add(shz_quat_t q, shz_quat_t p) SHZ_NOEXCEPT
Returns the quaternion produced from adding each component of the given quaternions.
float shz_quat_magnitude_inv(shz_quat_t quat) SHZ_NOEXCEPT
Returns the inverse magnitude of the given quaternion.
float shz_quat_angle(shz_quat_t q) SHZ_NOEXCEPT
Returns the angle of rotation from the given quaternion.
shz_quat_t shz_quat_slerp(shz_quat_t q, shz_quat_t p, float t) SHZ_NOEXCEPT
Returns the quaternion that is spherically linearly interpolating a to b, by a t factor of 0....
shz_quat_t shz_quat_normalize_safe(shz_quat_t quat) SHZ_NOEXCEPT
SAFELY returns the normalized form of the given quaternion.
shz_quat_t shz_quat_lerp(shz_quat_t a, shz_quat_t b, float t) SHZ_NOEXCEPT
Returns the quaternion that is linearly interpolating a to b, by a t factor of 0.0f-1....
shz_quat_t shz_quat_div(shz_quat_t q, shz_quat_t p) SHZ_NOEXCEPT
Divides quaternion p by quaternion q (multiplying by its inverse), returning the resulting quaternion...
float shz_quat_angle_x(shz_quat_t q) SHZ_NOEXCEPT
Returns the angle of rotation the quaternion represents about the X axis in radians.
shz_vec3_t shz_quat_to_angles_xyz(shz_quat_t q) SHZ_NOEXCEPT
Returns the roll, pitch, and yaw angles of rotation represented by the given quaternion.
shz_quat_t shz_quat_rotate_towards(shz_quat_t from, shz_quat_t to, float max_angle) SHZ_NOEXCEPT
Rotates quaternion from towards quaternion to by at most max_angle radians.
shz_vec2_t shz_quat_dot2(shz_quat_t l, shz_quat_t r1, shz_quat_t r2) SHZ_NOEXCEPT
Returns the two dot products taken between the l quaternion and the r1 and r2 quaternions.
shz_quat_t shz_quat_normalize(shz_quat_t quat) SHZ_NOEXCEPT
Returns the normalized form of the given quaternion.
shz_quat_t shz_quat_squad(shz_quat_t q1, shz_quat_t q2, shz_quat_t s1, shz_quat_t s2, float t) SHZ_NOEXCEPT
Evaluates a smooth cubic spherical interpolation (SQUAD) at parameter t.
float shz_quat_dot(shz_quat_t q1, shz_quat_t q2) SHZ_NOEXCEPT
Returns the dot product of the two quaternions.
shz_quat_t shz_quat_identity(void) SHZ_NOEXCEPT
Initializes and returns an identity quaternion.
void shz_quat_to_axis_angle(shz_quat_t q, shz_vec3_t *vec, float *angle) SHZ_NOEXCEPT
Returns both the axis and angle of rotation simultaneously (faster if both are needed) from the given...
shz_vec3_t shz_quat_dot3(shz_quat_t l, shz_quat_t r1, shz_quat_t r2, shz_quat_t r3) SHZ_NOEXCEPT
Returns the two dot products taken between the l quaternion and the r1, r2, and r3 quaternions.
shz_quat_t shz_quat_from_angles_xyz(float xangle, float yangle, float zangle) SHZ_NOEXCEPT
Initializes and returns a quaternion with the given X-Y-Z rotations in radians.
shz_quat_t shz_quat_conjugate(shz_quat_t quat) SHZ_NOEXCEPT
Returns the conjugate of the given quaternion.
shz_quat_t shz_quat_mult(shz_quat_t q1, shz_quat_t q2) SHZ_NOEXCEPT
Multiplies the two quaternions, returning the result as a new quaternion.
float shz_quat_angle_z(shz_quat_t q) SHZ_NOEXCEPT
Returns the angle of rotation the quaternion represents about the Z axis in radians.
shz_quat_t shz_quat_sub(shz_quat_t q, shz_quat_t p) SHZ_NOEXCEPT
Returns the quaternion produced from subtracting each component of quaternion p from quaterion q.
float shz_quat_angle_y(shz_quat_t q) SHZ_NOEXCEPT
Returns the angle of rotation the quaternion represents about the Y axis in radians.
float shz_invf(float x) SHZ_NOEXCEPT
Takes the inverse of x using a slighty faster approximation than doing a full division,...
C++ structure representing a quaternion.
Definition shz_quat.hpp:38
static quat nlerp(quat q, quat p, float t) noexcept
Equivalent to lerp(), except that the resulting quaternion is normalized.
Definition shz_quat.hpp:94
quat rotate_towards(shz_quat_t to, float max_angle) const noexcept
Rotates quaternion from towards quaternion to by at most max_angle radians.
Definition shz_quat.hpp:354
float angle() const noexcept
Returns the angle of rotation represented by the given quaternion.
Definition shz_quat.hpp:169
void negate() noexcept
Negates the components of the given quaternion.
Definition shz_quat.hpp:285
quat(const shz_quat_t &q) noexcept
C Converting constructor: constructs a C++ shz::quat from a C shz_quat_t.
Definition shz_quat.hpp:56
static quat identity() noexcept
Returns an identity quaternion.
Definition shz_quat.hpp:64
quat normalized_safe() const noexcept
Returns a safely normalized quaternion from the given quaternion, protecting against division-by-zero...
Definition shz_quat.hpp:250
quat mult(quat rhs) const noexcept
Returns a new quaterion from multiplying the given quaternion by another.
Definition shz_quat.hpp:332
quat operator/=(quat rhs) noexcept
Divides the given quaternion by rhs.
Definition shz_quat.hpp:393
quat add(quat rhs) const noexcept
Returns a new quaternion from adding the given quaterion to rhs.
Definition shz_quat.hpp:297
vec3 axis() const noexcept
Returns the axis of rotation represented by the given quaternion.
Definition shz_quat.hpp:174
quat(const volatile shz_quat_t &other) noexcept
Converting constructor from existing volatile C instance.
Definition shz_quat.hpp:60
float magnitude_inv() const noexcept
Returns the inverse of the magnitude of the quaternion.
Definition shz_quat.hpp:204
quat div(quat rhs) const noexcept
Returns a new quaterion from dividing the given quaternion by another (or multiplying the given quate...
Definition shz_quat.hpp:337
static quat from_rotated_axis(vec3 start, vec3 end) noexcept
Returns the quaternion representing the rotation from the start to the end axes.
Definition shz_quat.hpp:84
vec3 transform(vec3 in) const noexcept
Returns a new shz::vec3 from transforming in by the given quaternion.
Definition shz_quat.hpp:366
static quat squad(quat q1, quat q2, quat s1, quat s2, float t) noexcept
Evaluates the smooth cubic spherical interpolation (SQUAD) at parameter t.
Definition shz_quat.hpp:104
auto to_axis_angle() const noexcept -> std::pair< vec3, float >
Returns both the axis and angle of rotation as a std::pair.
Definition shz_quat.hpp:226
quat(const quat &other) noexcept=default
Default copy constructor.
void conjugate() noexcept
Conjugates the given quaternion.
Definition shz_quat.hpp:265
float dot(quat other) const noexcept
Returns the dot product between the given quaternion and another.
Definition shz_quat.hpp:317
static quat from_axis_angle(vec3 axis, float angle) noexcept
Initializes a quaternion which is a rotation in angle radians about the given axis.
Definition shz_quat.hpp:74
quat negated() const noexcept
Returns a new quaternion whose components are the negated values of the given quaternion.
Definition shz_quat.hpp:280
float angle_y() const noexcept
Returns the angle of rotation about the Y axis represented by the given quaternion.
Definition shz_quat.hpp:184
quat operator+=(quat rhs) noexcept
Adds and accumulates rhs onto the given quaternion.
Definition shz_quat.hpp:378
quat scaled(float s) const noexcept
Returns a new quaternion from scaling the given quaterion by s.
Definition shz_quat.hpp:307
static quat slerp(quat q, quat p, float t) noexcept
Returns the quaternion that is spherically linearly interpolating q to p, by a t factor of 0....
Definition shz_quat.hpp:99
quat operator/=(float rhs) noexcept
Divides each component of the given quaternion by rhs.
Definition shz_quat.hpp:404
vec3 dot(quat q1, quat q2, quat q3) const noexcept
Returns the dot product of the given quaternion against three others.
Definition shz_quat.hpp:327
void invert() noexcept
Inverts the given quaternion.
Definition shz_quat.hpp:275
vec3 to_angles_xyz() const noexcept
Returns the tait-bryan rotation angles about the X, Y, then Z axes which are represented by the given...
Definition shz_quat.hpp:216
void normalize() noexcept
Normalizes the given quaternion.
Definition shz_quat.hpp:245
friend bool operator==(quat lhs, quat rhs) noexcept
Overloaded comparison operator, checks for quaternion equality.
Definition shz_quat.hpp:151
quat conjugated() const noexcept
Returns a quaternion that is the conjugate of the given quaternion.
Definition shz_quat.hpp:260
static quat lerp(quat q, quat p, float t) noexcept
Returns the quaternion that is linearly interpolating q to p, by a t factor of 0.0f-1....
Definition shz_quat.hpp:89
quat operator-() const noexcept
Overloaded unary negation operator, returns the negation of the given quaternion.
Definition shz_quat.hpp:373
float magnitude() const noexcept
Returns the magnitude of the quaternion.
Definition shz_quat.hpp:199
volatile quat & operator=(volatile shz_quat_t other) volatile noexcept
Overloaded operator for assigning volatile reference to base C type.
Definition shz_quat.hpp:156
quat operator*=(quat rhs) noexcept
Multiplies and accumulates rhs into the given quaternion.
Definition shz_quat.hpp:388
quat() noexcept=default
Default constructor: does nothing.
quat normalized() const noexcept
Returns the given quaternion as a unit quaternion.
Definition shz_quat.hpp:240
float angle_x() const noexcept
Returns the angle of rotation about the X axis represented by the given quaternion.
Definition shz_quat.hpp:179
quat sub(quat rhs) const noexcept
Returns a new quaternion from adding rhs from the given quaternion.
Definition shz_quat.hpp:302
float magnitude_sqr() const noexcept
Returns the magnitude of the quaternion squared.
Definition shz_quat.hpp:194
quat operator-=(quat rhs) noexcept
Subtracts rhs from the given quaternion.
Definition shz_quat.hpp:383
static quat from_angles_xyz(float x, float y, float z) noexcept
C++ convenience wrapper for shz_quat_from_angles_xyz().
Definition shz_quat.hpp:69
quat inverse() const noexcept
Returns the inverse of the given quaternion.
Definition shz_quat.hpp:270
quat(float w, float x, float y, float z) noexcept
Value constructor: initializes a quaternion with the given values for each component.
Definition shz_quat.hpp:52
void scale(float s) noexcept
Multiplies each component of the given quaternion by s.
Definition shz_quat.hpp:312
void normalize_safe() noexcept
Safely normalizes the given quaternion by protecting against division-by-zero.
Definition shz_quat.hpp:255
static quat from_look_axis(vec3 forward, vec3 up) noexcept
Creates a quaternion looking in the given direction with the given reference direction.
Definition shz_quat.hpp:79
void to_axis_angle(shz_vec3_t *axis, float *angle) const noexcept
Returns both the axis and angle of rotation through the pointer arguments.
Definition shz_quat.hpp:221
quat operator*=(float rhs) noexcept
Multiplies and accumulates each component of the given quaternion by rhs.
Definition shz_quat.hpp:398
float angle_between(quat p) const noexcept
Returns the angle in radians between the rotations represented by quaternions q and p.
Definition shz_quat.hpp:349
vec2 dot(quat q1, quat q2) const noexcept
Returns the dot product of the given quaternion against two others.
Definition shz_quat.hpp:322
float angle_z() const noexcept
Returns the angle of rotation about the Z axis represented by the given quaternion.
Definition shz_quat.hpp:189
2D Vector type
3D Vector type