Ogre::Quaternion Class Reference
Core » Math

Implementation of a Quaternion, i.e. More...

`#include <OgreQuaternion.h>`

## Public Member Functions

| Quaternion ()
| Default constructor, initializes to identity rotation (aka 0°) More...
| Quaternion (Real fW, Real fX, Real fY, Real fZ)
| Construct from an explicit list of values. More...
| Quaternion (const Matrix3 &rot)
| Construct a quaternion from a rotation matrix. More...
| Quaternion (const Radian &rfAngle, const Vector3 &rkAxis)
| Construct a quaternion from an angle/axis. More...
| Quaternion (const Vector3 &xaxis, const Vector3 &yaxis, const Vector3 &zaxis)
| Construct a quaternion from 3 orthonormal local axes. More...
| Quaternion (const Vector3 *akAxis)
| Construct a quaternion from 3 orthonormal local axes. More...
| Quaternion (Real *valptr)
| Construct a quaternion from 4 manual w/x/y/z values. More...
Real | Dot (const Quaternion &rkQ) const
| Returns the dot product of the quaternion. More...
bool | equals (const Quaternion &rhs, const Radian &tolerance) const
| Equality with tolerance (tolerance is max angle difference) More...
Quaternion | Exp () const
| Apply to unit-length quaternion. More...
void | FromAngleAxis (const Radian &rfAngle, const Vector3 &rkAxis)
| Setups the quaternion using the supplied vector, and "roll" around that vector by the specified radians. More...
void | FromAxes (const Vector3 *akAxis)
| Constructs the quaternion using 3 axes, the axes are assumed to be orthonormal. More...
void | FromAxes (const Vector3 &xAxis, const Vector3 &yAxis, const Vector3 &zAxis)
void | FromRotationMatrix (const Matrix3 &kRot)
Radian | getPitch (bool reprojectAxis=true) const
| Calculate the local pitch element of this quaternion. More...
Radian | getRoll (bool reprojectAxis=true) const
| Calculate the local roll element of this quaternion. More...
Radian | getYaw (bool reprojectAxis=true) const
| Calculate the local yaw element of this quaternion. More...
Quaternion | Inverse () const
bool | isNaN () const
| Check whether this quaternion contains valid values. More...
Quaternion | Log () const
Real | Norm () const
Real | normalise (void)
| Normalises this quaternion, and returns the previous length. More...
bool | operator!= (const Quaternion &rhs) const
Quaternion | operator* (const Quaternion &rkQ) const
Quaternion | operator* (Real fScalar) const
Vector3 | operator* (const Vector3 &rkVector) const
| Rotation of a vector by a quaternion. More...
Quaternion | operator+ (const Quaternion &rkQ) const
Quaternion | operator- (const Quaternion &rkQ) const
Quaternion | operator- () const
Quaternion & | operator= (const Quaternion &rkQ)
bool | operator== (const Quaternion &rhs) const
Real | operator[] (const size_t i) const
| Array accessor operator. More...
Real & | operator[] (const size_t i)
| Array accessor operator. More...
Real * | ptr ()
| Pointer accessor for direct copying. More...
const Real * | ptr () const
| Pointer accessor for direct copying. More...
void | swap (Quaternion &other)
| Exchange the contents of this quaternion with another. More...
void | ToAngleAxis (Radian &rfAngle, Vector3 &rkAxis) const
void | ToAngleAxis (Degree &dAngle, Vector3 &rkAxis) const
void | ToAxes (Vector3 *akAxis) const
| Gets the 3 orthonormal axes defining the quaternion. More...
void | ToAxes (Vector3 &xAxis, Vector3 &yAxis, Vector3 &zAxis) const
void | ToRotationMatrix (Matrix3 &kRot) const
Quaternion | UnitInverse () const
| Apply to non-zero quaternion. More...
Vector3 | xAxis (void) const
| Returns the X orthonormal axis defining the quaternion. More...
Vector3 | yAxis (void) const
| Returns the Y orthonormal axis defining the quaternion. More...
Vector3 | zAxis (void) const
| Returns the Z orthonormal axis defining the quaternion. More...

## Static Public Member Functions

