Honeycomb  0.1
Component-Model Framework
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
honey::Quat_< Real__ > Class Template Reference

Quaternion rotation class. Represents a counter-clockwise rotation of an angle about its axis. More...

#include <Matrix4.h>

Collaboration diagram for honey::Quat_< Real__ >:
Collaboration graph
[legend]

Public Types

enum  EulerOrder {
  EulerOrder::xyz_s = _ORD(eulAxX, eulParEven, eulRepNo, eulFrmS), EulerOrder::xyx_s = _ORD(eulAxX, eulParEven, eulRepYes, eulFrmS), EulerOrder::xzy_s = _ORD(eulAxX, eulParOdd, eulRepNo, eulFrmS), EulerOrder::xzx_s = _ORD(eulAxX, eulParOdd, eulRepYes, eulFrmS),
  EulerOrder::yzx_s = _ORD(eulAxY, eulParEven, eulRepNo, eulFrmS), EulerOrder::yzy_s = _ORD(eulAxY, eulParEven, eulRepYes, eulFrmS), EulerOrder::yxz_s = _ORD(eulAxY, eulParOdd, eulRepNo, eulFrmS), EulerOrder::yxy_s = _ORD(eulAxY, eulParOdd, eulRepYes, eulFrmS),
  EulerOrder::zxy_s = _ORD(eulAxZ, eulParEven, eulRepNo, eulFrmS), EulerOrder::zxz_s = _ORD(eulAxZ, eulParEven, eulRepYes, eulFrmS), EulerOrder::zyx_s = _ORD(eulAxZ, eulParOdd, eulRepNo, eulFrmS), EulerOrder::zyz_s = _ORD(eulAxZ, eulParOdd, eulRepYes, eulFrmS),
  EulerOrder::zyx_r = _ORD(eulAxX, eulParEven, eulRepNo, eulFrmR), EulerOrder::xyx_r = _ORD(eulAxX, eulParEven, eulRepYes, eulFrmR), EulerOrder::yzx_r = _ORD(eulAxX, eulParOdd, eulRepNo, eulFrmR), EulerOrder::xzx_r = _ORD(eulAxX, eulParOdd, eulRepYes, eulFrmR),
  EulerOrder::xzy_r = _ORD(eulAxY, eulParEven, eulRepNo, eulFrmR), EulerOrder::yzy_r = _ORD(eulAxY, eulParEven, eulRepYes, eulFrmR), EulerOrder::zxy_r = _ORD(eulAxY, eulParOdd, eulRepNo, eulFrmR), EulerOrder::yxy_r = _ORD(eulAxY, eulParOdd, eulRepYes, eulFrmR),
  EulerOrder::yxz_r = _ORD(eulAxZ, eulParEven, eulRepNo, eulFrmR), EulerOrder::zxz_r = _ORD(eulAxZ, eulParEven, eulRepYes, eulFrmR), EulerOrder::xyz_r = _ORD(eulAxZ, eulParOdd, eulRepNo, eulFrmR), EulerOrder::zyz_r = _ORD(eulAxZ, eulParOdd, eulRepYes, eulFrmR)
}
 Euler angle order. More...
 
typedef Real__ Real
 

Public Member Functions

 Quat_ ()
 Construct with identity. More...
 
 Quat_ (Real x, Real y, Real z, Real w)
 Construct with imaginary vector components x,y,z and real scalar component w. More...
 
 Quat_ (const Vec3 &axis, Real angle)
 Construct from axis and angle in radians. More...
 
 Quat_ (const Vec3 &axisX, const Vec3 &axisY, const Vec3 &axisZ)
 Construct from 3 unit vectors. More...
 
 Quat_ (const Vec3 &from, const Vec3 &to)
 Construct a quaternion that rotates unit vector from towards unit vector to. More...
 
 Quat_ (const Vec3 &eulerAngles)
 Construct from euler angles in radians and order xyz_s More...
 
 Quat_ (const Vec3 &eulerAngles, EulerOrder order)
 Construct from euler angles in order. More...
 
 Quat_ (const Matrix4 &rot)
 Construct from 4x4 homogeneous matrix. Rotation is extracted from upper-left 3x3 submatrix. More...
 
Quat_fromZero ()
 Set quaternion to zero. More...
 
Quat_fromIdentity ()
 Set quaternion to identity. More...
 
Quat_fromAxisAngle (const Vec3 &axis, Real angle)
 Construct from axis and angle in radians. More...
 
Quat_fromEulerAngles (const Vec3 &eulerAngles)
 Construct from euler angles in radians and order xyz_s More...
 
Quat_fromEulerAngles (const Vec3 &eulerAngles, EulerOrder order)
 Construct from euler angles in order. More...
 
Quat_fromMatrix (const Matrix4 &rot)
 Construct from 4x4 homogeneous matrix. Rotation is extracted from upper-left 3x3 submatrix. More...
 
Quat_fromAlign (const Vec3 &v1, const Vec3 &v2)
 Construct a quaternion that rotates unit vector v1 towards unit vector v2. The resulting quat's axis is perpendicular to v1 and v2. More...
 
Quat_fromAxes (const Vec3 &axisX, const Vec3 &axisY, const Vec3 &axisZ)
 Construct from 3 unit vectors. More...
 
bool operator== (const Quat_ &rhs) const
 
bool operator!= (const Quat_ &rhs) const
 
Quat_ operator+ () const
 
Quat_ operator+ (const Quat_ &rhs) const
 
Quat_operator+= (const Quat_ &rhs)
 
Quat_ operator- () const
 
Quat_ operator- (const Quat_ &rhs) const
 
Quat_operator-= (const Quat_ &rhs)
 
Quat_ operator* (const Quat_ &rhs) const
 
Vec3 operator* (const Vec3 &rhs) const
 
Quat_ operator* (Real rhs) const
 
Quat_operator*= (const Quat_ &rhs)
 
Quat_operator*= (Real rhs)
 
Quat_ operator/ (const Quat_ &rhs) const
 
Quat_ operator/ (Real rhs) const
 
Quat_operator/= (const Quat_ &rhs)
 
Quat_operator/= (Real rhs)
 
const Realoperator[] (int i) const
 Access quaternion components. More...
 
Realoperator[] (int i)
 
 operator Real * ()
 Cast to array of quaternion components. More...
 
 operator const Real * () const
 
Real dot (const Quat_ &q) const
 
Quat_ conjugate () const
 
Quat_ inverse () const
 Assumes that quaternion is unit length, same as conjugate() More...
 
Quat_ inverseNonUnit () const
 Proper quaternion inverse. Only use if quaternion is expected to be non-unit length. More...
 
Quat_ exp () const
 
Quat_ ln () const
 
Quat_ sqrt () const
 
Real lengthSqr () const
 Square of the length. More...
 
Real length () const
 
Quat_ normalize (optional< Real & > len=optnull) const
 Get unit quaternion. The pre-normalized length will be returned in len if specified. More...
 
Quat_ normalize_fast () const
 Fast normalization, only accurate when quaternion is close to unit length. More...
 
void axisAngle (Vec3 &axis, Real &angle) const
 Get quaternion axis and angle in radians. More...
 
Vec3 axisX () const
 Get quaternion's rotated unit axis. More...
 
Vec3 axisY () const
 
Vec3 axisZ () const
 
void axes (Vec3 &axisX, Vec3 &axisY, Vec3 &axisZ) const
 Get unit axes that represent this quaternion. More...
 
Vec3 eulerAngles () const
 Get euler angles in radians and order xyz_s More...
 
Vec3 eulerAngles (EulerOrder order) const
 Get euler angles in order. More...
 
Matrix4toMatrix (Matrix4 &rot, bool b3x3=false) const
 Convert quaternion to 4x4 homogeneous rotation matrix. Set b3x3 to true to store the result only in the upper-left 3x3 submatrix of rot, leaving rest of matrix unchanged. More...
 

Static Public Member Functions

static Quat_ slerp (Real t, const Quat_ &q0, const Quat_ &q1)
 Spherical linear interpolation from q0 to q1. t ranges from [0,1]. More...
 
static void squadSetup (const Quat_ &q0, const Quat_ &q1, const Quat_ &q2, const Quat_ &q3, Quat_ &a, Quat_ &b, Quat_ &c)
 Calc intermediate quats required for Squad. Ex. To interpolate between q1 and q2: setup(q0,q1,q2,q3,a,b,c) -> squad(q1,a,b,c) More...
 
static Quat_ squad (Real t, const Quat_ &q1, const Quat_ &a, const Quat_ &b, const Quat_ &c)
 Spherical quadratic interpolation between q1 and c. t ranges from [0,1]. More...
 
static Quat_ baryCentric (Real f, Real g, const Quat_ &q0, const Quat_ &q1, const Quat_ &q2)
 Triangular bary-centric interpolation. More...
 

Public Attributes

Real x
 
Real y
 
Real z
 
Real w
 

Static Public Attributes

static const int dim = 4
 
static const Quat_ zero
 
static const Quat_ identity
 

Friends

Quat_ operator* (Real lhs, const Quat_ &rhs)
 
ostream & operator<< (ostream &os, const Quat_ &val)
 

Detailed Description

template<class Real__>
class honey::Quat_< Real__ >

Quaternion rotation class. Represents a counter-clockwise rotation of an angle about its axis.

Quaternion concatenation, like matrices, follows a right-to-left ordering.

ie. To rotate a vector first by q0, followed by a rotation of q1, apply $ v' = q_1*q_0*v $

Member Typedef Documentation

template<class Real__>
typedef Real__ honey::Quat_< Real__ >::Real

Member Enumeration Documentation

template<class Real__>
enum honey::Quat_::EulerOrder
strong

Euler angle order.

The default order xyz_s represents a rotation of z radians around the z-axis, followed by a rotation around the y-axis then x-axis. All axes are from the static (initial) frame.

Return values
(axes)_sStatic (initial) frame axes
(axes)_rRotating frame axes
Enumerator
xyz_s 
xyx_s 
xzy_s 
xzx_s 
yzx_s 
yzy_s 
yxz_s 
yxy_s 
zxy_s 
zxz_s 
zyx_s 
zyz_s 
zyx_r 
xyx_r 
yzx_r 
xzx_r 
xzy_r 
yzy_r 
zxy_r 
yxy_r 
yxz_r 
zxz_r 
xyz_r 
zyz_r 

Constructor & Destructor Documentation

template<class Real__>
honey::Quat_< Real__ >::Quat_ ( )
inline

Construct with identity.

template<class Real__>
honey::Quat_< Real__ >::Quat_ ( Real  x,
Real  y,
Real  z,
Real  w 
)
inline

Construct with imaginary vector components x,y,z and real scalar component w.

template<class Real__>
honey::Quat_< Real__ >::Quat_ ( const Vec3 axis,
Real  angle 
)
inline

Construct from axis and angle in radians.

template<class Real__>
honey::Quat_< Real__ >::Quat_ ( const Vec3 axisX,
const Vec3 axisY,
const Vec3 axisZ 
)
inline

Construct from 3 unit vectors.

template<class Real__>
honey::Quat_< Real__ >::Quat_ ( const Vec3 from,
const Vec3 to 
)
inline

Construct a quaternion that rotates unit vector from towards unit vector to.

template<class Real__>
honey::Quat_< Real__ >::Quat_ ( const Vec3 eulerAngles)
inlineexplicit

Construct from euler angles in radians and order xyz_s

template<class Real__>
honey::Quat_< Real__ >::Quat_ ( const Vec3 eulerAngles,
EulerOrder  order 
)
inline

Construct from euler angles in order.

template<class Real__>
honey::Quat_< Real__ >::Quat_ ( const Matrix4 rot)
inline

Construct from 4x4 homogeneous matrix. Rotation is extracted from upper-left 3x3 submatrix.

Member Function Documentation

template<class Real >
void honey::Quat_< Real >::axes ( Vec3 axisX,
Vec3 axisY,
Vec3 axisZ 
) const

Get unit axes that represent this quaternion.

template<class Real >
void honey::Quat_< Real >::axisAngle ( Vec3 axis,
Real angle 
) const

Get quaternion axis and angle in radians.

template<class Real >
Quat_< Real >::Vec3 honey::Quat_< Real >::axisX ( ) const

Get quaternion's rotated unit axis.

template<class Real >
Quat_< Real >::Vec3 honey::Quat_< Real >::axisY ( ) const
template<class Real >
Quat_< Real >::Vec3 honey::Quat_< Real >::axisZ ( ) const
template<class Real >
Quat_< Real > honey::Quat_< Real >::baryCentric ( Real  f,
Real  g,
const Quat_< Real__ > &  q0,
const Quat_< Real__ > &  q1,
const Quat_< Real__ > &  q2 
)
static

Triangular bary-centric interpolation.

Input -> Output:

(0,0) -> q0              (1,0) -> q1             (0,1) -> q2
1-f-g==0 -> line q1,q2   (f,0) -> line q0,q1     (0,g) -> line q0,q2     
template<class Real__>
Quat_ honey::Quat_< Real__ >::conjugate ( ) const
inline
template<class Real__>
Real honey::Quat_< Real__ >::dot ( const Quat_< Real__ > &  q) const
inline
template<class Real >
Quat_< Real >::Vec3 honey::Quat_< Real >::eulerAngles ( ) const

Get euler angles in radians and order xyz_s

template<class Real >
Quat_< Real >::Vec3 honey::Quat_< Real >::eulerAngles ( EulerOrder  order) const

Get euler angles in order.

template<class Real >
Quat_< Real > honey::Quat_< Real >::exp ( ) const
template<class Real >
Quat_< Real > & honey::Quat_< Real >::fromAlign ( const Vec3 v1,
const Vec3 v2 
)

Construct a quaternion that rotates unit vector v1 towards unit vector v2. The resulting quat's axis is perpendicular to v1 and v2.

template<class Real >
Quat_< Real > & honey::Quat_< Real >::fromAxes ( const Vec3 axisX,
const Vec3 axisY,
const Vec3 axisZ 
)

Construct from 3 unit vectors.

template<class Real >
Quat_< Real > & honey::Quat_< Real >::fromAxisAngle ( const Vec3 axis,
Real  angle 
)

Construct from axis and angle in radians.

template<class Real >
Quat_< Real > & honey::Quat_< Real >::fromEulerAngles ( const Vec3 eulerAngles)

Construct from euler angles in radians and order xyz_s

template<class Real >
Quat_< Real > & honey::Quat_< Real >::fromEulerAngles ( const Vec3 eulerAngles,
EulerOrder  order 
)

Construct from euler angles in order.

template<class Real__>
Quat_& honey::Quat_< Real__ >::fromIdentity ( )
inline

Set quaternion to identity.

template<class Real >
Quat_< Real > & honey::Quat_< Real >::fromMatrix ( const Matrix4 rot)

Construct from 4x4 homogeneous matrix. Rotation is extracted from upper-left 3x3 submatrix.

template<class Real__>
Quat_& honey::Quat_< Real__ >::fromZero ( )
inline

Set quaternion to zero.

template<class Real__>
Quat_ honey::Quat_< Real__ >::inverse ( ) const
inline

Assumes that quaternion is unit length, same as conjugate()

template<class Real__>
Quat_ honey::Quat_< Real__ >::inverseNonUnit ( ) const
inline

Proper quaternion inverse. Only use if quaternion is expected to be non-unit length.

template<class Real__>
Real honey::Quat_< Real__ >::length ( ) const
inline
template<class Real__>
Real honey::Quat_< Real__ >::lengthSqr ( ) const
inline

Square of the length.

template<class Real >
Quat_< Real > honey::Quat_< Real >::ln ( ) const
template<class Real__>
Quat_ honey::Quat_< Real__ >::normalize ( optional< Real & >  len = optnull) const
inline

Get unit quaternion. The pre-normalized length will be returned in len if specified.

template<class Real__>
Quat_ honey::Quat_< Real__ >::normalize_fast ( ) const
inline

Fast normalization, only accurate when quaternion is close to unit length.

template<class Real__>
honey::Quat_< Real__ >::operator const Real * ( ) const
inline
template<class Real__>
honey::Quat_< Real__ >::operator Real * ( )
inline

Cast to array of quaternion components.

