SH4ZAM! 0.1.0
Fast math library for the Sega Dreamcast's SH4 CPU
Loading...
Searching...
No Matches
shz::quat Struct Reference

#include <shz_quat.hpp>

Inheritance diagram for shz::quat:
Collaboration diagram for shz::quat:

Public Member Functions

 quat () noexcept=default
 
 quat (float w, float x, float y, float z) noexcept
 
 quat (shz_quat_t q) noexcept
 
float angle () const noexcept
 
vec3 axis () const noexcept
 
float angle_x () const noexcept
 
float angle_y () const noexcept
 
float angle_z () const noexcept
 
vec3 to_angles_xyz () const noexcept
 
void to_axis_angle (shz_vec3_t *axis, float *angle) const noexcept
 
auto to_axis_angle () const noexcept -> std::pair< vec3, float >
 
float magnitude_sqr () const noexcept
 
float magnitude () const noexcept
 
float magnitude_inv () const noexcept
 
void normalize () noexcept
 
quat normalized () const noexcept
 
void normalize_safe () noexcept
 
quat normalized_safe () const noexcept
 
void conjugate () noexcept
 
quat conjugated () const noexcept
 
void invert () noexcept
 
quat inverse () const noexcept
 
quat add (quat rhs) const noexcept
 
quat scale (float s) const noexcept
 
float dot (quat other) const noexcept
 
vec2 dot (quat q1, quat q2) const noexcept
 
vec3 dot (quat q1, quat q2, quat q3) const noexcept
 
quat mult (quat rhs) const noexcept
 
vec3 transform (vec3 in) const noexcept
 

Static Public Member Functions

static quat identity () noexcept
 
static quat from_angles_xyz (float x, float y, float z) noexcept
 
static quat from_axis_angle (vec3 axis, float angle) noexcept
 
static quat from_look_axis (vec3 forward, vec3 up) noexcept
 
static quat from_rotated_axis (vec3 start, vec3 end) noexcept
 
static quat lerp (quat q, quat p, float t) noexcept
 
static quat nlerp (quat q, quat p, float t) noexcept
 
static quat slerp (quat q, quat p, float t) noexcept
 

Static Public Attributes

static constexpr float slerp_phi_epsilon
 

Friends

auto operator== (quat lhs, quat rhs) noexcept
 

Additional Inherited Members

- Data Fields inherited from shz_quat_t
union { 
 
   struct { 
 
      float   w 
 
      union { 
 
         struct { 
 
            float   x 
 
            float   y 
 
            float   z 
 
         }  
 
         shz_vec3_t   axis 
 
      }  
 
   }  
 
   float   e [4] 
 
};  
 

Detailed Description

C++ structure representing a quaternion.

A quaternion represents a rotation about an arbitrary axis in 3D space.

Warning
The SH4ZAM internal quaternion representatino puts the W or angle component first, followed by the X, Y, Z components for the axis!
Note
shz::quat is the C++ extension of shz_quat_t, which adds member functions, convenience operators, and still retains backwards compatibility with the C API.
See also
shz_quat_t, shz::mat4x4, shz::vec3

Definition at line 38 of file shz_quat.hpp.

Constructor & Destructor Documentation

◆ quat() [1/3]

shz::quat::quat ( )
defaultnoexcept

Default constructor: does nothing.

◆ quat() [2/3]

shz::quat::quat ( float w,
float x,
float y,
float z )
inlinenoexcept

Value constructor: initializes a quaternion with the given values for each component.

Definition at line 46 of file shz_quat.hpp.

46 :
47 shz_quat_t({w, x, y, z}) {}
float z
Z component of axis of rotation (imaginary)
Definition shz_quat.h:47
float w
< Anonymous structure with named components.
Definition shz_quat.h:42
float y
Y component of axis of rotation (imaginary)
Definition shz_quat.h:46
float x
X component of axis of rotation (imaginary)
Definition shz_quat.h:45

◆ quat() [3/3]

shz::quat::quat ( shz_quat_t q)
inlinenoexcept

C Converting constructor: constructs a C++ shz::quat from a C shz_quat_t.

Definition at line 50 of file shz_quat.hpp.

50 :
51 shz_quat_t(q) {}

Member Function Documentation

◆ identity()

static quat shz::quat::identity ( )
inlinestaticnoexcept

Returns an identity quaternion.

