Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
|
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 | |
quaternion & | operator= (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. | |
quaternion & | operator*= (f32 s) |
Multiplication operator with scalar. | |
vector3df | operator* (const vector3df &v) const |
Multiplication operator. | |
quaternion & | operator*= (const quaternion &other) |
Multiplication operator. | |
f32 | dotProduct (const quaternion &other) const |
Calculates the dot product. | |
quaternion & | set (f32 x, f32 y, f32 z, f32 w) |
Sets new quaternion. | |
quaternion & | set (f32 x, f32 y, f32 z) |
Sets new quaternion based on Euler angles (radians) | |
quaternion & | set (const core::vector3df &vec) |
Sets new quaternion based on Euler angles (radians) | |
quaternion & | set (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 | |
quaternion & | normalize () |
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 ¢er, const core::vector3df &translation) const |
void | getMatrix_transposed (matrix4 &dest) const |
Creates a matrix from this quaternion. | |
quaternion & | makeInverse () |
Inverts this quaternion. | |
quaternion & | lerp (quaternion q1, quaternion q2, f32 time) |
Set this quaternion to the linear interpolation between two quaternions. | |
quaternion & | lerpN (quaternion q1, quaternion q2, f32 time) |
Set this quaternion to the linear interpolation between two quaternions and normalize the result. | |
quaternion & | slerp (quaternion q1, quaternion q2, f32 time, f32 threshold=.05f) |
Set this quaternion to the result of the spherical interpolation between two quaternions. | |
quaternion & | fromAngleAxis (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) | |
quaternion & | makeIdentity () |
Set quaternion to identity. | |
quaternion & | rotationFromTo (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 |
Quaternion class for representing rotations.
It provides cheap combinations and avoids gimbal locks. Also useful for interpolations.
|
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).
angle | Rotation Angle in radians. |
axis | Rotation axis. |
|
inline |
Creates a matrix from this quaternion.
Creates a matrix from this quaternion
|
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;
|
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.
q1 | First quaternion to be interpolated. |
q2 | Second quaternion to be interpolated. |
time | Progress 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. |
|
inline |
Set this quaternion to the linear interpolation between two quaternions and normalize the result.
q1 | First quaternion to be interpolated. |
q2 | Second quaternion to be interpolated. |
time | Progress 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. |
|
inline |
Multiplication operator Be careful, unfortunately the operator order here is opposite of that in CMatrix4::operator*
|
inline |
Set this quaternion to the result of the spherical interpolation between two quaternions.
q1 | First quaternion to be interpolated. |
q2 | Second quaternion to be interpolated. |
time | Progress of interpolation. For time=0 the result is q1, for time=1 the result is q2. Otherwise interpolation between q1 and q2. |
threshold | To 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. |