static void | Intermediate (const Quaternion &rkQ0, const Quaternion &rkQ1, const Quaternion &rkQ2, Quaternion &rka, Quaternion &rkB)
| Setup for spherical quadratic interpolation. More...
static Quaternion | nlerp (Real fT, const Quaternion &rkP, const Quaternion &rkQ, bool shortestPath=false)
| Performs Normalised linear interpolation between two quaternions, and returns the result. More...
static Quaternion | Slerp (Real fT, const Quaternion &rkP, const Quaternion &rkQ, bool shortestPath=false)
| Performs Spherical linear interpolation between two quaternions, and returns the result. More...
static Quaternion | SlerpExtraSpins (Real fT, const Quaternion &rkP, const Quaternion &rkQ, int iExtraSpins)
static Quaternion | Squad (Real fT, const Quaternion &rkP, const Quaternion &rkA, const Quaternion &rkB, const Quaternion &rkQ, bool shortestPath=false)
| Spherical quadratic interpolation. More...

## Public Attributes

Real | w
Real | x
Real | y
Real | z

## Static Public Attributes

static const Quaternion | IDENTITY
static const Real | msEpsilon
| Cutoff for sine near zero. More...
static const Quaternion | ZERO

## Friends

_OgreExport friend Quaternion | operator* (Real fScalar, const Quaternion &rkQ)
_OgreExport friend std::ostream & | operator<< (std::ostream &o, const Quaternion &q)
| Function for writing to a stream. More...

## Detailed Description

Implementation of a Quaternion, i.e.

a rotation around an axis. For more information about Quaternions and the theory behind it, we recommend reading: http://www.ogre3d.org/tikiwiki/Quaternion+and+Rotation+Primer http://www.cprogramming.com/tutorial/3d/quaternions.html http://www.gamedev.net/page/resources/_/reference/programming/math-and-physics/ quaternions/quaternion-powers-r1095

Definition at line 57 of file OgreQuaternion.h.

## Constructor & Destructor Documentation

## Quaternion() [1/7]

Ogre::Quaternion::Quaternion | ( |  | ) |

Default constructor, initializes to identity rotation (aka 0°)

Definition at line 61 of file OgreQuaternion.h.

## Quaternion() [2/7]

Ogre::Quaternion::Quaternion | ( | Real | fW,
|  | Real | fX,
|  | Real | fY,
|  | Real | fZ
| ) |  |

Construct from an explicit list of values.

Definition at line 66 of file OgreQuaternion.h.

## Quaternion() [3/7]

Ogre::Quaternion::Quaternion | ( | const Matrix3 & | rot | ) |

Construct a quaternion from a rotation matrix.

Definition at line 73 of file OgreQuaternion.h.

## Quaternion() [4/7]

Ogre::Quaternion::Quaternion | ( | const Radian & | rfAngle,
|  | const Vector3 & | rkAxis
| ) |  |

Construct a quaternion from an angle/axis.

Definition at line 78 of file OgreQuaternion.h.

## Quaternion() [5/7]

Ogre::Quaternion::Quaternion | ( | const Vector3 & | xaxis,
|  | const Vector3 & | yaxis,
|  | const Vector3 & | zaxis
| ) |  |

Construct a quaternion from 3 orthonormal local axes.

Definition at line 83 of file OgreQuaternion.h.

## Quaternion() [6/7]

Ogre::Quaternion::Quaternion | ( | const Vector3 * | akAxis | ) |

Construct a quaternion from 3 orthonormal local axes.

Definition at line 88 of file OgreQuaternion.h.

## Quaternion() [7/7]

Ogre::Quaternion::Quaternion | ( | Real * | valptr | ) |

Construct a quaternion from 4 manual w/x/y/z values.

Definition at line 93 of file OgreQuaternion.h.

## Member Function Documentation

## Dot()

Real Ogre::Quaternion::Dot | ( | const Quaternion & | rkQ | ) | const

Returns the dot product of the quaternion.

## equals()

bool Ogre::Quaternion::equals | ( | const Quaternion & | rhs,
|  | const Radian & | tolerance
| ) |  | const

Equality with tolerance (tolerance is max angle difference)

## Exp()

Quaternion Ogre::Quaternion::Exp | ( |  | ) | const

Apply to unit-length quaternion.

## FromAngleAxis()