Definition at line 54 of file shz_quat.hpp.

54 {
55 return shz_quat_identity();
56 }
shz_quat_t shz_quat_identity(void) SHZ_NOEXCEPT
Initializes and returns an identity quaternion.

◆ from_angles_xyz()

static quat shz::quat::from_angles_xyz ( float x,
float y,
float z )
inlinestaticnoexcept

C++ convenience wrapper for shz_quat_From_angles_xyz().

Definition at line 59 of file shz_quat.hpp.

59 {
60 return shz_quat_from_angles_xyz(x, y, z);
61 }
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.

◆ from_axis_angle()

static quat shz::quat::from_axis_angle ( vec3 axis,
float angle )
inlinestaticnoexcept

initializes a quaternion which is a rotation in angle degrees about the given axis.

Definition at line 64 of file shz_quat.hpp.

64 {
66 }
shz_quat_t shz_quat_from_axis_angle(shz_vec3_t axis, float angle) SHZ_NOEXCEPT
Initializes and returns a quaternion representing a rotation of angle radians about the given axis.
float angle() const noexcept
Returns the angle of rotation represented by the given quaternion.
Definition shz_quat.hpp:130
vec3 axis() const noexcept
Returns the axis of rotation represented by the given quaternion.
Definition shz_quat.hpp:135

◆ from_look_axis()

static quat shz::quat::from_look_axis ( vec3 forward,
vec3 up )
inlinestaticnoexcept

Creates a quaternion looking in the given direction with the given reference direction.

Definition at line 69 of file shz_quat.hpp.

69 {
70 return shz_quat_from_look_axis(forward, up);
71 }
shz_quat_t shz_quat_from_look_axis(shz_vec3_t forward, shz_vec3_t up) SHZ_NOEXCEPT
Creates a quaternion looking in the given direction with the given reference direction.

◆ from_rotated_axis()

static quat shz::quat::from_rotated_axis ( vec3 start,
vec3 end )
inlinestaticnoexcept

Returns the quaternion representing the rotation from the start to the end axes.

Definition at line 74 of file shz_quat.hpp.

74 {
75 return shz_quat_from_rotated_axis(start, end);
76 }
shz_quat_t shz_quat_from_rotated_axis(shz_vec3_t v1, shz_vec3_t v2) SHZ_NOEXCEPT
Returns the quaternion representing the rotation from axis v1 to v2.

◆ lerp()

static quat shz::quat::lerp ( quat q,
quat p,
float t )
inlinestaticnoexcept

Returns the quaternion that is linearly interpolating q to p, by a t factor of 0.0f-1.0f.

Definition at line 79 of file shz_quat.hpp.

79 {
80 return shz_quat_lerp(q, p, t);
81 }
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....

◆ nlerp()

static quat shz::quat::nlerp ( quat q,
quat p,
float t )
inlinestaticnoexcept

Equivalent to lerp(), except that the resulting quaternion is normalized.

Definition at line 84 of file shz_quat.hpp.

84 {
85 return shz_quat_nlerp(q, p, t);
86 }
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.

◆ slerp()

static quat shz::quat::slerp ( quat q,
quat p,
float t )
inlinestaticnoexcept

Returns the quaternion that is spherically linearly interpolating q to p, by a t factor of 0.0f-1.0f.

Warning
The returned quaternion is not guaranteed to be normalized due to floating-point error. Callers should normalize the result before reuse, especially when performing repeated interpolations.

Definition at line 93 of file shz_quat.hpp.

93 {
94 return shz_quat_slerp(q, p, t);
95 }
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....

◆ angle()

float shz::quat::angle ( ) const
inlinenoexcept

Returns the angle of rotation represented by the given quaternion.

Definition at line 130 of file shz_quat.hpp.

130 {
131 return shz_quat_angle(*this);
132 }
float shz_quat_angle(shz_quat_t q) SHZ_NOEXCEPT
Returns the angle of rotation from the given quaternion.

◆ axis()

vec3 shz::quat::axis ( ) const
inlinenoexcept

Returns the axis of rotation represented by the given quaternion.

Definition at line 135 of file shz_quat.hpp.

135 {
136 return shz_quat_axis(*this);
137 }
shz_vec3_t shz_quat_axis(shz_quat_t q) SHZ_NOEXCEPT
Returns the axis of rotation from the given quaternion.

