ML Reference
ml::Rotation Class Reference

Class to handle Rotations (internally, the rotation is stored as a unit quaternion) More...

#include <mlRotation.h>

Public Member Functions

 Rotation ()
 Initializes this rotation to the identity rotation. More...
 
 Rotation (const Vector3 &axis, MLdouble angle)
 Generates a rotation from axis and angle; the angle is given in radians. More...
 
 Rotation (const Vector3 &fromVec, const Vector3 &toVec)
 Generates a rotation from fromVec to toVec. More...
 
 Rotation (const Matrix4 &m)
 Generates a rotation from a rotation matrix. The result is invalid if the matrix is not a rotation matrix. More...
 
 Rotation (const Rotation &)
 Copy constructor. More...
 
 Rotation (MLdouble x, MLdouble y, MLdouble z, MLdouble w)
 Constructs a rotation from quaternion parameters x y z w. More...
 
Matrix4 getMatrix () const
 Converts the rotation to a rotation matrix and returns the matrix. More...
 
void getRotation (Vector3 &axis, MLdouble &angle) const
 Converts the rotation to an axis axis and and angle angle (in radians). More...
 
void setRotation (const Vector3 &axis, MLdouble angle)
 Builds a rotation from an axis axis and an angle angle (in radians). More...
 
Rotation multiply (const Rotation &rotation) const
 Multiplies (concatenates) this rotation with rotation and returns the new rotation. More...
 
Vector3 rotate (const Vector3 &vec) const
 Rotates the given vector and returns the result vector. More...
 
Rotationconjugate ()
 Negates the rotation. More...
 
Rotationoperator*= (const Rotation &rotation)
 Multiplies two rotations with each other (see multiply). More...
 
Rotationoperator= (const Rotation &rotation)
 Assignment operator. More...
 
const Vector3getVector () const
 Returns the vector part (x/y/z). More...
 
MLdouble getScalar () const
 Returns the scalar part (w). More...
 

Static Public Member Functions

static Matrix4 slerp (const Matrix4 &m1, const Matrix4 &m2, MLdouble t)
 Spherical linear interpolation at t between matrices m1 and [ m2. More...
 
static Rotation slerp (const Rotation &rot1, const Rotation &rot2, MLdouble t)
 Spherical linear interpolation at t between rotations rot1 and rot2. More...
 

Protected Attributes

Vector3 _vector
 The x,y,z part of the quaternion. More...
 
MLdouble _scalar
 The w part of the quaternion. More...
 

Friends

ML_LINEAR_ALGEBRA_EXPORT friend Rotation operator* (const Rotation &a, const Rotation &b)
 Multiplies two rotations with each other (see multiply). More...
 

Detailed Description

Class to handle Rotations (internally, the rotation is stored as a unit quaternion)

See "Advanced Animation and Rendering Techniques", Watt, Addison+Wesley, page 360ff for an introduction on quaternions

Quaternions extend the concept of rotation in three dimensions to rotation in four dimensions. This avoids the problem of a 'gimbal-lock' and allows for the implementation of a smooth and continuous rotation. In effect, they may be considered to add an additional rotation angle to spherical coordinates such as Longitude, Latitude, and Rotation angles. A Quaternion is defined using four floating point values |x y z w|. These are calculated from the combination of the three coordinates of the rotation axis and the rotation angle.

Definition at line 37 of file mlRotation.h.

Constructor & Destructor Documentation

◆ Rotation() [1/6]

ml::Rotation::Rotation ( )

Initializes this rotation to the identity rotation.

◆ Rotation() [2/6]

ml::Rotation::Rotation ( const Vector3 axis,
MLdouble  angle 
)

Generates a rotation from axis and angle; the angle is given in radians.

◆ Rotation() [3/6]

ml::Rotation::Rotation ( const Vector3 fromVec,
const Vector3 toVec 
)

Generates a rotation from fromVec to toVec.

◆ Rotation() [4/6]

ml::Rotation::Rotation ( const Matrix4 m)

Generates a rotation from a rotation matrix. The result is invalid if the matrix is not a rotation matrix.

◆ Rotation() [5/6]

ml::Rotation::Rotation ( const Rotation )

Copy constructor.

◆ Rotation() [6/6]

ml::Rotation::Rotation ( MLdouble  x,
MLdouble  y,
MLdouble  z,
MLdouble  w 
)

Constructs a rotation from quaternion parameters x y z w.

These parameters are not axis and angle; read more on quaternions to use this constructor! It accepts any quaternion and normalizes it to a unit quaternion.

Member Function Documentation

◆ conjugate()

Rotation& ml::Rotation::conjugate ( )

Negates the rotation.

◆ getMatrix()

Matrix4 ml::Rotation::getMatrix ( ) const

Converts the rotation to a rotation matrix and returns the matrix.

◆ getRotation()

void ml::Rotation::getRotation ( Vector3 axis,
MLdouble angle 
) const

Converts the rotation to an axis axis and and angle angle (in radians).

◆ getScalar()

MLdouble ml::Rotation::getScalar ( ) const
inline

Returns the scalar part (w).

Definition at line 99 of file mlRotation.h.

◆ getVector()

const Vector3& ml::Rotation::getVector ( ) const
inline

Returns the vector part (x/y/z).

Definition at line 96 of file mlRotation.h.

◆ multiply()

Rotation ml::Rotation::multiply ( const Rotation rotation) const

Multiplies (concatenates) this rotation with rotation and returns the new rotation.

◆ operator*=()

Rotation& ml::Rotation::operator*= ( const Rotation rotation)

Multiplies two rotations with each other (see multiply).

◆ operator=()

Rotation& ml::Rotation::operator= ( const Rotation rotation)

Assignment operator.

◆ rotate()

Vector3 ml::Rotation::rotate ( const Vector3 vec) const

Rotates the given vector and returns the result vector.

◆ setRotation()

void ml::Rotation::setRotation ( const Vector3 axis,
MLdouble  angle 
)

Builds a rotation from an axis axis and an angle angle (in radians).

◆ slerp() [1/2]

static Matrix4 ml::Rotation::slerp ( const Matrix4 m1,
const Matrix4 m2,
MLdouble  t 
)
static

Spherical linear interpolation at t between matrices m1 and [ m2.

Returns an interpolated rotation matrix.

◆ slerp() [2/2]

static Rotation ml::Rotation::slerp ( const Rotation rot1,
const Rotation rot2,
MLdouble  t 
)
static

Spherical linear interpolation at t between rotations rot1 and rot2.

Returns an interpolated rotation.

Friends And Related Function Documentation

◆ operator*

ML_LINEAR_ALGEBRA_EXPORT friend Rotation operator* ( const Rotation a,
const Rotation b 
)
friend

Multiplies two rotations with each other (see multiply).

Member Data Documentation

◆ _scalar

MLdouble ml::Rotation::_scalar
protected

The w part of the quaternion.

Definition at line 106 of file mlRotation.h.

◆ _vector

Vector3 ml::Rotation::_vector
protected

The x,y,z part of the quaternion.

Definition at line 103 of file mlRotation.h.


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