MinGfx Toolkit  1.0
A minimal library for writing cross-platform (Windows, OSX, linux) graphics programs.
Public Member Functions | Static Public Member Functions | List of all members
mingfx::Quaternion Class Reference

Detailed Description

A quaternion to represent rotations in 3D space.

The main use of quaternions within the library is to support smooth interpolation between rotations, since this is not possible using Euler angles or rotation matrices. The class includes a Slerp routine for spherical interpolation between rotations. Example use:

// find a rotation 1/2 way between r1 and r2, both originally expressed in Euler angles
Vector3 euler1 = GfxMath::ToRadians(Vector3(0,0,60));
Vector3 euler2 = GfxMath::ToRadians(Vector3(45,45,60));
float alpha = 0.5;
Quaternion q_half_way = q1.Slerp(q2, alpha);
Vector3 new_euler_angles = GfxMath::ToDegrees(q_half_way.ToEulerAnglesZYX());
static float ToRadians(float degrees)
static float ToDegrees(float radians)
static Quaternion FromEulerAnglesZYX(const Vector3 &angles)
Creates a new quaternion from a rotation defined in Euler angles.
Quaternion()
Creates a quat with the identity rotation.

Definition at line 41 of file quaternion.h.

#include <quaternion.h>

Public Member Functions

 Quaternion ()
 Creates a quat with the identity rotation. More...
 
 Quaternion (float qx, float qy, float qz, float qw)
 Creates a quat from the 4 parameters. More...
 
 Quaternion (float *ptr)
 Creates a quate from a pointer to 4 floating point numbers in the order qx, qy, qz, qw. More...
 
 Quaternion (const Quaternion &other)
 Copy constructor. More...
 
virtual ~Quaternion ()
 
bool operator== (const Quaternion &q) const
 Check for "equality", taking floating point imprecision into account. More...
 
bool operator!= (const Quaternion &q) const
 Check for "inequality", taking floating point imprecision into account. More...
 
Quaternionoperator= (const Quaternion &q)
 Assignment operator. More...
 
float operator[] (const int i) const
 Read only access to the ith coordinate of the quaternion (qx, qy, qz, qw). More...
 
float & operator[] (const int i)
 Writable access the ith coordinate of the quaternion (qx, qy, qz, qw). More...
 
float x () const
 Read only access to the x coordinate of the imaginary part of the quaternion. More...
 
float y () const
 Read only access to the y coordinate of the imaginary part of the quaternion. More...
 
float z () const
 Read only access to the z coordinate of the imaginary part of the quaternion. More...
 
float w () const
 Read only access to the w, real part, of the quaternion. More...
 
const float * value_ptr () const
 Returns a const pointer to the raw data array, stored in the order qx, qy, qz, qw. More...
 
float Dot (const Quaternion &q) const
 Returns the dot product of this quaternion with another. More...
 
float Length () const
 Returns the length of the quaternion. More...
 
void Normalize ()
 Normalizes the quat by making it unit length. More...
 
Quaternion ToUnit () const
 Returns a normalized (i.e., unit length) version of the quaternion without modifying the original. More...
 
Quaternion Conjugate () const
 Returns the conjugate of the quaternion. More...
 
Vector3 ToEulerAnglesZYX () const
 Converts the rotation specified by the quaternion into Euler angles. More...
 
Quaternion Slerp (const Quaternion &other, float alpha) const
 Uses spherical interpolation to interpoloate between the rotation stored in this quaternion and the rotation stored in another. More...
 

Static Public Member Functions

static Quaternion FromAxisAngle (const Vector3 &axis, float angle)
 Creates a new quaternion that describes a rotation by angle radians about. More...
 
static Quaternion FromEulerAnglesZYX (const Vector3 &angles)
 Creates a new quaternion from a rotation defined in Euler angles. More...
 
static Quaternion Slerp (const Quaternion &a, const Quaternion &b, float alpha)
 Uses spherical interpolation to interpoloate between the rotations specified by two quaternions. More...
 

Constructor & Destructor Documentation

◆ Quaternion() [1/4]

mingfx::Quaternion::Quaternion ( )

