reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofQuaternion Class Reference

#include <ofQuaternion.h>

Public Member Functions

Constructor
 ofQuaternion ()
 
 ofQuaternion (float x, float y, float z, float w)
 
 ofQuaternion (const ofVec4f &v)
 
 ofQuaternion (float angle, const ofVec3f &axis)
 
 ofQuaternion (float angle1, const ofVec3f &axis1, float angle2, const ofVec3f &axis2, float angle3, const ofVec3f &axis3)
 
 ofQuaternion (const glm::quat &q)
 
 operator glm::quat () const
 
Setters
void set (float x, float y, float z, float w)
 
void set (const ofVec4f &v)
 
void set (const ofMatrix4x4 &matrix)
 
Getters
float & operator[] (int i)
 
float operator[] (int i) const
 
void get (ofMatrix4x4 &matrix) const
 
float & x ()
 
float & y ()
 
float & z ()
 
float & w ()
 
float x () const
 
float y () const
 
float z () const
 
float w () const
 
ofVec4f asVec4 () const
 
ofVec3f asVec3 () const
 
Functions
bool zeroRotation () const
 return true if the Quat represents a zero rotation, and therefore can be ignored in computations.
 
float length () const
 Length of the quaternion = sqrt(vec . vec)
 
float length2 () const
 Length of the quaternion = vec . vec.
 
ofQuaternion conj () const
 Conjugate.
 
const ofQuaternion inverse () const
 Multiplicative inverse method.
 
void makeRotate (float angle, float x, float y, float z)
 
void makeRotate (float angle, const ofVec3f &vec)
 
void makeRotate (float angle1, const ofVec3f &axis1, float angle2, const ofVec3f &axis2, float angle3, const ofVec3f &axis3)
 
void makeRotate (const ofVec3f &vec1, const ofVec3f &vec2)
 Make a rotation Quat which will rotate vec1 to vec2. Generally take a dot product to get the angle between these and then use a cross product to get the rotation axis Watch out for the two special cases when the vectors are co-incident or opposite in direction.
 
void makeRotate_original (const ofVec3f &vec1, const ofVec3f &vec2)
 
void getRotate (float &angle, float &x, float &y, float &z) const
 Return the angle and vector components represented by the quaternion.
 
void getRotate (float &angle, ofVec3f &vec) const
 
ofVec3f getEuler () const
 Calculate and return the rotation as euler angles.
 
void slerp (float t, const ofQuaternion &from, const ofQuaternion &to)
 Spherical Linear Interpolation.
 
void normalize ()
 

Operators

ofQuaternionoperator= (const ofQuaternion &q)
 
bool operator== (const ofQuaternion &q) const
 
bool operator!= (const ofQuaternion &q) const
 
const ofQuaternion operator* (float rhs) const
 Multiply by scalar.
 
const ofQuaternion operator* (const ofQuaternion &rhs) const
 Binary multiply.
 
ofVec3f operator* (const ofVec3f &v) const
 Rotate a vector by this quaternion.
 
ofQuaternionoperator*= (float rhs)
 Unary multiply by scalar.
 
ofQuaternionoperator*= (const ofQuaternion &rhs)
 Unary multiply.
 
ofQuaternion operator/ (float rhs) const
 Divide by scalar.
 
const ofQuaternion operator/ (const ofQuaternion &denom) const
 Binary divide.
 
ofQuaternionoperator/= (float rhs)
 Unary divide by scalar.
 
ofQuaternionoperator/= (const ofQuaternion &denom)
 Unary divide.
 
const ofQuaternion operator+ (const ofQuaternion &rhs) const
 Binary addition.
 
ofQuaternionoperator+= (const ofQuaternion &rhs)
 Unary addition.
 
ofQuaternionoperator-= (const ofQuaternion &rhs)
 Unary subtraction.
 
const ofQuaternion operator- (const ofQuaternion &rhs) const
 Binary subtraction.
 
const ofQuaternion operator- () const
 returns the negative of the quaternion. calls operator -() on the Vec4
 
std::ostream & operator<< (std::ostream &os, const ofQuaternion &q)
 