void Ogre::Quaternion::FromAngleAxis | ( | const Radian & | rfAngle,
|  | const Vector3 & | rkAxis
| ) |  |

Setups the quaternion using the supplied vector, and "roll" around that vector by the specified radians.

Referenced by Ogre::Vector3::getRotationTo(), and Ogre::Vector3::randomDeviant().

## FromAxes() [1/2]

void Ogre::Quaternion::FromAxes | ( | const Vector3 * | akAxis | ) |

Constructs the quaternion using 3 axes, the axes are assumed to be orthonormal.

See also
  FromAxes

## FromAxes() [2/2]

void Ogre::Quaternion::FromAxes | ( | const Vector3 & | xAxis,
|  | const Vector3 & | yAxis,
|  | const Vector3 & | zAxis
| ) |  |

## FromRotationMatrix()

void Ogre::Quaternion::FromRotationMatrix | ( | const Matrix3 & | kRot | ) |

## getPitch()

Radian Ogre::Quaternion::getPitch | ( | bool | reprojectAxis = `true` | ) | const

Calculate the local pitch element of this quaternion.

Parameters

  reprojectAxis

  By default the method returns the 'intuitive' result that is, if you projected the local Z of the quaternion onto the X and Y axes, the angle between them is returned. If set to true though, the result is the actual yaw that will be used to implement the quaternion, which is the shortest possible path to get to the same orientation and may involve less axial rotation. The co-domain of the returned value is from -180 to 180 degrees.

## getRoll()

Radian Ogre::Quaternion::getRoll | ( | bool | reprojectAxis = `true` | ) | const

Calculate the local roll element of this quaternion.

Parameters

  reprojectAxis

  By default the method returns the 'intuitive' result that is, if you projected the local Y of the quaternion onto the X and Y axes, the angle between them is returned. If set to false though, the result is the actual yaw that will be used to implement the quaternion, which is the shortest possible path to get to the same orientation and may involve less axial rotation. The co-domain of the returned value is from -180 to 180 degrees.

## getYaw()

Radian Ogre::Quaternion::getYaw | ( | bool | reprojectAxis = `true` | ) | const

Calculate the local yaw element of this quaternion.

Parameters

  reprojectAxis

  By default the method returns the 'intuitive' result that is, if you projected the local Y of the quaternion onto the X and Z axes, the angle between them is returned. If set to true though, the result is the actual yaw that will be used to implement the quaternion, which is the shortest possible path to get to the same orientation and may involve less axial rotation. The co-domain of the returned value is from -180 to 180 degrees.

## Intermediate()

static void Ogre::Quaternion::Intermediate | ( | const Quaternion & | rkQ0,
|  | const Quaternion & | rkQ1,
|  | const Quaternion & | rkQ2,
|  | Quaternion & | rka,
|  | Quaternion & | rkB
| ) |  |

static

Setup for spherical quadratic interpolation.

## Inverse()

Quaternion Ogre::Quaternion::Inverse | ( |  | ) | const

## isNaN()

bool Ogre::Quaternion::isNaN | ( |  | ) | const

Check whether this quaternion contains valid values.

Definition at line 306 of file OgreQuaternion.h.

References _OgreExport, and Ogre::Math::isNaN().

## Log()

Quaternion Ogre::Quaternion::Log | ( |  | ) | const

## nlerp()

static Quaternion Ogre::Quaternion::nlerp | ( | Real | fT,
|  | const Quaternion & | rkP,
|  | const Quaternion & | rkQ,
|  | bool | shortestPath = `false`
| ) |  |

static

Performs Normalised linear interpolation between two quaternions, and returns the result.

nlerp ( 0.0f, A, B ) = A nlerp ( 1.0f, A, B ) = B

Remarks
  Nlerp is faster than Slerp. Nlerp has the proprieties of being commutative (

See also
  Slerp; commutativity is desired in certain places, like IK animation), and being torque-minimal (unless shortestPath=false). However, it's performing the interpolation at non-constant velocity; sometimes this is desired, sometimes it is not. Having a non-constant velocity can produce a more natural rotation feeling without the need of tweaking the weights; however if your scene relies on the timing of the rotation or assumes it will point at a specific angle at a specific weight value, Slerp is a better choice.

## Norm()

