Momentum Scripting v1
Loading...
Searching...
No Matches
MOMENTUM_NAMESPACE::Quat Class Reference

#include <Quat.h>

Public Member Functions

 Quat ()
 
 Quat (const AffineMatrix4x4 &matrix)
 
 Quat (const EulerAngles &euler)
 
 Quat (const Quat &copy)
 
 Quat (const Vec3 &from, const Vec3 &to)
 
 Quat (const Vec4 &v)
 
 Quat (double angle, const Vec3 &axis)
 
 Quat (double angle1, const Vec3 &axis1, double angle2, const Vec3 &axis2, double angle3, const Vec3 &axis3)
 
 Quat (double x, double y, double z, double w)
 
Vec3 asVec3 () const
 
Vec4 asVec4 () const
 
Quat conj () const
 
AffineMatrix4x4 get (const AffineMatrix4x4 &matrix) const
 
std::pair< double, Vec3getAsAngleAndVector () const
 
Vec3 getAsEulerAngles (EulerConvention::Convention convention=EulerConvention::Convention::DEFAULT_CONVENTION) const
 
std::pair< double, Vec3getRotate () const
 
Quat inverse () const
 
const Quat leftMult (const Quat &rhs) const
 
double length () const
 
double length2 () const
 
double normalize ()
 
bool operator!= (const Quat &v) const
 
const Quat operator* (const Quat &rhs) const
 
Vec3 operator* (const Vec3 &v) const
 
const Quat operator* (double rhs) const
 
Quat operator*= (const Quat &rhs)
 
Quat operator*= (double rhs)
 
const Quat operator+ (const Quat &rhs) const
 
Quat operator+= (const Quat &rhs)
 
const Quat operator- () const
 
const Quat operator- (const Quat &rhs) const
 
Quat operator-= (const Quat &rhs)
 
const Quat operator/ (const Quat &denom) const
 
Quat operator/ (double rhs) const
 
Quat operator/= (const Quat &denom)
 
Quat operator/= (double rhs)
 
Quat operator= (const Quat &v)
 
bool operator== (const Quat &v) const
 
double & operator[] (int i)
 
double operator[] (int i) const
 
const Quat rightMult (const Quat &rhs) const
 
Quat set (const AffineMatrix4x4 &matrix)
 
Quat set (const EulerAngles &euler)
 
void set (const Vec4 &v)
 
void set (double x, double y, double z, double w)
 
void setRotate (const Vec3 &from, const Vec3 &to)
 
void setRotate (double angle, const Vec3 &vec)
 
void setRotate (double angle, double x, double y, double z)
 
void setRotate (double angle1, const Vec3 &axis1, double angle2, const Vec3 &axis2, double angle3, const Vec3 &axis3)
 
double setW (double val)
 
double setX (double val)
 
double setY (double val)
 
double setZ (double val)
 
void slerp (double t, const Quat &from, const Quat &to)
 
double w () const
 
double x () const
 
double y () const
 
double z () const
 
bool zeroRotation () const
 

Static Public Member Functions

static Quat rotate (const Vec3 &from, const Vec3 &to)
 
static Quat rotate (double angle, const Vec3 &vec)
 
static Quat rotate (double angle, double x, double y, double z)
 
static Quat rotate (double angle1, const Vec3 &axis1, double angle2, const Vec3 &axis2, double angle3, const Vec3 &axis3)
 

Detailed Description

The object holding quaternions and providing operations on these.

The quaternion class holds a representation of quaternion objects and provides simple arithmetic as well as conversion utilities. In addition, the class can compute the 3x4 matrices for converting angular velocities to quaternion velocities and vice versa.

The convention adopted for quaternions is that they map a moving frame to the fixed global reference.

Constructor & Destructor Documentation

◆ Quat() [1/9]

MOMENTUM_NAMESPACE::Quat::Quat ( )

Default constructor. Create a Quaternion with an identity rotation.

◆ Quat() [2/9]

MOMENTUM_NAMESPACE::Quat::Quat ( double  x,
double  y,
double  z,
double  w 
)