◆ angle_x()

float shz::quat::angle_x ( ) const
inlinenoexcept

Returns the angle of rotation about the X axis represented by the given quaternion.

Definition at line 140 of file shz_quat.hpp.

140 {
141 return shz_quat_angle_x(*this);
142 }

◆ angle_y()

float shz::quat::angle_y ( ) const
inlinenoexcept

Returns the angle of rotation about the Y axis represented by the given quaternion.

Definition at line 145 of file shz_quat.hpp.

145 {
146 return shz_quat_angle_y(*this);
147 }

◆ angle_z()

float shz::quat::angle_z ( ) const
inlinenoexcept

Returns the angle of rotation about the Z axis represented by the given quaternion.

Definition at line 150 of file shz_quat.hpp.

150 {
151 return shz_quat_angle_z(*this);
152 }

◆ to_angles_xyz()

vec3 shz::quat::to_angles_xyz ( ) const
inlinenoexcept

Definition at line 154 of file shz_quat.hpp.

154 {
155 return shz_quat_to_angles_xyz(*this);
156 }
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.

◆ to_axis_angle() [1/2]

void shz::quat::to_axis_angle ( shz_vec3_t * axis,
float * angle ) const
inlinenoexcept

Returns both the axis and angle of rotation through the pointer arguments.

Definition at line 159 of file shz_quat.hpp.

159 {
161 }
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...

◆ to_axis_angle() [2/2]

auto shz::quat::to_axis_angle ( ) const -> std::pair<vec3, float>
inlinenoexcept

Returns both the axis and angle of rotation as a std::pair.

Definition at line 164 of file shz_quat.hpp.

164 {
165 std::pair<vec3, float> aa;
166 shz_quat_to_axis_angle(*this, &std::get<0>(aa), &std::get<1>(aa));
167 return aa;
168 }

◆ magnitude_sqr()

float shz::quat::magnitude_sqr ( ) const
inlinenoexcept

Returns the magnitude of the quaternion squared.

Definition at line 171 of file shz_quat.hpp.

171 {
172 return shz_quat_magnitude_sqr(*this);
173 }
float shz_quat_magnitude_sqr(shz_quat_t quat) SHZ_NOEXCEPT
Returns the squared magnitude of the given quaternion.

◆ magnitude()

float shz::quat::magnitude ( ) const
inlinenoexcept

Returns the magnitude of the quaternion.

Definition at line 176 of file shz_quat.hpp.

176 {
177 return shz_quat_magnitude(*this);
178 }
float shz_quat_magnitude(shz_quat_t quat) SHZ_NOEXCEPT
Returns the magnitude of the given quaternion.

◆ magnitude_inv()

float shz::quat::magnitude_inv ( ) const
inlinenoexcept

Returns the inverse of the magnitude of the quaternion.

Definition at line 181 of file shz_quat.hpp.

181 {
182 return shz_quat_magnitude_inv(*this);
183 }
float shz_quat_magnitude_inv(shz_quat_t quat) SHZ_NOEXCEPT
Returns the inverse magnitude of the given quaternion.

◆ normalize()

void shz::quat::normalize ( )
inlinenoexcept

Normalizes the given quaternion.

Definition at line 186 of file shz_quat.hpp.

186 {
187 *this = shz_quat_normalize(*this);
188 }
shz_quat_t shz_quat_normalize(shz_quat_t quat) SHZ_NOEXCEPT
Returns the normalized form of the given quaternion.

◆ normalized()

quat shz::quat::normalized ( ) const
inlinenoexcept

Returns the given quaternion as a unit quaternion.

Definition at line 191 of file shz_quat.hpp.

191 {
192 return shz_quat_normalize(*this);
193 }

◆ normalize_safe()

void shz::quat::normalize_safe ( )
inlinenoexcept

Safely normalizes the given quaternion by protecting against division-by-zero.

Definition at line 196 of file shz_quat.hpp.

196 {
197 *this = shz_quat_normalize_safe(*this);
198 }
shz_quat_t shz_quat_normalize_safe(shz_quat_t quat) SHZ_NOEXCEPT
SAFELY returns the normalized form of the given quaternion.

◆ normalized_safe()

quat shz::quat::normalized_safe ( ) const
inlinenoexcept

Returns a safely normalized quaternion from the given quaternion, protecting against division-by-zero.

