2
3
4
5
6
7
8
9
10
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 struct quat:
public shz_quat_t {
43
44
45
51 SHZ_FORCE_INLINE
quat(
float w,
float x,
float y,
float z)
noexcept:
52 shz_quat_t({w, x, y, z}) {}
55 SHZ_FORCE_INLINE
quat(shz_quat_t q)
noexcept:
70 return shz_quat_from_axis_angle(axis, angle);
75 return shz_quat_from_look_axis(forward, up);
80 return shz_quat_from_rotated_axis(start, end);
108
109
110
130
131
132
153
154
155
158 SHZ_FORCE_INLINE
float angle()
const noexcept {
168 SHZ_FORCE_INLINE
float angle_x()
const noexcept {
173 SHZ_FORCE_INLINE
float angle_y()
const noexcept {
178 SHZ_FORCE_INLINE
float angle_z()
const noexcept {
200
201
202
210 SHZ_FORCE_INLINE
void to_axis_angle(shz_vec3_t* axis,
float* angle)
const noexcept {
216 std::pair<
vec3,
float> aa;
217 shz_quat_to_axis_angle(*
this, &std::get<0>(aa), &std::get<1>(aa));
224
225
226
264 SHZ_FORCE_INLINE
void invert()
noexcept {
274 SHZ_FORCE_INLINE
void negate()
noexcept {
281
282
283
301 SHZ_FORCE_INLINE
void scale(
float s)
noexcept {
306 SHZ_FORCE_INLINE
float dot(
quat other)
const noexcept {
333
334
335
350
351
352
356 return shz_quat_transform_vec3(*
this, in);
368 return *
this =
add(rhs
);
373 return *
this =
sub(rhs
);
383 return *
this =
div(rhs
);
Namespace enclosing the SH4ZAM C++ API.
quat operator*(quat lhs, float rhs) noexcept
Overloaded operator for scaling each component of lhs by rhs and returning the result.
quat operator/(quat lhs, float rhs) noexcept
Overloaded operator for dividing each element of lhs by rhs and returning the result.
quat operator/(quat lhs, quat rhs) noexcept
Overloaded operator for dividing lhs by rhs (or multiplying by the reciprocal of rhs) and returning t...
quat operator*(quat lhs, quat rhs) noexcept
Overloaded operator for multiplying two quaternions and returning the result.
quat operator-(quat lhs, quat rhs) noexcept
Overloaded operator for subtracting two quaternions and returning the result.
vec3 operator*(quat lhs, vec3 rhs) noexcept
Overloaded operator for transforming/rotating a vec3, rhs, by a quaternion, lhs.
quat operator*(float lhs, quat rhs) noexcept
Overloaded operator for scaling each component of rhs by lhs and returning the result.
quat operator/(float lhs, quat rhs) noexcept
Overloaded operator for dividing each component of rhs by lhs.
quat operator+(quat lhs, quat rhs) noexcept
Overloaded operator for adding two quaternions and returning the result.
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...
#define SHZ_QUAT_SLERP_PHI_EPSILON
Minimum epsilon below which shz_quat_slerp() performs no interpolation.
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.
static quat nlerp(quat q, quat p, float t) noexcept
Equivalent to lerp(), except that the resulting quaternion is normalized.
quat rotate_towards(shz_quat_t to, float max_angle) const noexcept
Rotates quaternion from towards quaternion to by at most max_angle radians.
float angle() const noexcept
Returns the angle of rotation represented by the given quaternion.
void negate() noexcept
Negates the components of the given quaternion.
static quat identity() noexcept
Returns an identity quaternion.
quat normalized_safe() const noexcept
Returns a safely normalized quaternion from the given quaternion, protecting against division-by-zero...
quat mult(quat rhs) const noexcept
Returns a new quaterion from multiplying the given quaternion by another.
quat operator/=(quat rhs) noexcept
Divides the given quaternion by rhs.
quat(shz_quat_t q) noexcept
C Converting constructor: constructs a C++ shz::quat from a C shz_quat_t.
quat add(quat rhs) const noexcept
Returns a new quaternion from adding the given quaterion to rhs.
vec3 axis() const noexcept
Returns the axis of rotation represented by the given quaternion.
float magnitude_inv() const noexcept
Returns the inverse of the magnitude of the quaternion.
quat div(quat rhs) const noexcept
Returns a new quaterion from dividing the given quaternion by another (or multiplying the given quate...
static quat from_rotated_axis(vec3 start, vec3 end) noexcept
Returns the quaternion representing the rotation from the start to the end axes.
vec3 transform(vec3 in) const noexcept
Returns a new shz::vec3 from transforming in by the given quaternion.
static quat squad(quat q1, quat q2, quat s1, quat s2, float t) noexcept
Evaluates the smooth cubic spherical interpolation (SQUAD) at parameter t.
auto to_axis_angle() const noexcept -> std::pair< vec3, float >
Returns both the axis and angle of rotation as a std::pair.
void conjugate() noexcept
Conjugates the given quaternion.
static constexpr float slerp_phi_epsilon
Minimum epsilon for bothering to interpolate in shz::quat::slerp().
float dot(quat other) const noexcept
Returns the dot product between the given quaternion and another.
static quat from_axis_angle(vec3 axis, float angle) noexcept
Initializes a quaternion which is a rotation in angle radians about the given axis.
quat negated() const noexcept
Returns a new quaternion whose components are the negated values of the given quaternion.
float angle_y() const noexcept
Returns the angle of rotation about the Y axis represented by the given quaternion.
quat operator+=(quat rhs) noexcept
Adds and accumulates rhs onto the given quaternion.
quat scaled(float s) const noexcept
Returns a new quaternion from scaling the given quaterion by s.
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....
quat operator/=(float rhs) noexcept
Divides each component of the given quaternion by rhs.
vec3 dot(quat q1, quat q2, quat q3) const noexcept
Returns the dot product of the given quaternion against three others.
void invert() noexcept
Inverts the given quaternion.
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...
void normalize() noexcept
Normalizes the given quaternion.
friend bool operator==(quat lhs, quat rhs) noexcept
Overloaded comparison operator, checks for quaternion equality.
quat conjugated() const noexcept
Returns a quaternion that is the conjugate of the given quaternion.
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....
quat operator-() const noexcept
Overloaded unary negation operator, returns the negation of the given quaternion.
float magnitude() const noexcept
Returns the magnitude of the quaternion.
quat operator*=(quat rhs) noexcept
Multiplies and accumulates rhs into the given quaternion.
quat() noexcept=default
Default constructor: does nothing.
quat normalized() const noexcept
Returns the given quaternion as a unit quaternion.
float angle_x() const noexcept
Returns the angle of rotation about the X axis represented by the given quaternion.
quat sub(quat rhs) const noexcept
Returns a new quaternion from adding rhs from the given quaternion.
float magnitude_sqr() const noexcept
Returns the magnitude of the quaternion squared.
quat operator-=(quat rhs) noexcept
Subtracts rhs from the given quaternion.
static quat from_angles_xyz(float x, float y, float z) noexcept
C++ convenience wrapper for shz_quat_from_angles_xyz().
quat inverse() const noexcept
Returns the inverse of the given quaternion.
quat(float w, float x, float y, float z) noexcept
Value constructor: initializes a quaternion with the given values for each component.
void scale(float s) noexcept
Multiplies each component of the given quaternion by s.
void normalize_safe() noexcept
Safely normalizes the given quaternion by protecting against division-by-zero.
static quat from_look_axis(vec3 forward, vec3 up) noexcept
Creates a quaternion looking in the given direction with the given reference direction.
void to_axis_angle(shz_vec3_t *axis, float *angle) const noexcept
Returns both the axis and angle of rotation through the pointer arguments.
quat operator*=(float rhs) noexcept
Multiplies and accumulates each component of the given quaternion by rhs.
float angle_between(quat p) const noexcept
Returns the angle in radians between the rotations represented by quaternions q and p.
vec2 dot(quat q1, quat q2) const noexcept
Returns the dot product of the given quaternion against two others.
float angle_z() const noexcept
Returns the angle of rotation about the Z axis represented by the given quaternion.