API Documentation
Public Member Functions | Public Attributes | List of all members
nkMaths::Quaternion Class Reference

A quaternion, symbolizing rotations as a 4D vector. More...

Public Member Functions

 Quaternion () noexcept
 
 Quaternion (float x, float y, float z, float w) noexcept
 
 Quaternion (const Vector &axis, float angle) noexcept
 
 Quaternion (const Vector &eulerAngles) noexcept
 
 Quaternion (const Matrix &mat) noexcept
 
 Quaternion (const Quaternion &other) noexcept
 
Vector getAsEulerAngles () const
 
Vector getAsAxisAngle () const
 
QuaternionsetFromAxisAngle (const Vector &axis, float angle)
 
QuaternionsetFromEuler (const Vector &angles)
 
QuaternionsetFromOrientationMatrix (const Matrix &mat)
 
QuaternionsetFromTransformationMatrix (const Matrix &mat)
 
Vector transform (const Vector &vector) const
 
Vectorapply (Vector &vector) const
 
nkMemory::String toString () const
 
QuaternionfromString (nkMemory::StringView str)
 
Quaternionoperator= (const Quaternion &other) noexcept
 
Vector operator* (const Vector &other) const
 
Quaternion operator* (const Quaternion &other) const
 
void operator*= (const Quaternion &other)
 
bool operator== (const Quaternion &other) const
 

Public Attributes

float _x
 X component of the quaternion.
 
float _y
 Y component of the quaternion.
 
float _z
 Z component of the quaternion.
 
float _w
 W component of the quaternion.
 

Detailed Description

A quaternion, symbolizing rotations as a 4D vector.

The equation for the quaternion is considered as : xi + yj + zk + w.

Constructor & Destructor Documentation

◆ Quaternion() [1/6]

nkMaths::Quaternion::Quaternion ( )
noexcept

Default constructor. Defaults to (0, 0, 0, 1), encoding no rotation.

◆ Quaternion() [2/6]

nkMaths::Quaternion::Quaternion ( float  x,
float  y,
float  z,
float  w 
)
noexcept

Filling constructor.

Parameters
xThe x component.
yThe y component.
zThe z component.
wThe w component.

◆ Quaternion() [3/6]

nkMaths::Quaternion::Quaternion ( const Vector axis,
float  angle 
)
noexcept

Axis angle constructor.

Parameters
axisThe axis of rotation to consider.
angleThe angle around this axis, in radians.

◆ Quaternion() [4/6]

nkMaths::Quaternion::Quaternion ( const Vector eulerAngles)
noexcept

Euler angles constructor.

Parameters
eulerAnglesThe euler angles, considering rotation in ZYX (Yaw-Pitch-Roll) order.

◆ Quaternion() [5/6]

nkMaths::Quaternion::Quaternion ( const Matrix mat)
noexcept

Matrix constructor.

Parameters
matThe matrix from which to extract the rotation.

◆ Quaternion() [6/6]

nkMaths::Quaternion::Quaternion ( const Quaternion other)
noexcept

Copy constructor.

Parameters
otherThe quaternion to copy.

Member Function Documentation

◆ getAsEulerAngles()

Vector nkMaths::Quaternion::getAsEulerAngles ( ) const
Returns
The quaternion translated as euler angles, encoded with ZYX ordering (Yaw-Pitch-Roll).

◆ getAsAxisAngle()

Vector nkMaths::Quaternion::getAsAxisAngle ( ) const
Returns
The quaternion translated as an axis angle vector (xyz axis, w angle in radians).

◆ setFromAxisAngle()

Quaternion& nkMaths::Quaternion::setFromAxisAngle ( const Vector axis,
float  angle 
)

Sets the quaternion from an axis and angle pair.

Parameters
axisThe axis to rotate around.
angleThe angle to rotate, in radians.
Returns
Reference over caller.

◆ setFromEuler()

Quaternion& nkMaths::Quaternion::setFromEuler ( const Vector angles)

Sets the quaternion from euler angles.

Parameters
anglesThe euler angles to translate, considering rotation in ZYX (Yaw-Pitch-Roll) order.
Returns
Reference over caller.

◆ setFromOrientationMatrix()

Quaternion& nkMaths::Quaternion::setFromOrientationMatrix ( const Matrix mat)

Sets the quaternion from a rotation matrix.

Parameters
matThe matrix to extract the rotation from.
Returns
Reference over caller.

◆ setFromTransformationMatrix()

Quaternion& nkMaths::Quaternion::setFromTransformationMatrix ( const Matrix mat)

Sets the quaternion from a full transformation matrix.

Parameters
matThe matrix to extract the rotation from.
Returns
Reference over caller.

◆ transform()

Vector nkMaths::Quaternion::transform ( const Vector vector) const

Rotates a vector, by copying it and returning it. Another way to express q * v.

Parameters
vectorThe vector to rotate.
Returns
The vector once rotated.

◆ apply()

Vector& nkMaths::Quaternion::apply ( Vector vector) const

Rotates a vector, by altering the vector parameter. Another way to express q *= v.

Parameters
vectorThe vector to rotate.
Returns
The vector given, once rotated.

◆ toString()

nkMemory::String nkMaths::Quaternion::toString ( ) const
Returns
The quaternion expressed as a string, formatted as "x, y, z, w".

◆ fromString()

Quaternion& nkMaths::Quaternion::fromString ( nkMemory::StringView  str)

Parse components from a string. Format is "x,y,z,w".

Parameters
strThe string to parse.
Returns
The updated quaternion instance.

◆ operator=()

Quaternion& nkMaths::Quaternion::operator= ( const Quaternion other)
noexcept

Assignment operator.

Parameters
otherThe quaternion to assign.

◆ operator*() [1/2]

Vector nkMaths::Quaternion::operator* ( const Vector other) const

Multiplication operator.

Parameters
otherThe vector to apply the quaternion to.
Returns
The vector, rotated by the quaternion.

◆ operator*() [2/2]

Quaternion nkMaths::Quaternion::operator* ( const Quaternion other) const

Multiplication operator.

Parameters
otherThe quaternion to multiply with.
Returns
A quaternion being the result of the multiplication of both quaternions.

◆ operator*=()

void nkMaths::Quaternion::operator*= ( const Quaternion other)

Multiplication and assignment operator.

Parameters
otherThe quaternion to multiply with.

◆ operator==()

bool nkMaths::Quaternion::operator== ( const Quaternion other) const

Comparison operator.

Parameters
otherThe quaternion to compare with.
Returns
Whether the quaternions have the same component values (true) or not (false).

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