![]() |
Duckcpp 2.1.0
Duckcpp is a high-performance c++ graphics engine.
|
Quaternion class for representing rotations. More...
#include <duckcpp/core/engine/quaternion.hpp>
Public Member Functions | |
quaternion () | |
Default Constructor. | |
quaternion (dcpp::float32_kt x, dcpp::float32_kt y, dcpp::float32_kt z, dcpp::float32_kt w) | |
Constructor. | |
quaternion (dcpp::float32_kt x, dcpp::float32_kt y, dcpp::float32_kt 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* (dcpp::float32_kt s) const |
Multiplication operator with scalar. | |
quaternion & | operator*= (dcpp::float32_kt s) |
Multiplication operator with scalar. | |
vector3df | operator* (const vector3df &v) const |
Multiplication operator. | |
quaternion & | operator*= (const quaternion &other) |
Multiplication operator. | |
dcpp::float32_kt | dotProduct (const quaternion &other) const |
Calculates the dot product. | |
quaternion & | set (dcpp::float32_kt x, dcpp::float32_kt y, dcpp::float32_kt z, dcpp::float32_kt w) |
Sets new quaternion. | |
quaternion & | set (dcpp::float32_kt x, dcpp::float32_kt y, dcpp::float32_kt z) |
Sets new quaternion based on Euler angles (radians) | |
quaternion & | set (const dcpp::nub::vector3df &vec) |
Sets new quaternion based on Euler angles (radians) | |
quaternion & | set (const dcpp::nub::quaternion &quat) |
Sets new quaternion from other quaternion. | |
bool | equals (const quaternion &other, const dcpp::float32_kt tolerance=ROUNDING_ERROR_Float32) 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 dcpp::nub::vector3df &translation=dcpp::nub::vector3df()) const |
Creates a matrix from this quaternion. | |
void | getMatrixCenter (matrix4 &dest, const dcpp::nub::vector3df ¢er, const dcpp::nub::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, dcpp::float32_kt time) |
Set this quaternion to the linear interpolation between two quaternions. | |
quaternion & | lerpN (quaternion q1, quaternion q2, dcpp::float32_kt time) |
Set this quaternion to the linear interpolation between two quaternions and normalize the result. | |
quaternion & | slerp (quaternion q1, quaternion q2, dcpp::float32_kt time, dcpp::float32_kt threshold=.05f) |
Set this quaternion to the result of the spherical interpolation between two quaternions. | |
quaternion & | fromAngleAxis (dcpp::float32_kt angle, const vector3df &axis) |
Set this quaternion to represent a rotation from angle and axis. | |
void | toAngleAxis (dcpp::float32_kt &angle, dcpp::nub::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 | |
dcpp::float32_kt | X |
Quaternion elements. | |
dcpp::float32_kt | Y |
dcpp::float32_kt | Z |
dcpp::float32_kt | 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 dcpp::nub::quaternion q; q.rotationFromTo ( vin[i].Normal, forward ); q.getMatrixCenter ( lookat, center, newPos );
dcpp::nub::matrix4 m2; m2.setInverseTranslation ( center ); lookat *= m2;
dcpp::nub::matrix4 m3; m2.setTranslation ( newPos ); lookat *= m3;
Creates a matrix from this quaternion Rotate about a center point shortcut for dcpp::nub::quaternion q; q.rotationFromTo(vin[i].Normal, forward); q.getMatrix(lookat, center);
dcpp::nub::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 PMatrix4::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. |