Real Ogre::Quaternion::Norm | ( |  | ) | const

## normalise()

Real Ogre::Quaternion::normalise | ( | void |  | ) |

Normalises this quaternion, and returns the previous length.

Referenced by Ogre::Vector3::getRotationTo().

## operator!=()

bool Ogre::Quaternion::operator!= | ( | const Quaternion & | rhs | ) | const

Definition at line 192 of file OgreQuaternion.h.

References Ogre::operator*(), and Ogre::operator==().

## operator*() [1/3]

Quaternion Ogre::Quaternion::operator* | ( | const Quaternion & | rkQ | ) | const

## operator*() [2/3]

Quaternion Ogre::Quaternion::operator* | ( | Real | fScalar | ) | const

## operator*() [3/3]

Vector3 Ogre::Quaternion::operator* | ( | const Vector3 & | rkVector | ) | const

Rotation of a vector by a quaternion.

## operator+()

Quaternion Ogre::Quaternion::operator+ | ( | const Quaternion & | rkQ | ) | const

## operator-() [1/2]

Quaternion Ogre::Quaternion::operator- | ( | const Quaternion & | rkQ | ) | const

## operator-() [2/2]

Quaternion Ogre::Quaternion::operator- | ( |  | ) | const

## operator=()

Quaternion& Ogre::Quaternion::operator= | ( | const Quaternion & | rkQ | ) |

Definition at line 172 of file OgreQuaternion.h.

References _OgreExport, Ogre::operator*(), w, x, y, and z.

## operator==()

bool Ogre::Quaternion::operator== | ( | const Quaternion & | rhs | ) | const

Definition at line 187 of file OgreQuaternion.h.

References w, x, y, and z.

## operator[]() [1/2]

Real Ogre::Quaternion::operator[] | ( | const size_t | i | ) | const

Array accessor operator.

Definition at line 109 of file OgreQuaternion.h.

## operator[]() [2/2]

Real& Ogre::Quaternion::operator[] | ( | const size_t | i | ) |

Array accessor operator.

Definition at line 117 of file OgreQuaternion.h.

## ptr() [1/2]

Real* Ogre::Quaternion::ptr | ( |  | ) |

Pointer accessor for direct copying.

Definition at line 125 of file OgreQuaternion.h.

Referenced by Ogre::AnimableValue::setAsBaseValue().

## ptr() [2/2]

const Real* Ogre::Quaternion::ptr | ( |  | ) | const

Pointer accessor for direct copying.

Definition at line 131 of file OgreQuaternion.h.

## Slerp()

static Quaternion Ogre::Quaternion::Slerp | ( | Real | fT,
|  | const Quaternion & | rkP,
|  | const Quaternion & | rkQ,
|  | bool | shortestPath = `false`
| ) |  |

static

Performs Spherical linear interpolation between two quaternions, and returns the result.

Slerp ( 0.0f, A, B ) = A Slerp ( 1.0f, A, B ) = B

Returns
  Interpolated quaternion

Remarks
  Slerp has the proprieties of performing the interpolation at constant velocity, and being torque-minimal (unless shortestPath=false). However, it's NOT commutative, which means Slerp ( 0.75f, A, B ) != Slerp ( 0.25f, B, A ); therefore be careful if your code relies in the order of the operands. This is specially important in IK animation.

## SlerpExtraSpins()

static Quaternion Ogre::Quaternion::SlerpExtraSpins | ( | Real | fT,
|  | const Quaternion & | rkP,
|  | const Quaternion & | rkQ,
|  | int | iExtraSpins
| ) |  |

static

See also
  Slerp. It adds extra "spins" (i.e. rotates several times) specified by parameter 'iExtraSpins' while interpolating before arriving to the final values

## Squad()

static Quaternion Ogre::Quaternion::Squad | ( | Real | fT,
|  | const Quaternion & | rkP,
|  | const Quaternion & | rkA,
|  | const Quaternion & | rkB,
|  | const Quaternion & | rkQ,
|  | bool | shortestPath = `false`
| ) |  |

static

Spherical quadratic interpolation.

## swap()

void Ogre::Quaternion::swap | ( | Quaternion & | other | ) |

Exchange the contents of this quaternion with another.

Definition at line 100 of file OgreQuaternion.h.