std::istream & operator>> (std::istream &is, ofQuaternion &q)
 

Constructor & Destructor Documentation

◆ ofQuaternion() [1/6]

ofQuaternion::ofQuaternion ( )
inline

◆ ofQuaternion() [2/6]

ofQuaternion::ofQuaternion ( float  x,
float  y,
float  z,
float  w 
)
inline

◆ ofQuaternion() [3/6]

ofQuaternion::ofQuaternion ( const ofVec4f v)
inline

◆ ofQuaternion() [4/6]

ofQuaternion::ofQuaternion ( float  angle,
const ofVec3f axis 
)
inline

◆ ofQuaternion() [5/6]

ofQuaternion::ofQuaternion ( float  angle1,
const ofVec3f axis1,
float  angle2,
const ofVec3f axis2,
float  angle3,
const ofVec3f axis3 
)
inline

◆ ofQuaternion() [6/6]

ofQuaternion::ofQuaternion ( const glm::quat &  q)

Member Function Documentation

◆ asVec3()

ofVec3f ofQuaternion::asVec3 ( ) const
inline

◆ asVec4()

ofVec4f ofQuaternion::asVec4 ( ) const
inline

◆ conj()

ofQuaternion ofQuaternion::conj ( ) const
inline

Conjugate.

◆ get()

void ofQuaternion::get ( ofMatrix4x4 matrix) const

◆ getEuler()

ofVec3f ofQuaternion::getEuler ( ) const

Calculate and return the rotation as euler angles.

◆ getRotate() [1/2]

void ofQuaternion::getRotate ( float &  angle,
float &  x,
float &  y,
float &  z 
) const

Return the angle and vector components represented by the quaternion.

◆ getRotate() [2/2]

void ofQuaternion::getRotate ( float &  angle,
ofVec3f vec 
) const

◆ inverse()

const ofQuaternion ofQuaternion::inverse ( ) const
inline

Multiplicative inverse method.

q^(-1) = q^*&zwj;/(q.q^*) 

◆ length()

float ofQuaternion::length ( ) const
inline

Length of the quaternion = sqrt(vec . vec)

◆ length2()

float ofQuaternion::length2 ( ) const
inline

Length of the quaternion = vec . vec.

◆ makeRotate() [1/4]

void ofQuaternion::makeRotate ( const ofVec3f from,
const ofVec3f to 
)

Make a rotation Quat which will rotate vec1 to vec2. Generally take a dot product to get the angle between these and then use a cross product to get the rotation axis Watch out for the two special cases when the vectors are co-incident or opposite in direction.

Make a rotation Quat which will rotate vec1 to vec2

This routine uses only fast geometric transforms, without costly acos/sin computations. It's exact, fast, and with less degenerate cases than the acos/sin method.

For an explanation of the math used, you may see for example: http://logiciels.cnes.fr/MARMOTTES/marmottes-mathematique.pdf

Note
This is the rotation with shortest angle, which is the one equivalent to the acos/sin transform method. Other rotations exists, for example to additionally keep a local horizontal attitude.
Author
Nicolas Brodu

◆ makeRotate() [2/4]

void ofQuaternion::makeRotate ( float  angle,
const ofVec3f vec 
)

◆ makeRotate() [3/4]

void ofQuaternion::makeRotate ( float  angle,
float  x,
float  y,
float  z 
)

\briefSet a quaternion which will perform a rotation of an angle around the axis given by the vector(x,y,z).

Define Spherical Linear interpolation method also

Set the elements of the Quat to represent a rotation of angle (degrees) around the axis (x,y,z)

◆ makeRotate() [4/4]

void ofQuaternion::makeRotate ( float  angle1,
const ofVec3f axis1,
float  angle2,
const ofVec3f axis2,
float  angle3,
const ofVec3f axis3 
)

◆ makeRotate_original()

void ofQuaternion::makeRotate_original ( const ofVec3f vec1,
const ofVec3f vec2 
)

◆ normalize()

void ofQuaternion::normalize ( )
inline

◆ operator glm::quat()

ofQuaternion::operator glm::quat ( ) const

◆ operator!=()

bool ofQuaternion::operator!= ( const ofQuaternion q) const
inline