Create a Quaternion with the specified scalar values.

◆ Quat() [3/9]

MOMENTUM_NAMESPACE::Quat::Quat ( const Vec4 v)
explicit

Create a Quaternion based on the 4D vector (x,y,z,w)

◆ Quat() [4/9]

MOMENTUM_NAMESPACE::Quat::Quat ( double  angle,
const Vec3 axis 
)

Create a Quaternion calculated from a rotation of angle radians around the rotation axis axis.

◆ Quat() [5/9]

MOMENTUM_NAMESPACE::Quat::Quat ( double  angle1,
const Vec3 axis1,
double  angle2,
const Vec3 axis2,
double  angle3,
const Vec3 axis3 
)

Create a Quaternion based on the concatenation between the three specified angle and axis.

◆ Quat() [6/9]

MOMENTUM_NAMESPACE::Quat::Quat ( const Vec3 from,
const Vec3 to 
)

Create a Quaternion which maps the rotation from vector from to the vector to.

◆ Quat() [7/9]

MOMENTUM_NAMESPACE::Quat::Quat ( const EulerAngles euler)
explicit

Create a Quaternion based on the rotation from euler specified as a EulerAngle.

◆ Quat() [8/9]

MOMENTUM_NAMESPACE::Quat::Quat ( const Quat copy)

Copy constructor.

◆ Quat() [9/9]

MOMENTUM_NAMESPACE::Quat::Quat ( const AffineMatrix4x4 matrix)
explicit

Create a Quaternion based on the rotation part in the specified Affine 4x4 transformation matrix.

Member Function Documentation

◆ asVec3()

Vec3 MOMENTUM_NAMESPACE::Quat::asVec3 ( ) const
Returns
the vector part (x,y,z) as a Vec3

◆ asVec4()

Vec4 MOMENTUM_NAMESPACE::Quat::asVec4 ( ) const
Returns
the elements in the Quaternion as a Vec4

◆ conj()

Quat MOMENTUM_NAMESPACE::Quat::conj ( ) const
Returns
the conjugate

◆ get()

AffineMatrix4x4 MOMENTUM_NAMESPACE::Quat::get ( const AffineMatrix4x4 matrix) const

Set the Rotational part of matrix from this quaternion.

Parameters
matrix- reference to the matrix where the result will be written.

◆ getAsAngleAndVector()

std::pair< double, Vec3 > MOMENTUM_NAMESPACE::Quat::getAsAngleAndVector ( ) const

Convert a Quaternion to an axis and angle representation.

Returns
the angle as the first element and the vector as the second

◆ getAsEulerAngles()

Vec3 MOMENTUM_NAMESPACE::Quat::getAsEulerAngles ( EulerConvention::Convention  convention = EulerConvention::Convention::DEFAULT_CONVENTION) const

Convert to Euler anglers.

and retrieve as a Vec3 with the angles stored.

Parameters
convention- The specified convention for EulerAngles

◆ getRotate()

std::pair< double, Vec3 > MOMENTUM_NAMESPACE::Quat::getRotate ( ) const

Get the angle and vector represented by the quaternion.

◆ inverse()

Quat MOMENTUM_NAMESPACE::Quat::inverse ( ) const

Multiplicative inverse method: q^(-1) = q^*‍/(q.q^*)

◆ leftMult()

const Quat MOMENTUM_NAMESPACE::Quat::leftMult ( const Quat rhs) const

Binary left multiplication: q = p * rhs; results in the OTHER WAY AROUND: q = rhs quatmultiply p;.

◆ length()

double MOMENTUM_NAMESPACE::Quat::length ( ) const
Returns
the length of the quaternion = sqrt( vec . vec )

◆ length2()

double MOMENTUM_NAMESPACE::Quat::length2 ( ) const
Returns
the squared length of the quaternion = vec . vec

◆ normalize()

double MOMENTUM_NAMESPACE::Quat::normalize ( )

Normalize the quat so that it has unit length.

