Crazy Eddie's GUI System  0.8.3
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
CEGUI::Quaternion Class Reference

Class to represent rotation, avoids Gimbal lock. More...

+ Inheritance diagram for CEGUI::Quaternion:
+ Collaboration diagram for CEGUI::Quaternion:

Public Member Functions

 Quaternion (float w=1.0f, float x=0.0f, float y=0.0f, float z=0.0f)
 verbatim constructor
 
 Quaternion (const Quaternion &v)
 copy constructor
 
Quaternionoperator= (const Quaternion &v)
 assignment operator
 
bool operator== (const Quaternion &v) const
 equality operator
 
bool operator!= (const Quaternion &v) const
 inequality operator
 
Quaternion operator- () const
 negation operator
 
Quaternion operator* (float v) const
 scalar multiplication operator
 
float dot (const Quaternion &v) const
 quaternion dot product
 
Quaternion operator+ (const Quaternion &v) const
 addition operator
 
Quaternion operator* (const Quaternion &v) const
 quaternion multiplication (not commutative!) More...
 
float length () const
 computers and returns the length of this quaternion
 
float normalise ()
 normalises this quaternion and returns it's length (since it has to be computed anyways)
 

Static Public Member Functions

static Quaternion eulerAnglesRadians (float x, float y, float z)
 constructs a quaternion from euler angles in radians More...
 
static Quaternion eulerAnglesDegrees (float x, float y, float z)
 constructs a quaternion from euler angles in degrees More...
 
static Quaternion axisAngleRadians (const Vector3f &axis, float rotation)
 constructs a quaternion from axis and angle around it in radians More...
 
static Quaternion axisAngleDegrees (const Vector3f &axis, float rotation)
 constructs a quaternion from axis and angle around it in degrees More...
 
static Quaternion slerp (const Quaternion &left, const Quaternion &right, float position, bool shortestPath=false)
 spherical linear interpolation More...
 

Public Attributes

float d_w
 imaginary part
 
float d_x
 x component of the vector part
 
float d_y
 y component of the vector part
 
float d_z
 z component of the vector part
 

Static Public Attributes

static const Quaternion ZERO
 Quaternion(0, 0, 0, 0)
 
static const Quaternion IDENTITY
 Quaternion(1, 0, 0, 0)
 

Friends

Quaternion operator* (float v, const Quaternion &q)
 scalar multiplication operator
 
std::ostream & operator<< (std::ostream &s, const Quaternion &v)
 allows writing the quaternion to std ostream
 

Detailed Description

Class to represent rotation, avoids Gimbal lock.

Most people are afraid of Quaternions, you don't have to fully understand them. In CEGUI, you can just think of quaternions as magic opaque boxes that hold rotation data. No need to understand how they work and why. You obviously have to understand what degrees and radians are, I won't go into that here.

How to convert "human readable" rotation data to Quaternions: 1) Euler angles, 3 floating point values x - rotation around X axis (anticlockwise) y - rotation around Y axis (anticlockwise) z - rotation around Z axis (anticlockwise)

The actual rotation is performed in z, y, x order. Keep that in mind!

For these, just use eulerAnglesDegrees or eulerAnglesRadians static methods.

2) Rotation around axis, 1 Vector3 and one degree/radian angle the vector represents the axis (it's length doesn't matter at all), rotation is then performed by rotating given angle anticlockwise around that axis.

For these, use axisAngleDegrees or axisAngleRadians static methods.

Member Function Documentation

static Quaternion CEGUI::Quaternion::axisAngleDegrees ( const Vector3f axis,
float  rotation 
)
static

constructs a quaternion from axis and angle around it in degrees

Parameters
axisvector describing the axis of rotation
rotationAnticlockwise rotation around given axis
static Quaternion CEGUI::Quaternion::axisAngleRadians ( const Vector3f axis,
float  rotation 
)
static

constructs a quaternion from axis and angle around it in radians

Parameters
axisvector describing the axis of rotation
rotationAnticlockwise rotation around given axis
static Quaternion CEGUI::Quaternion::eulerAnglesDegrees ( float  x,
float  y,
float  z 
)
static

constructs a quaternion from euler angles in degrees

Parameters
xAnticlockwise rotation around X axis
yAnticlockwise rotation around Y axis
zAnticlockwise rotation around Z axis

The rotation is performed around Z first, then Y and then X!

static Quaternion CEGUI::Quaternion::eulerAnglesRadians ( float  x,
float  y,
float  z 
)
static

constructs a quaternion from euler angles in radians

Parameters
xAnticlockwise rotation around X axis
yAnticlockwise rotation around Y axis
zAnticlockwise rotation around Z axis

The rotation is performed around Z first, then Y and then X!

Quaternion CEGUI::Quaternion::operator* ( const Quaternion v) const
inline

quaternion multiplication (not commutative!)

Lets say we have quaternion A describing a rotation and another quaternion B. If we write C = A * B, C is actually describing a rotation we would get if we rotated Identity by A and then rotated the result by B

References d_w, d_x, d_y, and d_z.

static Quaternion CEGUI::Quaternion::slerp ( const Quaternion left,
const Quaternion right,
float  position,
bool  shortestPath = false 
)
static

spherical linear interpolation

Parameters
leftLeft keyframe Quaternion
rightRight keyframe Quaternion
positionNumber from range <0.0, 1.0), the closer this is to 1.0, the closer the interpolation is to the "right" quaternion
shortestPathIf true, the interpolation is guaranteed to go through the shortest path