◆ operator*() [1/3]

const ofQuaternion ofQuaternion::operator* ( const ofQuaternion rhs) const
inline

Binary multiply.

◆ operator*() [2/3]

ofVec3f ofQuaternion::operator* ( const ofVec3f v) const
inline

Rotate a vector by this quaternion.

◆ operator*() [3/3]

const ofQuaternion ofQuaternion::operator* ( float  rhs) const
inline

Multiply by scalar.

◆ operator*=() [1/2]

ofQuaternion & ofQuaternion::operator*= ( const ofQuaternion rhs)
inline

Unary multiply.

◆ operator*=() [2/2]

ofQuaternion & ofQuaternion::operator*= ( float  rhs)
inline

Unary multiply by scalar.

◆ operator+()

const ofQuaternion ofQuaternion::operator+ ( const ofQuaternion rhs) const
inline

Binary addition.

◆ operator+=()

ofQuaternion & ofQuaternion::operator+= ( const ofQuaternion rhs)
inline

Unary addition.

◆ operator-() [1/2]

const ofQuaternion ofQuaternion::operator- ( ) const
inline

returns the negative of the quaternion. calls operator -() on the Vec4

◆ operator-() [2/2]

const ofQuaternion ofQuaternion::operator- ( const ofQuaternion rhs) const
inline

Binary subtraction.

◆ operator-=()

ofQuaternion & ofQuaternion::operator-= ( const ofQuaternion rhs)
inline

Unary subtraction.

◆ operator/() [1/2]

const ofQuaternion ofQuaternion::operator/ ( const ofQuaternion denom) const
inline

Binary divide.

◆ operator/() [2/2]

ofQuaternion ofQuaternion::operator/ ( float  rhs) const
inline

Divide by scalar.

◆ operator/=() [1/2]

ofQuaternion & ofQuaternion::operator/= ( const ofQuaternion denom)
inline

Unary divide.

◆ operator/=() [2/2]

ofQuaternion & ofQuaternion::operator/= ( float  rhs)
inline

Unary divide by scalar.

◆ operator=()

ofQuaternion & ofQuaternion::operator= ( const ofQuaternion q)
inline

◆ operator==()

bool ofQuaternion::operator== ( const ofQuaternion q) const
inline

◆ operator[]() [1/2]

float & ofQuaternion::operator[] ( int  i)
inline

◆ operator[]() [2/2]

float ofQuaternion::operator[] ( int  i) const
inline

◆ set() [1/3]

void ofQuaternion::set ( const ofMatrix4x4 matrix)

◆ set() [2/3]

void ofQuaternion::set ( const ofVec4f v)
inline

◆ set() [3/3]

void ofQuaternion::set ( float  x,
float  y,
float  z,
float  w 
)
inline

◆ slerp()

void ofQuaternion::slerp ( float  t,
const ofQuaternion from,
const ofQuaternion to 
)

Spherical Linear Interpolation.

As t goes from 0 to 1, the Quat object goes from "from" to "to".

Spherical Linear Interpolation As t goes from 0 to 1, the Quat object goes from "from" to "to" Reference: Shoemake at SIGGRAPH 89 See also http://www.gamasutra.com/features/programming/19980703/quaternions_01.htm

◆ w() [1/2]

float & ofQuaternion::w ( )
inline

◆ w() [2/2]

float ofQuaternion::w ( ) const
inline

◆ x() [1/2]

float & ofQuaternion::x ( )
inline

◆ x() [2/2]

float ofQuaternion::x ( ) const
inline

◆ y() [1/2]

float & ofQuaternion::y ( )
inline

◆ y() [2/2]

float ofQuaternion::y ( ) const
inline

◆ z() [1/2]

float & ofQuaternion::z ( )
inline

◆ z() [2/2]

float ofQuaternion::z ( ) const
inline

◆ zeroRotation()

bool ofQuaternion::zeroRotation ( ) const
inline

return true if the Quat represents a zero rotation, and therefore can be ignored in computations.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const ofQuaternion q 
)
friend

◆ operator>>

std::istream & operator>> ( std::istream &  is,
ofQuaternion q 
)
friend

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