Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::Quaternion Class Reference

Represents a rotation using (x, y, z, w) and offers common conversions. More...

#include <spk_quaternion.hpp>

Collaboration diagram for spk::Quaternion:
Collaboration graph

Public Member Functions

 Quaternion ()
 Builds an identity quaternion.
 Quaternion (float p_x, float p_y, float p_z, float p_w)
 Builds from components.
std::wstring toWstring () const
 Converts the quaternion to a wide string.
std::string toString () const
 Converts the quaternion to a string.
Vector3 toEuler () const
 Converts to Euler angles in degrees.
Quaternion normalize () const
 Returns a normalized copy.
Quaternion operator* (const Quaternion &p_rhs) const
 Concatenates two rotations.
Vector3 operator* (const Vector3 &p_rhs) const
 Rotates a vector by this quaternion.
Vector3 rotate (const Vector3 &p_v) const
 Rotates a vector by this quaternion.

Static Public Member Functions

static Quaternion identity ()
 Returns the identity quaternion.
static Quaternion fromEuler (const Vector3 &p_euler)
 Builds from Euler angles in degrees.
static Quaternion fromAxisAngle (const Vector3 &p_axis, float p_angle)
 Builds from axis and angle in degrees.
static Quaternion lookAt (const Vector3 &p_eye, const Vector3 &p_target, const Vector3 &p_up)
 Builds a quaternion looking from eye to target with an up vector.

Public Attributes

float x
 X component of the quaternion vector part.
float y
 Y component of the quaternion vector part.
float z
 Z component of the quaternion vector part.
float w
 W component representing the scalar part.

Friends

std::wostream & operator<< (std::wostream &p_os, const Quaternion &p_vec)
 Streams the quaternion to a wide output stream.
std::ostream & operator<< (std::ostream &p_os, const Quaternion &p_vec)
 Streams the quaternion to a narrow output stream.

Detailed Description

Represents a rotation using (x, y, z, w) and offers common conversions.

See also
Vector3
spk::Vector3 rotated = q.rotate({1.f, 0.f, 0.f});
Represents a rotation using (x, y, z, w) and offers common conversions.
Definition spk_quaternion.hpp:19
Vector3 rotate(const Vector3 &p_v) const
Rotates a vector by this quaternion.
Definition spk_quaternion.cpp:154
static Quaternion fromEuler(const Vector3 &p_euler)
Builds from Euler angles in degrees.
Definition spk_quaternion.cpp:43

Constructor & Destructor Documentation

◆ Quaternion()

spk::Quaternion::Quaternion ( float p_x,
float p_y,
float p_z,
float p_w )

Builds from components.

Parameters
p_xX component.
p_yY component.
p_zZ component.
p_wW component.

Member Function Documentation

◆ fromAxisAngle()

Quaternion spk::Quaternion::fromAxisAngle ( const Vector3 & p_axis,
float p_angle )
static

Builds from axis and angle in degrees.

Parameters
p_axisNormalized axis.
p_angleAngle in degrees.
Returns
Quaternion representing the axis-angle rotation.
Here is the call graph for this function:

◆ fromEuler()

Quaternion spk::Quaternion::fromEuler ( const Vector3 & p_euler)
static

Builds from Euler angles in degrees.

Parameters
p_eulerPitch/Yaw/Roll in degrees.
Returns
Quaternion representing the rotation.
Here is the call graph for this function:

◆ identity()

Quaternion spk::Quaternion::identity ( )
static

Returns the identity quaternion.

Returns
Quaternion with vector part zero and scalar part one.
Here is the call graph for this function:

◆ lookAt()

Quaternion spk::Quaternion::lookAt ( const Vector3 & p_eye,
const Vector3 & p_target,
const Vector3 & p_up )
static

Builds a quaternion looking from eye to target with an up vector.

Parameters
p_eyeEye position.
p_targetTarget position.
p_upUp direction.
Returns
Quaternion aligning forward to the target.
Here is the call graph for this function:

◆ normalize()

Quaternion spk::Quaternion::normalize ( ) const

Returns a normalized copy.

Returns
Unit-length quaternion pointing in the same direction.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator*() [1/2]

Quaternion spk::Quaternion::operator* ( const Quaternion & p_rhs) const

Concatenates two rotations.

Parameters
p_rhsRight-hand quaternion.
Returns
Combined rotation.
Here is the call graph for this function:

◆ operator*() [2/2]

Vector3 spk::Quaternion::operator* ( const Vector3 & p_rhs) const

Rotates a vector by this quaternion.

Parameters
p_rhsVector to rotate.
Returns
Rotated vector.
Here is the call graph for this function:

◆ rotate()

Vector3 spk::Quaternion::rotate ( const Vector3 & p_v) const

Rotates a vector by this quaternion.

Parameters
p_vVector to rotate.
Returns
Rotated vector.

◆ toEuler()

Vector3 spk::Quaternion::toEuler ( ) const

Converts to Euler angles in degrees.

Returns
Pitch/Yaw/Roll.
Here is the call graph for this function:

◆ toString()

std::string spk::Quaternion::toString ( ) const

Converts the quaternion to a string.

Returns
Components in (x, y, z, w) format.

◆ toWstring()

std::wstring spk::Quaternion::toWstring ( ) const

Converts the quaternion to a wide string.

Returns
Components in (x, y, z, w) wide format.

◆ operator<< [1/2]

std::ostream & operator<< ( std::ostream & p_os,
const Quaternion & p_vec )
friend

Streams the quaternion to a narrow output stream.

Parameters
p_osDestination stream.
p_vecQuaternion to print.
Returns
Stream reference after write.

◆ operator<< [2/2]

std::wostream & operator<< ( std::wostream & p_os,
const Quaternion & p_vec )
friend

Streams the quaternion to a wide output stream.

Parameters
p_osDestination stream.
p_vecQuaternion to print.
Returns
Stream reference after write.

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