Returns the previous length of the quat.

◆ operator!=()

bool MOMENTUM_NAMESPACE::Quat::operator!= ( const Quat v) const
Returns
true if v is not identical to this quaternion

◆ operator*() [1/3]

const Quat MOMENTUM_NAMESPACE::Quat::operator* ( const Quat rhs) const

Binary LEFT multiply: result is q = rhs quatmultiply this, even though the notation is q = this * rhs ;.

◆ operator*() [2/3]

Vec3 MOMENTUM_NAMESPACE::Quat::operator* ( const Vec3 v) const

Rotate a vector by this quaternion.

◆ operator*() [3/3]

const Quat MOMENTUM_NAMESPACE::Quat::operator* ( double  rhs) const

Multiply by scalar rhs.

◆ operator*=() [1/2]

Quat MOMENTUM_NAMESPACE::Quat::operator*= ( const Quat rhs)

Unary LEFT multiply: result is this = rhs quatmultiply this, which makes sense since the notation suggests this = rhs * this ;.

◆ operator*=() [2/2]

Quat MOMENTUM_NAMESPACE::Quat::operator*= ( double  rhs)

Unary multiply by scalar rhs.

◆ operator+()

const Quat MOMENTUM_NAMESPACE::Quat::operator+ ( const Quat rhs) const

Binary addition.

◆ operator+=()

Quat MOMENTUM_NAMESPACE::Quat::operator+= ( const Quat rhs)

Unary addition.

◆ operator-() [1/2]

const Quat MOMENTUM_NAMESPACE::Quat::operator- ( ) const

Negation operator - returns the negative of the quaternion.

Basically just calls operator - () on the Vec4

◆ operator-() [2/2]

const Quat MOMENTUM_NAMESPACE::Quat::operator- ( const Quat rhs) const

Binary subtraction.

◆ operator-=()

Quat MOMENTUM_NAMESPACE::Quat::operator-= ( const Quat rhs)

Unary subtraction.

◆ operator/() [1/2]

const Quat MOMENTUM_NAMESPACE::Quat::operator/ ( const Quat denom) const

Binary divide.

◆ operator/() [2/2]

Quat MOMENTUM_NAMESPACE::Quat::operator/ ( double  rhs) const

Divide by scalar rhs.

◆ operator/=() [1/2]

Quat MOMENTUM_NAMESPACE::Quat::operator/= ( const Quat denom)

Unary divide.

◆ operator/=() [2/2]

Quat MOMENTUM_NAMESPACE::Quat::operator/= ( double  rhs)

Unary divide by scalar rhs.

◆ operator=()

Quat MOMENTUM_NAMESPACE::Quat::operator= ( const Quat v)

Assignment operator.

◆ operator==()

bool MOMENTUM_NAMESPACE::Quat::operator== ( const Quat v) const

Test for equality.

Returns
true if this Quaternion is identical (using == operator) to v

◆ operator[]() [1/2]

double & MOMENTUM_NAMESPACE::Quat::operator[] ( int  i)
Returns
a reference to the i:th element of the quaternion in the order x,y,z,w

◆ operator[]() [2/2]

double MOMENTUM_NAMESPACE::Quat::operator[] ( int  i) const
Returns
the i:th element of the quaternion in the order x,y,z,w

◆ rightMult()

const Quat MOMENTUM_NAMESPACE::Quat::rightMult ( const Quat rhs) const

Binary RIGHT multiplication: q = p * rhs ; results in q = p quatmultiply rhs ;.

◆ rotate() [1/4]

Quat MOMENTUM_NAMESPACE::Quat::rotate ( const Vec3 from,
const Vec3 to 
)
static

Static method which constructs and returns a Quaternion from rotating vector from to vector to.

◆ rotate() [2/4]

Quat MOMENTUM_NAMESPACE::Quat::rotate ( double  angle,
const Vec3 vec 
)
static

Static method which constructs and returns a Quaternion from a rotation given as angle radians around the vector vec.

◆ rotate() [3/4]