References std::swap(), w, x, y, and z.

## ToAngleAxis() [1/2]

void Ogre::Quaternion::ToAngleAxis | ( | Radian & | rfAngle,
|  | Vector3 & | rkAxis
| ) |  | const

## ToAngleAxis() [2/2]

void Ogre::Quaternion::ToAngleAxis | ( | Degree & | dAngle,
|  | Vector3 & | rkAxis
| ) |  | const

Definition at line 143 of file OgreQuaternion.h.

## ToAxes() [1/2]

void Ogre::Quaternion::ToAxes | ( | Vector3 * | akAxis | ) | const

Gets the 3 orthonormal axes defining the quaternion.

See also
  FromAxes

## ToAxes() [2/2]

void Ogre::Quaternion::ToAxes | ( | Vector3 & | xAxis,
|  | Vector3 & | yAxis,
|  | Vector3 & | zAxis
| ) |  | const

## ToRotationMatrix()

void Ogre::Quaternion::ToRotationMatrix | ( | Matrix3 & | kRot | ) | const

Referenced by Ogre::Matrix4::Matrix4().

## UnitInverse()

Quaternion Ogre::Quaternion::UnitInverse | ( |  | ) | const

Apply to non-zero quaternion.

## xAxis()

Vector3 Ogre::Quaternion::xAxis | ( | void |  | ) | const

Returns the X orthonormal axis defining the quaternion.

Same as doing xAxis = Vector3::UNIT_X * this. Also called the local X-axis

## yAxis()

Vector3 Ogre::Quaternion::yAxis | ( | void |  | ) | const

Returns the Y orthonormal axis defining the quaternion.

Same as doing yAxis = Vector3::UNIT_Y * this. Also called the local Y-axis

## zAxis()

Vector3 Ogre::Quaternion::zAxis | ( | void |  | ) | const

Returns the Z orthonormal axis defining the quaternion.

Same as doing zAxis = Vector3::UNIT_Z * this. Also called the local Z-axis

## Friends And Related Function Documentation

## operator*

_OgreExport friend Quaternion operator* | ( | Real | fScalar,
|  | const Quaternion & | rkQ
| ) |  |

friend

## operator<<

_OgreExport friend std::ostream& operator<< | ( | std::ostream & | o,
|  | const Quaternion & | q
| ) |  |

friend

Function for writing to a stream.

Outputs "Quaternion(w, x, y, z)" with w,x,y,z being the member values of the quaternion.

Definition at line 315 of file OgreQuaternion.h.

## Member Data Documentation

## IDENTITY

const Quaternion Ogre::Quaternion::IDENTITY

static

Definition at line 301 of file OgreQuaternion.h.

Referenced by Ogre::SceneNode::getCreator(), Ogre::Entity::getCurrentLodIndex(), Ogre::StaticGeometry::getName(), Ogre::InstancedGeometry::getName(), Ogre::Vector3::getRotationTo(), Ogre::SceneManager::getSkyBoxGenParameters(), Ogre::SceneManager::getSkyPlaneGenParameters(), and Ogre::StringConverter::parseAngle().

## msEpsilon

const Real Ogre::Quaternion::msEpsilon

static

Cutoff for sine near zero.

Definition at line 297 of file OgreQuaternion.h.

## w

Real Ogre::Quaternion::w

Definition at line 303 of file OgreQuaternion.h.

Referenced by Ogre::Vector3::getRotationTo(), operator=(), operator==(), and swap().

## x

Real Ogre::Quaternion::x

Definition at line 303 of file OgreQuaternion.h.

Referenced by Ogre::Vector3::getRotationTo(), operator=(), operator==(), and swap().

## y

Real Ogre::Quaternion::y

Definition at line 303 of file OgreQuaternion.h.

Referenced by Ogre::Vector3::getRotationTo(), operator=(), operator==(), and swap().

## z

Real Ogre::Quaternion::z

Definition at line 303 of file OgreQuaternion.h.

Referenced by Ogre::Vector3::getRotationTo(), operator=(), operator==(), and swap().

## ZERO

const Quaternion Ogre::Quaternion::ZERO

static

Definition at line 300 of file OgreQuaternion.h.

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

- OgreQuaternion.h

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.