Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
nirt::core::quaternion Class Reference

Quaternion class for representing rotations. More...

#include <nirtcpp/core/engine/quaternion.hpp>

Public Member Functions

 quaternion ()
 Default Constructor.
 
 quaternion (f32 x, f32 y, f32 z, f32 w)
 Constructor.
 
 quaternion (f32 x, f32 y, f32 z)
 Constructor which converts Euler angles (radians) to a quaternion.
 
 quaternion (const vector3df &vec)
 Constructor which converts Euler angles (radians) to a quaternion.
 
 quaternion (const matrix4 &mat)
 Constructor which converts a matrix to a quaternion.
 
bool operator== (const quaternion &other) const
 Equality operator.
 
bool operator!= (const quaternion &other) const
 inequality operator
 
quaternionoperator= (const matrix4 &other)
 Matrix assignment operator.
 
quaternion operator+ (const quaternion &other) const
 Add operator.
 
quaternion operator* (const quaternion &other) const
 
quaternion operator* (f32 s) const
 Multiplication operator with scalar.
 
quaternionoperator*= (f32 s)
 Multiplication operator with scalar.
 
vector3df operator* (const vector3df &v) const
 Multiplication operator.
 
quaternionoperator*= (const quaternion &other)
 Multiplication operator.
 
f32 dotProduct (const quaternion &other) const
 Calculates the dot product.
 
quaternionset (f32 x, f32 y, f32 z, f32 w)
 Sets new quaternion.
 
quaternionset (f32 x, f32 y, f32 z)
 Sets new quaternion based on Euler angles (radians)
 
quaternionset (const core::vector3df &vec)
 Sets new quaternion based on Euler angles (radians)
 
quaternionset (const core::quaternion &quat)
 Sets new quaternion from other quaternion.
 
bool equals (const quaternion &other, const f32 tolerance=ROUNDING_ERROR_f32) const
 returns if this quaternion equals the other one, taking floating point rounding errors into account
 
quaternionnormalize ()
 Normalizes the quaternion.
 
matrix4 getMatrix () const
 Creates a matrix from this quaternion.
 
void getMatrixFast (matrix4 &dest) const
 Faster method to create a rotation matrix, you should normalize the quaternion before!
 
void getMatrix (matrix4 &dest, const core::vector3df &translation=core::vector3df()) const
 Creates a matrix from this quaternion.
 
void getMatrixCenter (matrix4 &dest, const core::vector3df &center, const core::vector3df &translation) const
 
void getMatrix_transposed (matrix4 &dest) const
 Creates a matrix from this quaternion.
 
quaternionmakeInverse ()
 Inverts this quaternion.
 
quaternionlerp (quaternion q1, quaternion q2, f32 time)
 Set this quaternion to the linear interpolation between two quaternions.
 
quaternionlerpN (quaternion q1, quaternion q2, f32 time)
 Set this quaternion to the linear interpolation between two quaternions and normalize the result.
 
quaternionslerp (quaternion q1, quaternion q2, f32 time, f32 threshold=.05f)
 Set this quaternion to the result of the spherical interpolation between two quaternions.
 
quaternionfromAngleAxis (f32 angle, const vector3df &axis)
 Set this quaternion to represent a rotation from angle and axis.
 
void toAngleAxis (f32 &angle, core::vector3df &axis) const
 Fills an angle (radians) around an axis (unit vector)
 
void toEuler (vector3df &euler) const
 Output this quaternion to an Euler angle (radians)
 
quaternionmakeIdentity ()
 Set quaternion to identity.
 
quaternionrotationFromTo (const vector3df &from, const vector3df &to)
 Set quaternion to represent a rotation from one vector to another.
 

Public Attributes

f32 X
 Quaternion elements.
 
f32 Y
 
f32 Z
 
f32 W
 

Detailed Description

Quaternion class for representing rotations.

It provides cheap combinations and avoids gimbal locks. Also useful for interpolations.

Member Function Documentation

◆ fromAngleAxis()

quaternion & nirt::core::quaternion::fromAngleAxis ( f32  angle,
const vector3df axis 
)
inline

Set this quaternion to represent a rotation from angle and axis.

axis must be unit length, angle in radians

Axis must be unit length. The quaternion representing the rotation is q = cos(A/2)+sin(A/2)*(x*i+y*j+z*k).

Parameters
angleRotation Angle in radians.
axisRotation axis.

◆ getMatrix()

void nirt::core::quaternion::getMatrix ( matrix4 dest,
const core::vector3df center = core::vector3df() 
) const
inline

Creates a matrix from this quaternion.

Creates a matrix from this quaternion

◆ getMatrixCenter()

void nirt::core::quaternion::getMatrixCenter ( matrix4 dest,
const core::vector3df center,
const core::vector3df translation 
) const
inline

Creates a matrix from this quaternion Rotate about a center point shortcut for core::quaternion q; q.rotationFromTo ( vin[i].Normal, forward ); q.getMatrixCenter ( lookat, center, newPos );

core::matrix4 m2; m2.setInverseTranslation ( center ); lookat *= m2;

core::matrix4 m3; m2.setTranslation ( newPos ); lookat *= m3;

Creates a matrix from this quaternion Rotate about a center point shortcut for core::quaternion q; q.rotationFromTo(vin[i].Normal, forward); q.getMatrix(lookat, center);

core::matrix4 m2; m2.setInverseTranslation(center); lookat *= m2;

◆ lerp()

quaternion & nirt::core::quaternion::lerp ( quaternion  q1,
quaternion  q2,
f32  time 
)
inline

Set this quaternion to the linear interpolation between two quaternions.

NOTE: lerp result is not a normalized quaternion. In most cases you will want to use lerpN instead as most other quaternion functions expect to work with a normalized quaternion.

Parameters
q1First quaternion to be interpolated.
q2Second quaternion to be interpolated.
timeProgress of interpolation. For time=0 the result is q1, for time=1 the result is q2. Otherwise interpolation between q1 and q2. Result is not normalized.

◆ lerpN()

quaternion & nirt::core::quaternion::lerpN ( quaternion  q1,
quaternion  q2,
f32  time 
)
inline

Set this quaternion to the linear interpolation between two quaternions and normalize the result.

Parameters
q1First quaternion to be interpolated.
q2Second quaternion to be interpolated.
timeProgress of interpolation. For time=0 the result is q1, for time=1 the result is q2. Otherwise interpolation between q1 and q2. Result is normalized.

◆ operator*()

quaternion nirt::core::quaternion::operator* ( const quaternion other) const
inline

Multiplication operator Be careful, unfortunately the operator order here is opposite of that in CMatrix4::operator*

◆ slerp()

quaternion & nirt::core::quaternion::slerp ( quaternion  q1,
quaternion  q2,
f32  time,
f32  threshold = .05f 
)
inline

Set this quaternion to the result of the spherical interpolation between two quaternions.

Parameters
q1First quaternion to be interpolated.
q2Second quaternion to be interpolated.
timeProgress of interpolation. For time=0 the result is q1, for time=1 the result is q2. Otherwise interpolation between q1 and q2.
thresholdTo avoid inaccuracies at the end (time=1) the interpolation switches to linear interpolation at some point. This value defines how much of the remaining interpolation will be calculated with lerp. Everything from 1-threshold up will be linear interpolation.

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

Nirtcpp    @cppfx.xyz

Utxcpp    utx::print