Quat MOMENTUM_NAMESPACE::Quat::rotate ( double  angle,
double  x,
double  y,
double  z 
)
static

Static method which constructs and returns a Quaternion from a rotation given as angle radians around the vector (x, y, z)

◆ rotate() [4/4]

Quat MOMENTUM_NAMESPACE::Quat::rotate ( double  angle1,
const Vec3 axis1,
double  angle2,
const Vec3 axis2,
double  angle3,
const Vec3 axis3 
)
static

Static method which constructs and returns a Quaternion from a rotation given as a concatenation of the three angle/axis rotations:

this = q1*q2*q3

◆ set() [1/4]

Quat MOMENTUM_NAMESPACE::Quat::set ( const AffineMatrix4x4 matrix)

Set this quaternion with the rotational part of matrix.

Returns
a reference to this updated quaternion.

◆ set() [2/4]

Quat MOMENTUM_NAMESPACE::Quat::set ( const EulerAngles euler)

Set this quaternion with the rotation described by the EulerAngles representation.

Returns
reference to this updated quaternion.

◆ set() [3/4]

void MOMENTUM_NAMESPACE::Quat::set ( const Vec4 v)

Set the four elements of the quaternion as an Vec4.

◆ set() [4/4]

void MOMENTUM_NAMESPACE::Quat::set ( double  x,
double  y,
double  z,
double  w 
)

Set the 4 elements of the quaternion as 4 scalars.

◆ setRotate() [1/4]

void MOMENTUM_NAMESPACE::Quat::setRotate ( const Vec3 from,
const Vec3 to 
)

Make a rotation Quat which will rotate from to to 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.

◆ setRotate() [2/4]

void MOMENTUM_NAMESPACE::Quat::setRotate ( double  angle,
const Vec3 vec 
)

Set the rotation of this Quaternion as a rotation angle radians around the vector vec.

◆ setRotate() [3/4]

void MOMENTUM_NAMESPACE::Quat::setRotate ( double  angle,
double  x,
double  y,
double  z 
)

Set the rotation of the Quaternion as a rotation angle radians around the vector (x, y, z)

◆ setRotate() [4/4]

void MOMENTUM_NAMESPACE::Quat::setRotate ( double  angle1,
const Vec3 axis1,
double  angle2,
const Vec3 axis2,
double  angle3,
const Vec3 axis3 
)

Set the rotation of this Quaternion as a concatenation of the three angle/axis rotations:

this = q1*q2*q3

◆ setW()

double MOMENTUM_NAMESPACE::Quat::setW ( double  val)
Returns
a reference to the scalar (last) element of the quaternion.

◆ setX()

double MOMENTUM_NAMESPACE::Quat::setX ( double  val)
Returns
a reference to the first element of the vector part of the quaternion.

◆ setY()

double MOMENTUM_NAMESPACE::Quat::setY ( double  val)
Returns
a reference to the second element of the vector part of the quaternion.

◆ setZ()

double MOMENTUM_NAMESPACE::Quat::setZ ( double  val)
Returns
a reference to the third element of the vector part of the quaternion.

◆ slerp()

void MOMENTUM_NAMESPACE::Quat::slerp ( double  t,
const Quat from,
const Quat to 
)

Spherical Linear Interpolation.

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

◆ w()

double MOMENTUM_NAMESPACE::Quat::w ( ) const
Returns
the scalar (last) element of the quaternion.

◆ x()

double MOMENTUM_NAMESPACE::Quat::x ( ) const
Returns
the first element of the vector part of the quaternion.

◆ y()

double MOMENTUM_NAMESPACE::Quat::y ( ) const
Returns
the second element of the vector part of the quaternion.

◆ z()

double MOMENTUM_NAMESPACE::Quat::z ( ) const
Returns
the third element of the vector part of the quaternion.

◆ zeroRotation()

bool MOMENTUM_NAMESPACE::Quat::zeroRotation ( ) const
Returns
true if the Quat represents a zero rotation, and therefore can be ignored in computations.