Definition at line 201 of file shz_quat.hpp.

201 {
202 return shz_quat_normalize_safe(*this);
203 }

◆ conjugate()

void shz::quat::conjugate ( )
inlinenoexcept

Conjugates the given quaternion.

Definition at line 206 of file shz_quat.hpp.

206 {
207 *this = shz_quat_conjugate(*this);
208 }
shz_quat_t shz_quat_conjugate(shz_quat_t quat) SHZ_NOEXCEPT
Returns the conjugate of the given quaternion.

◆ conjugated()

quat shz::quat::conjugated ( ) const
inlinenoexcept

Returns a quaternion that is the conjugate of the given quaternion.

Definition at line 211 of file shz_quat.hpp.

211 {
212 return shz_quat_conjugate(*this);
213 }

◆ invert()

void shz::quat::invert ( )
inlinenoexcept

Inverts the given quaternion.

Definition at line 216 of file shz_quat.hpp.

216 {
217 *this = shz_quat_inv(*this);
218 }
shz_quat_t shz_quat_inv(shz_quat_t quat) SHZ_NOEXCEPT
Returns the inverse of the given quaternion.

◆ inverse()

quat shz::quat::inverse ( ) const
inlinenoexcept

Returns the inverse of the given quaternion.

Definition at line 221 of file shz_quat.hpp.

221 {
222 return shz_quat_inv(*this);
223 }

◆ add()

quat shz::quat::add ( quat rhs) const
inlinenoexcept

Returns a new quaternion from adding the given quaterion to rhs.

Definition at line 226 of file shz_quat.hpp.

226 {
227 return shz_quat_add(*this, rhs);
228 }
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.

◆ scale()

quat shz::quat::scale ( float s) const
inlinenoexcept

Returns a new quaternion from scaling the given quaterion by s.

Definition at line 231 of file shz_quat.hpp.

231 {
232 return shz_quat_scale(*this, s);
233 }
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.

◆ dot() [1/3]

float shz::quat::dot ( quat other) const
inlinenoexcept

Returns the dot product between the given quaternion and another.

Definition at line 236 of file shz_quat.hpp.

236 {
237 return shz_quat_dot(*this, other);
238 }
float shz_quat_dot(shz_quat_t q1, shz_quat_t q2) SHZ_NOEXCEPT
Returns the dot product of the two quaternions.

◆ dot() [2/3]

vec2 shz::quat::dot ( quat q1,
quat q2 ) const
inlinenoexcept

Returns the dot product of the given quaternion against two others.

Definition at line 241 of file shz_quat.hpp.

241 {
242 return shz_quat_dot2(*this, q1, q2);
243 }
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.

◆ dot() [3/3]

vec3 shz::quat::dot ( quat q1,
quat q2,
quat q3 ) const
inlinenoexcept

Returns the dot product of the given quaternion against three others.

Definition at line 246 of file shz_quat.hpp.

246 {
247 return shz_quat_dot3(*this, q1, q2, q3);
248 }
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.

◆ mult()

quat shz::quat::mult ( quat rhs) const
inlinenoexcept

Returns a new quaterion from multiplying the given quaternion by another.

Definition at line 251 of file shz_quat.hpp.

251 {
252 return shz_quat_mult(*this, rhs);
253 }
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.

◆ transform()

vec3 shz::quat::transform ( vec3 in) const
inlinenoexcept

Returns a new shz::vec3 from transforming in by the given quaternion.

Definition at line 256 of file shz_quat.hpp.

256 {
257 return shz_quat_transform_vec3(*this, in);
258 }
shz_vec3_t shz_quat_transform_vec3(shz_quat_t q, shz_vec3_t v) SHZ_NOEXCEPT
Rotates a vector by the given quaternion.

Friends And Related Symbol Documentation

◆ operator==

auto operator== ( quat lhs,
quat rhs )
friend

Overloaded comparison operator, checks for quaternion equality.

Definition at line 125 of file shz_quat.hpp.

125 {
126 return shz_quat_equal(lhs, rhs);
127 }
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...

Field Documentation

◆ slerp_phi_epsilon

float shz::quat::slerp_phi_epsilon
staticconstexpr

Minimum epsilon for bothering to interpolate in shz::quat::slerp().

Definition at line 40 of file shz_quat.hpp.


The documentation for this struct was generated from the following file: