Files Class List
Quaternion< T > Class Template Reference

Detailed Description

template<typename T>
class cy::Quaternion< T >

Quaternion class.

#include <cyQuaternion.h>

+ Inheritance diagram for Quaternion< T >:

Public Member Functions

Constructors
 Quaternion (T const &x, T const &y, T const &z, T const &_s)
 
 Quaternion (Vec3< T > const &_v, T _s=0)
 
 Quaternion (Vec4< T > const &q)
 
 Quaternion (UnitQuaternion< T > const &q)
 
 Quaternion (Vec3< T > const &from, Vec3< T > const &to)
 
Set & Get value functions
void Zero ()
 Sets the scalar part to one and vector part to zero, meaning no rotation.
 
void Set (Vec3< T > const &_v, T _s)
 Sets the scalar and vector components of the quaternion.
 
void Set (T x, T y, T z, T _s)
 Sets the scalar and vector components of the quaternion.
 
bool IsFinite () const
 Returns true if all components are non-infinite numbers.
 
bool IsUnit () const
 Returns true if the length of the quaternion is close to 1.
 
void SetRotation (Vec3< T > const &axis, T angle)
 Sets a rotation around the given axis.
 
void SetRotation (Matrix3< T > const &rotation)
 Sets the quaternion using a rotation matrix. This method only works for rotation matrices.
 
void SetRotation (Vec3< T > const &from, Vec3< T > const &to)
 Sets the quaternion as a rotation from one direction to another. The resulting quaternion is not normalized.
 
void SetHalfRotation ()
 Reduces the rotation of the quaternion by half.
 
GetRotationAngle () const
 Returns rotation angle in radians.
 
Vec3< T > GetRotationAxis () const
 Returns the normalized rotation axis.
 
Normalize, Length, and Inverse functions
void Normalize ()
 Normalizes the quaternion, such that its length becomes 1.
 
Quaternion GetNormalized () const
 Returns a normalized copy of the quaternion.
 
LengthSquared () const
 Returns the square of the length. Effectively, this is the dot product of the vector with itself.
 
Length () const
 Returns the length of the quaternion.
 
Quaternion GetInverse () const
 Returns the inverse of the quaternion.
 
void Invert ()
 Normalizes the quaternion, such that its length becomes 1.
 
Conversion functions
Matrix3< T > GetMatrix3 () const
 Returns a matrix representing the rotation of the quaternion.
 
Matrix4< T > GetMatrix4 () const
 Returns a matrix representing the rotation of the quaternion.
 
 operator Matrix3< T > () const
 Returns a matrix representing the rotation of the quaternion.
 
 operator Matrix4< T > () const
 Returns a matrix representing the rotation of the quaternion.
 
 operator Vec4< T > () const
 Returns a vector containing the values of the quaternion with the scalar in the w coordinate.
 
Unary operators
Quaternion operator- () const
 
Binary operators
Quaternion operator* (Quaternion const &q) const
 
Quaternion operator+ (Quaternion const &q) const
 
Quaternion operator- (Quaternion const &q) const
 
Quaternion operator* (T const &f) const
 
Quaternion operator/ (T const &f) const
 
Vec3< T > operator* (Vec3< T > const &p) const
 
Matrix3< T > operator* (Matrix3< T > const &m) const
 
Assignment operators
Quaternionoperator*= (Quaternion const &q)
 
Quaternionoperator+= (Quaternion const &q)
 
Quaternionoperator-= (Quaternion const &q)
 
Quaternionoperator*= (T const &f)
 
Quaternionoperator/= (T const &f)
 
Test operators
int operator== (Quaternion const &q) const
 
int operator!= (Quaternion const &q) const
 
Dot product
Dot (Quaternion const &p) const
 Dot product.
 
operator% (Quaternion const &p) const
 Dot product.
 

Public Attributes

Vec3< T > v
 vector part
 
s
 scalar part
 

Friends

Quaternion operator* (T const &f, const Quaternion &q)
 
Matrix3< T > operator* (Matrix3< T > const &m, const Quaternion &q)
 
Quaternion Inverse (Quaternion const &q)
 return the inverse of the quaternion