Creates a quat with the identity rotation.

◆ Quaternion() [2/4]

mingfx::Quaternion::Quaternion ( float  qx,
float  qy,
float  qz,
float  qw 
)

Creates a quat from the 4 parameters.

◆ Quaternion() [3/4]

mingfx::Quaternion::Quaternion ( float *  ptr)

Creates a quate from a pointer to 4 floating point numbers in the order qx, qy, qz, qw.

◆ Quaternion() [4/4]

mingfx::Quaternion::Quaternion ( const Quaternion other)

Copy constructor.

◆ ~Quaternion()

virtual mingfx::Quaternion::~Quaternion ( )
virtual

Member Function Documentation

◆ Conjugate()

Quaternion mingfx::Quaternion::Conjugate ( ) const

Returns the conjugate of the quaternion.

◆ Dot()

float mingfx::Quaternion::Dot ( const Quaternion q) const

Returns the dot product of this quaternion with another.

◆ FromAxisAngle()

static Quaternion mingfx::Quaternion::FromAxisAngle ( const Vector3 axis,
float  angle 
)
static

Creates a new quaternion that describes a rotation by angle radians about.

◆ FromEulerAnglesZYX()

static Quaternion mingfx::Quaternion::FromEulerAnglesZYX ( const Vector3 angles)
static

Creates a new quaternion from a rotation defined in Euler angles.

◆ Length()

float mingfx::Quaternion::Length ( ) const

Returns the length of the quaternion.

◆ Normalize()

void mingfx::Quaternion::Normalize ( )

Normalizes the quat by making it unit length.

◆ operator!=()

bool mingfx::Quaternion::operator!= ( const Quaternion q) const

Check for "inequality", taking floating point imprecision into account.

◆ operator=()

Quaternion& mingfx::Quaternion::operator= ( const Quaternion q)

Assignment operator.

◆ operator==()

bool mingfx::Quaternion::operator== ( const Quaternion q) const

Check for "equality", taking floating point imprecision into account.

◆ operator[]() [1/2]

float& mingfx::Quaternion::operator[] ( const int  i)

Writable access the ith coordinate of the quaternion (qx, qy, qz, qw).

◆ operator[]() [2/2]

float mingfx::Quaternion::operator[] ( const int  i) const

Read only access to the ith coordinate of the quaternion (qx, qy, qz, qw).

◆ Slerp() [1/2]

static Quaternion mingfx::Quaternion::Slerp ( const Quaternion a,
const Quaternion b,
float  alpha 
)
static

Uses spherical interpolation to interpoloate between the rotations specified by two quaternions.

◆ Slerp() [2/2]

Quaternion mingfx::Quaternion::Slerp ( const Quaternion other,
float  alpha 
) const

Uses spherical interpolation to interpoloate between the rotation stored in this quaternion and the rotation stored in another.

◆ ToEulerAnglesZYX()

Vector3 mingfx::Quaternion::ToEulerAnglesZYX ( ) const

Converts the rotation specified by the quaternion into Euler angles.

◆ ToUnit()

Quaternion mingfx::Quaternion::ToUnit ( ) const

Returns a normalized (i.e., unit length) version of the quaternion without modifying the original.

◆ value_ptr()

const float* mingfx::Quaternion::value_ptr ( ) const

Returns a const pointer to the raw data array, stored in the order qx, qy, qz, qw.

◆ w()

float mingfx::Quaternion::w ( ) const
inline

Read only access to the w, real part, of the quaternion.

Definition at line 83 of file quaternion.h.

◆ x()

float mingfx::Quaternion::x ( ) const
inline

Read only access to the x coordinate of the imaginary part of the quaternion.

Definition at line 74 of file quaternion.h.

◆ y()

float mingfx::Quaternion::y ( ) const
inline

Read only access to the y coordinate of the imaginary part of the quaternion.

Definition at line 77 of file quaternion.h.

◆ z()

float mingfx::Quaternion::z ( ) const
inline

Read only access to the z coordinate of the imaginary part of the quaternion.

Definition at line 80 of file quaternion.h.


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