template<class Real__>
bool honey::Quat_< Real__ >::operator!= ( const Quat_< Real__ > &  rhs) const
inline
template<class Real__>
Quat_ honey::Quat_< Real__ >::operator* ( const Quat_< Real__ > &  rhs) const
inline
template<class Real__>
Vec3 honey::Quat_< Real__ >::operator* ( const Vec3 rhs) const
inline
template<class Real__>
Quat_ honey::Quat_< Real__ >::operator* ( Real  rhs) const
inline
template<class Real__>
Quat_& honey::Quat_< Real__ >::operator*= ( const Quat_< Real__ > &  rhs)
inline
template<class Real__>
Quat_& honey::Quat_< Real__ >::operator*= ( Real  rhs)
inline
template<class Real__>
Quat_ honey::Quat_< Real__ >::operator+ ( ) const
inline
template<class Real__>
Quat_ honey::Quat_< Real__ >::operator+ ( const Quat_< Real__ > &  rhs) const
inline
template<class Real__>
Quat_& honey::Quat_< Real__ >::operator+= ( const Quat_< Real__ > &  rhs)
inline
template<class Real__>
Quat_ honey::Quat_< Real__ >::operator- ( ) const
inline
template<class Real__>
Quat_ honey::Quat_< Real__ >::operator- ( const Quat_< Real__ > &  rhs) const
inline
template<class Real__>
Quat_& honey::Quat_< Real__ >::operator-= ( const Quat_< Real__ > &  rhs)
inline
template<class Real__>
Quat_ honey::Quat_< Real__ >::operator/ ( const Quat_< Real__ > &  rhs) const
inline
template<class Real__>
Quat_ honey::Quat_< Real__ >::operator/ ( Real  rhs) const
inline
template<class Real__>
Quat_& honey::Quat_< Real__ >::operator/= ( const Quat_< Real__ > &  rhs)
inline
template<class Real__>
Quat_& honey::Quat_< Real__ >::operator/= ( Real  rhs)
inline
template<class Real__>
bool honey::Quat_< Real__ >::operator== ( const Quat_< Real__ > &  rhs) const
inline
template<class Real__>
const Real& honey::Quat_< Real__ >::operator[] ( int  i) const
inline

Access quaternion components.

template<class Real__>
Real& honey::Quat_< Real__ >::operator[] ( int  i)
inline
template<class Real__>
static Quat_ honey::Quat_< Real__ >::slerp ( Real  t,
const Quat_< Real__ > &  q0,
const Quat_< Real__ > &  q1 
)
inlinestatic

Spherical linear interpolation from q0 to q1. t ranges from [0,1].

template<class Real__>
Quat_ honey::Quat_< Real__ >::sqrt ( ) const
inline
template<class Real >
Quat_< Real > honey::Quat_< Real >::squad ( Real  t,
const Quat_< Real__ > &  q1,
const Quat_< Real__ > &  a,
const Quat_< Real__ > &  b,
const Quat_< Real__ > &  c 
)
static

Spherical quadratic interpolation between q1 and c. t ranges from [0,1].

See also
squadSetup()
template<class Real >
void honey::Quat_< Real >::squadSetup ( const Quat_< Real__ > &  q0,
const Quat_< Real__ > &  q1,
const Quat_< Real__ > &  q2,
const Quat_< Real__ > &  q3,
Quat_< Real__ > &  a,
Quat_< Real__ > &  b,
Quat_< Real__ > &  c 
)
static

Calc intermediate quats required for Squad. Ex. To interpolate between q1 and q2: setup(q0,q1,q2,q3,a,b,c) -> squad(q1,a,b,c)

template<class Real >
Quat_< Real >::Matrix4 & honey::Quat_< Real >::toMatrix ( Matrix4 rot,
bool  b3x3 = false 
) const

Convert quaternion to 4x4 homogeneous rotation matrix. Set b3x3 to true to store the result only in the upper-left 3x3 submatrix of rot, leaving rest of matrix unchanged.

Friends And Related Function Documentation

template<class Real__>
Quat_ operator* ( Real  lhs,
const Quat_< Real__ > &  rhs 
)
friend
template<class Real__>
ostream& operator<< ( ostream &  os,
const Quat_< Real__ > &  val 
)
friend

Member Data Documentation

template<class Real__>
const int honey::Quat_< Real__ >::dim = 4
static
template<class Real__>
const Quat_< Real > honey::Quat_< Real >::identity
static
template<class Real__>
Real honey::Quat_< Real__ >::w
template<class Real__>
Real honey::Quat_< Real__ >::x
template<class Real__>
Real honey::Quat_< Real__ >::y
template<class Real__>
Real honey::Quat_< Real__ >::z
template<class Real__>
const Quat_< Real > honey::Quat_< Real >::zero
static

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