Raven Engine v0.1
A modern 3D Game Engine
Loading...
Searching...
No Matches
Crux::Quat< T > Struct Template Reference

Templated quaternion representation. More...

#include <Quaternion.h>

Public Member Functions

constexpr Quat () noexcept
 Construct identity quaternion.
constexpr Quat (T ix, T jy, T kz, T _w) noexcept
 Construct from explicit components.
constexpr Quat (const Vector< T, 3 > &v, T real) noexcept
 Construct from a 3D vector (imaginary part) and a real scalar.
constexpr Quat (const T comps[4]) noexcept
 Construct from a plain C-style array of 4 scalars.
constexpr Vector< T, 3 > imag () const noexcept
 Return the imaginary (vector) part as Vector<T,3>.
constexpr T real () const noexcept
 Return the real (scalar) component.
constexpr T & operator[] (size_t idx) noexcept
 Mutable indexed access to components.
constexpr const T & operator[] (size_t idx) const noexcept
 Const indexed access to components.
constexpr Quat operator- () const noexcept
 Return the negated quaternion.
constexpr Quat operator* (T s) const noexcept
 Multiply quaternion components by a scalar.
constexpr Quat operator+ (const Quat &o) const noexcept
 Component-wise addition.
constexpr Quat operator- (const Quat &o) const noexcept
 Component-wise subtraction.
constexpr Quatset (T ix, T iy, T iz, T iw) noexcept
 Set components directly.
constexpr QuatsetImag (const Vector< T, 3 > &v) noexcept
 Set imaginary part from a Vector<T,3>.

Public Attributes

x
 Imaginary i component (x).
y
 Imaginary j component (y).
z
 Imaginary k component (z).
w
 Real component (w).

Detailed Description

template<typename T>
struct Crux::Quat< T >

Templated quaternion representation.

Template Parameters
TScalar numeric type (f32, double, etc.)
Storage layout
The components are stored as:
  • x, y, z; the vector (imaginary) part
  • w; the scalar (real) part

This layout matches common engine conventions where a quaternion is represented as (x, y, z, w) and is compatible with copy/memcpy semantics.

Default Value
Default construction yields the identity quaternion (no rotation): {0, 0, 0, 1}.
Notes on usage
Prefer normalized quaternions for rotation semantics. Many operations in this assume or recommend normalization (unit-length) for numerical stability.

Constructor & Destructor Documentation

◆ Quat() [1/4]

template<typename T>
Crux::Quat< T >::Quat ( )
inlineconstexprnoexcept

Construct identity quaternion.

Note
Identity quaternion represents no rotation.

◆ Quat() [2/4]

template<typename T>
Crux::Quat< T >::Quat ( T ix,
T jy,
T kz,
T _w )
inlineconstexprnoexcept

Construct from explicit components.

Parameters
ixImaginary x component.
jyImaginary y component.
kzImaginary z component.
_wReal component.

◆ Quat() [3/4]

template<typename T>
Crux::Quat< T >::Quat ( const Vector< T, 3 > & v,
T real )
inlineexplicitconstexprnoexcept

Construct from a 3D vector (imaginary part) and a real scalar.

Parameters
v3D vector representing imaginary components.
realThe real (w) component.

◆ Quat() [4/4]

template<typename T>
Crux::Quat< T >::Quat ( const T comps[4])
inlineconstexprnoexcept

Construct from a plain C-style array of 4 scalars.

Parameters
compsArray of 4 elements in order {x, y, z, w}.
Note
No copying overhead beyond the field assignments. Useful for interop with binary formats or packed buffers.

Member Function Documentation

◆ imag()

template<typename T>
Vector< T, 3 > Crux::Quat< T >::imag ( ) const
inlineconstexprnoexcept

Return the imaginary (vector) part as Vector<T,3>.

Returns
Vector<T,3> containing {x, y, z}.
Note
The returned vector is a copy; use this for convenience when a Vector representation is required for other vector algebra helpers.

◆ operator*()

template<typename T>
Quat Crux::Quat< T >::operator* ( T s) const
inlineconstexprnoexcept

Multiply quaternion components by a scalar.

Element-wise scalar multiplication. Useful for scale-blending and intermediate operations; does not preserve unit-length unless scalar==1.

◆ operator+()

template<typename T>
Quat Crux::Quat< T >::operator+ ( const Quat< T > & o) const
inlineconstexprnoexcept

Component-wise addition.

Use with care — componentwise addition does not correspond to any simple composition of rotations. Primarily useful for linear interpolation and algebraic manipulations.

◆ operator-() [1/2]

template<typename T>
Quat Crux::Quat< T >::operator- ( ) const
inlineconstexprnoexcept

Return the negated quaternion.

Returns
Quat<T> with all components negated.
Note
Negating a quaternion represents the same rotation (q and -q are identical in rotation terms). Negation is useful when manipulating signs to ensure shortest-path slerp, etc.

◆ operator-() [2/2]

template<typename T>
Quat Crux::Quat< T >::operator- ( const Quat< T > & o) const
inlineconstexprnoexcept

Component-wise subtraction.

◆ operator[]() [1/2]

template<typename T>
const T & Crux::Quat< T >::operator[] ( size_t idx) const
inlineconstexprnoexcept

Const indexed access to components.

Parameters
idxIndex in [0..3] mapping to {x, y, z, w} respectively.
Returns
Const reference to selected component.
Warning
No bounds checking for speed. Caller must ensure idx < 4.

◆ operator[]() [2/2]

template<typename T>
T & Crux::Quat< T >::operator[] ( size_t idx)
inlineconstexprnoexcept

Mutable indexed access to components.

Parameters
idxIndex in [0..3] mapping to {x, y, z, w} respectively.
Returns
Reference to selected component.
Warning
No bounds checking for speed. Caller must ensure idx < 4.

◆ real()

template<typename T>
T Crux::Quat< T >::real ( ) const
inlineconstexprnoexcept

Return the real (scalar) component.

Returns
Real scalar w.

◆ set()

template<typename T>
Quat & Crux::Quat< T >::set ( T ix,
T iy,
T iz,
T iw )
inlineconstexprnoexcept

Set components directly.

Parameters
ixx component.
iyy component.
izz component.
iww component.
Returns
Reference to *this for chaining.

◆ setImag()

template<typename T>
Quat & Crux::Quat< T >::setImag ( const Vector< T, 3 > & v)
inlineconstexprnoexcept

Set imaginary part from a Vector<T,3>.

Parameters
vVector containing {x,y,z}.
Returns
Reference to *this for chaining.

Member Data Documentation

◆ w

template<typename T>
T Crux::Quat< T >::w

Real component (w).

◆ x

template<typename T>
T Crux::Quat< T >::x

Imaginary i component (x).

◆ y

template<typename T>
T Crux::Quat< T >::y

Imaginary j component (y).

◆ z

template<typename T>
T Crux::Quat< T >::z

Imaginary k component (z).


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