A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
EGG::Quatf Struct Reference

#include <Quat.hh>

Description

A quaternion, used to represent 3D rotation.

A quaternion is comprised of a scalar (w) and a vector (v). The vector is used to represent the axis of rotation, while the scalar is used to represent the amount of rotation.

Definition at line 12 of file Quat.hh.

Public Member Functions

constexpr Quatf (const Quatf &q)=default
 
constexpr Quatf (f32 w_, const Vector3f &v_)
 
constexpr Quatf (f32 w_, f32 x_, f32 y_, f32 z_)
 
constexpr Quatfoperator= (const Quatf &q)
 
constexpr Quatf operator+ (const Quatf &rhs) const
 
constexpr Quatfoperator+= (const Quatf &rhs)
 
constexpr Quatf operator* (const Vector3f &vec) const
 
constexpr Quatf operator* (f32 scalar) const
 
constexpr Quatfoperator*= (f32 scalar)
 
constexpr Quatf operator* (const Quatf &rhs) const
 
constexpr Quatfoperator*= (const Quatf &q)
 
constexpr bool operator== (const Quatf &rhs) const
 
constexpr bool operator!= (const Quatf &rhs) const
 
 operator std::string () const
 A conversion function that allows for string representation of a quaternion.
 
constexpr void setRPY (const Vector3f &rpy)
 Sets roll, pitch, and yaw.
 
constexpr void setRPY (f32 r, f32 p, f32 y)
 Helper function to avoid unnecessary Vector3f construction.
 
constexpr void normalise ()
 Scales the quaternion to a unit length.
 
constexpr void makeVectorRotation (const Vector3f &from, const Vector3f &to)
 Captures rotation between two vectors.
 
constexpr Quatf conjugate () const
 Computes \(conj(a+bi+cj+dk) = a-bi-cj-dk\).
 
constexpr Vector3f rotateVector (const Vector3f &vec) const
 Rotates a vector based on the quat.
 
constexpr Vector3f rotateVectorInv (const Vector3f &vec) const
 Rotates a vector on the inverse quat.
 
constexpr Quatf slerpTo (const Quatf &q1, f32 t) const
 Performs spherical linear interpolation.
 
constexpr f32 squaredNorm () const
 Computes \(this \cdot this = w^2 + x^2 + y^2 + z^2\).
 
constexpr f32 norm () const
 
constexpr f32 dot (const Quatf &q) const
 Computes \(this \cdot rhs = w \times rhs.w + x \times rhs.x + y \times rhs.y + z \times rhs.z\).
 
constexpr void setAxisRotation (f32 angle, const EGG::Vector3f &axis)
 Set the quat given angle and axis.
 
constexpr Quatf multSwap (const Vector3f &vec) const
 
constexpr Quatf multSwap (const Quatf &q) const
 
void read (Stream &stream)
 

Static Public Member Functions

static constexpr Quatf FromRPY (const EGG::Vector3f &rpy)
 
static constexpr Quatf FromRPY (f32 r, f32 p, f32 y)
 Helper function to avoid unnecessary Vector3f construction.
 

Public Attributes

Vector3f v
 
f32 w
 

Static Public Attributes

static const Quatf ident = Quatf(1.0f, Vector3f::zero)
 

Constructor & Destructor Documentation

◆ Quatf() [1/2]

EGG::Quatf::Quatf ( f32 w_,
const Vector3f & v_ )
inlineconstexpr

Definition at line 19 of file Quat.hh.

◆ Quatf() [2/2]

EGG::Quatf::Quatf ( f32 w_,
f32 x_,
f32 y_,
f32 z_ )
inlineconstexpr

Definition at line 20 of file Quat.hh.

Member Function Documentation

◆ conjugate()

Quatf EGG::Quatf::conjugate ( ) const
inlinenodiscardconstexpr

Computes \(conj(a+bi+cj+dk) = a-bi-cj-dk\).

Definition at line 130 of file Quat.hh.

◆ dot()

f32 EGG::Quatf::dot ( const Quatf & q) const
inlinenodiscardconstexpr

Computes \(this \cdot rhs = w \times rhs.w + x \times rhs.x + y \times rhs.y + z \times rhs.z\).

Definition at line 202 of file Quat.hh.

◆ FromRPY() [1/2]

static constexpr Quatf EGG::Quatf::FromRPY ( const EGG::Vector3f & rpy)
inlinestaticnodiscardconstexpr

Definition at line 240 of file Quat.hh.

◆ FromRPY() [2/2]

static constexpr Quatf EGG::Quatf::FromRPY ( f32 r,
f32 p,
f32 y )
inlinestaticnodiscardconstexpr

Helper function to avoid unnecessary Vector3f construction.

Definition at line 247 of file Quat.hh.

◆ makeVectorRotation()

void EGG::Quatf::makeVectorRotation ( const Vector3f & from,
const Vector3f & to )
inlineconstexpr0x8023A788

Captures rotation between two vectors.

Definition at line 116 of file Quat.hh.

◆ multSwap() [1/2]

Quatf EGG::Quatf::multSwap ( const Quatf & q) const
inlinenodiscardconstexpr

Definition at line 226 of file Quat.hh.

◆ multSwap() [2/2]

Quatf EGG::Quatf::multSwap ( const Vector3f & vec) const
inlinenodiscardconstexpr

Definition at line 217 of file Quat.hh.

◆ norm()

f32 EGG::Quatf::norm ( ) const
inlinenodiscardconstexpr

Definition at line 196 of file Quat.hh.

◆ normalise()

void EGG::Quatf::normalise ( )
inlineconstexpr0x8023A168

Scales the quaternion to a unit length.

Definition at line 104 of file Quat.hh.

◆ operator std::string()

EGG::Quatf::operator std::string ( ) const
inlineexplicitnodiscard

A conversion function that allows for string representation of a quaternion.

Definition at line 76 of file Quat.hh.

◆ operator!=()

bool EGG::Quatf::operator!= ( const Quatf & rhs) const
inlinenodiscardconstexpr

Definition at line 71 of file Quat.hh.

◆ operator*() [1/3]

Quatf EGG::Quatf::operator* ( const Quatf & rhs) const
inlinenodiscardconstexpr

Though part of this is a vector cross/dot product, FP arithmetic is not associative or commutative. It has to be done in this order.

Definition at line 54 of file Quat.hh.

◆ operator*() [2/3]

Quatf EGG::Quatf::operator* ( const Vector3f & vec) const
inlinenodiscardconstexpr

Definition at line 38 of file Quat.hh.

◆ operator*() [3/3]

Quatf EGG::Quatf::operator* ( f32 scalar) const
inlinenodiscardconstexpr

Definition at line 44 of file Quat.hh.

◆ operator*=() [1/2]

Quatf & EGG::Quatf::operator*= ( const Quatf & q)
inlineconstexpr

Definition at line 63 of file Quat.hh.

◆ operator*=() [2/2]

Quatf & EGG::Quatf::operator*= ( f32 scalar)
inlineconstexpr

Definition at line 48 of file Quat.hh.

◆ operator+()

Quatf EGG::Quatf::operator+ ( const Quatf & rhs) const
inlinenodiscardconstexpr

Definition at line 30 of file Quat.hh.

◆ operator+=()

Quatf & EGG::Quatf::operator+= ( const Quatf & rhs)
inlineconstexpr

Definition at line 34 of file Quat.hh.

◆ operator=()

Quatf & EGG::Quatf::operator= ( const Quatf & q)
inlineconstexpr

Definition at line 23 of file Quat.hh.

◆ operator==()

bool EGG::Quatf::operator== ( const Quatf & rhs) const
inlinenodiscardconstexpr

Definition at line 67 of file Quat.hh.

◆ read()

void EGG::Quatf::read ( Stream & stream)
inline

Definition at line 235 of file Quat.hh.

◆ rotateVector()

Vector3f EGG::Quatf::rotateVector ( const Vector3f & vec) const
inlinenodiscardconstexpr0x8023A2D0

Rotates a vector based on the quat.

Definition at line 136 of file Quat.hh.

◆ rotateVectorInv()

Vector3f EGG::Quatf::rotateVectorInv ( const Vector3f & vec) const
inlinenodiscardconstexpr0x8023A404

Rotates a vector on the inverse quat.

Definition at line 150 of file Quat.hh.

◆ setAxisRotation()

void EGG::Quatf::setAxisRotation ( f32 angle,
const EGG::Vector3f & axis )
inlineconstexpr0x8023A0A0

Set the quat given angle and axis.

Definition at line 208 of file Quat.hh.

◆ setRPY() [1/2]

void EGG::Quatf::setRPY ( const Vector3f & rpy)
inlineconstexpr0x80239E10

Sets roll, pitch, and yaw.

Definition at line 83 of file Quat.hh.

◆ setRPY() [2/2]

void EGG::Quatf::setRPY ( f32 r,
f32 p,
f32 y )
inlineconstexpr

Helper function to avoid unnecessary Vector3f construction.

Definition at line 88 of file Quat.hh.

◆ slerpTo()

Quatf EGG::Quatf::slerpTo ( const Quatf & q1,
f32 t ) const
inlinenodiscardconstexpr0x8023A5C4

Performs spherical linear interpolation.

Slerp is a method in which you can create smooth rotations between two quaternions.

Definition at line 165 of file Quat.hh.

◆ squaredNorm()

f32 EGG::Quatf::squaredNorm ( ) const
inlinenodiscardconstexpr0x8023A138

Computes \(this \cdot this = w^2 + x^2 + y^2 + z^2\).

Definition at line 192 of file Quat.hh.

Member Data Documentation

◆ ident

Quatf EGG::Quatf::ident = Quatf(1.0f, Vector3f::zero)
inlinestaticconstexpr

Definition at line 256 of file Quat.hh.

◆ v

Vector3f EGG::Quatf::v

Definition at line 253 of file Quat.hh.

◆ w

f32 EGG::Quatf::w

Definition at line 254 of file Quat.hh.