5 #ifndef __IRR_QUATERNION_H_INCLUDED__ 6 #define __IRR_QUATERNION_H_INCLUDED__ 47 #ifndef IRR_TEST_BROKEN_QUATERNION_USE 61 #ifndef IRR_TEST_BROKEN_QUATERNION_USE 107 #ifndef IRR_TEST_BROKEN_QUATERNION_USE 220 #ifndef IRR_TEST_BROKEN_QUATERNION_USE 231 return ((
X == other.
X) &&
240 return !(*
this == other);
253 #ifndef IRR_TEST_BROKEN_QUATERNION_USE 257 const f32 diag =
m[0] +
m[5] +
m[10] + 1;
261 const f32 scale = sqrtf(diag) * 2.0f;
271 if (
m[0]>
m[5] &&
m[0]>
m[10])
275 const f32 scale = sqrtf(1.0
f +
m[0] -
m[5] -
m[10]) * 2.0f;
287 const f32 scale = sqrtf(1.0
f +
m[5] -
m[0] -
m[10]) * 2.0f;
299 const f32 scale = sqrtf(1.0
f +
m[10] -
m[0] -
m[5]) * 2.0f;
319 tmp.
W = (other.
W *
W) - (other.
X *
X) - (other.
Y *
Y) - (other.
Z *
Z);
320 tmp.
X = (other.
W *
X) + (other.
X *
W) + (other.
Y *
Z) - (other.
Z *
Y);
321 tmp.
Y = (other.
W *
Y) + (other.
Y *
W) + (other.
Z *
X) - (other.
X *
Z);
322 tmp.
Z = (other.
W *
Z) + (other.
Z *
W) + (other.
X *
Y) - (other.
Y *
X);
348 return (*
this = other * (*
this));
357 #ifndef IRR_TEST_BROKEN_QUATERNION_USE 373 dest[0] = 1.0f - 2.0f*
Y*
Y - 2.0f*
Z*
Z;
374 dest[1] = 2.0f*
X*
Y + 2.0f*
Z*
W;
375 dest[2] = 2.0f*
X*
Z - 2.0f*
Y*
W;
378 dest[4] = 2.0f*
X*
Y - 2.0f*
Z*
W;
379 dest[5] = 1.0f - 2.0f*
X*
X - 2.0f*
Z*
Z;
380 dest[6] = 2.0f*
Z*
Y + 2.0f*
X*
W;
383 dest[8] = 2.0f*
X*
Z + 2.0f*
Y*
W;
384 dest[9] = 2.0f*
Z*
Y - 2.0f*
X*
W;
385 dest[10] = 1.0f - 2.0f*
X*
X - 2.0f*
Y*
Y;
412 dest[0] = 1.0f - 2.0f*
Y*
Y - 2.0f*
Z*
Z;
413 dest[1] = 2.0f*
X*
Y + 2.0f*
Z*
W;
414 dest[2] = 2.0f*
X*
Z - 2.0f*
Y*
W;
417 dest[4] = 2.0f*
X*
Y - 2.0f*
Z*
W;
418 dest[5] = 1.0f - 2.0f*
X*
X - 2.0f*
Z*
Z;
419 dest[6] = 2.0f*
Z*
Y + 2.0f*
X*
W;
422 dest[8] = 2.0f*
X*
Z + 2.0f*
Y*
W;
423 dest[9] = 2.0f*
Z*
Y - 2.0f*
X*
W;
424 dest[10] = 1.0f - 2.0f*
X*
X - 2.0f*
Y*
Y;
459 dest[0] = 1.0f - 2.0f*
Y*
Y - 2.0f*
Z*
Z;
460 dest[1] = 2.0f*
X*
Y + 2.0f*
Z*
W;
461 dest[2] = 2.0f*
X*
Z - 2.0f*
Y*
W;
464 dest[4] = 2.0f*
X*
Y - 2.0f*
Z*
W;
465 dest[5] = 1.0f - 2.0f*
X*
X - 2.0f*
Z*
Z;
466 dest[6] = 2.0f*
Z*
Y + 2.0f*
X*
W;
469 dest[8] = 2.0f*
X*
Z + 2.0f*
Y*
W;
470 dest[9] = 2.0f*
Z*
Y - 2.0f*
X*
W;
471 dest[10] = 1.0f - 2.0f*
X*
X - 2.0f*
Y*
Y;
487 dest[0] = 1.0f - 2.0f*
Y*
Y - 2.0f*
Z*
Z;
488 dest[4] = 2.0f*
X*
Y + 2.0f*
Z*
W;
489 dest[8] = 2.0f*
X*
Z - 2.0f*
Y*
W;
492 dest[1] = 2.0f*
X*
Y - 2.0f*
Z*
W;
493 dest[5] = 1.0f - 2.0f*
X*
X - 2.0f*
Z*
Z;
494 dest[9] = 2.0f*
Z*
Y + 2.0f*
X*
W;
497 dest[2] = 2.0f*
X*
Z + 2.0f*
Y*
W;
498 dest[6] = 2.0f*
Z*
Y - 2.0f*
X*
W;
499 dest[10] = 1.0f - 2.0f*
X*
X - 2.0f*
Y*
Y;
547 const f64 cpcy = cp * cy;
548 const f64 spcy = sp * cy;
549 const f64 cpsy = cp * sy;
550 const f64 spsy = sp * sy;
552 X = (
f32)(sr * cpcy - cr * spsy);
553 Y = (
f32)(cr * spcy + sr * cpsy);
554 Z = (
f32)(cr * cpsy - sr * spcy);
555 W = (
f32)(cr * cpcy + sr * spsy);
563 return set( vec.
X, vec.
Y, vec.
Z);
595 return (*
this = (q1*
scale) + (q2*time));
617 if (
angle <= (1-threshold))
621 const f32 scale = sinf(theta * (1.0
f-time)) * invsintheta;
622 const f32 invscale = sinf(theta * time) * invsintheta;
623 return (*
this = (q1*
scale) + (q2*invscale));
626 return lerpN(q1,q2,time);
633 return (
X * q2.
X) + (
Y * q2.
Y) + (
Z * q2.
Z) + (
W * q2.
W);
641 const f32 fSin = sinf(fHalfAngle);
642 W = cosf(fHalfAngle);
665 axis.
X =
X * invscale;
666 axis.
Y =
Y * invscale;
667 axis.
Z =
Z * invscale;
677 const f64 test = 2.0 * (
Y*
W -
X*
Z);
682 euler.
Z = (
f32) (-2.0*atan2(
X,
W));
691 euler.
Z = (
f32) (2.0*atan2(
X,
W));
700 euler.
Z = (
f32) atan2(2.0 * (
X*
Y +
Z*
W),(sqx - sqy - sqz + sqw));
702 euler.
X = (
f32) atan2(2.0 * (
Y*
Z +
X*
W),(-sqx - sqy + sqz + sqw));
704 euler.
Y = (
f32) asin(
clamp(test, -1.0, 1.0) );
760 const f32 s = sqrtf( (1+d)*2 );
761 const f32 invs = 1.f /
s;
GLenum GLenum GLenum GLenum GLenum scale
f32 dotProduct(const quaternion &other) const
Calculates the dot product.
vector3d< T > crossProduct(const vector3d< T > &p) const
Calculates the cross product with another vector.
quaternion & makeIdentity()
Set quaternion to identity.
void toEuler(vector3df &euler) const
Output this quaternion to an Euler angle (radians)
const f64 PI64
Constant for 64bit PI.
T Y
Y coordinate of the vector.
bool iszero(const f64 a, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals zero, taking rounding errors into account
void getMatrixFast(matrix4 &dest) const
Faster method to create a rotation matrix, you should normalize the quaternion before!
void setDefinitelyIdentityMatrix(bool isDefinitelyIdentityMatrix)
Sets if the matrix is definitely identity matrix.
float f32
32 bit floating point variable.
GLdouble GLdouble GLdouble GLdouble q
void toAngleAxis(f32 &angle, core::vector3df &axis) const
Fills an angle (radians) around an axis (unit vector)
void setRotationCenter(const core::vector3df ¢er, const core::vector3df &translate)
Builds a combined matrix which translates to a center before rotation and translates from origin afte...
T X
X coordinate of the vector.
quaternion & normalize()
Normalizes the quaternion.
vector3d< T > & set(const T nx, const T ny, const T nz)
Everything in the Irrlicht Engine can be found in this namespace.
bool operator==(const quaternion &other) const
Equality operator.
quaternion & operator *=(f32 s)
Multiplication operator with scalar.
quaternion(f32 x, f32 y, f32 z, f32 w)
Constructor.
double f64
64 bit floating point variable.
quaternion operator *(const quaternion &other) const
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
const f32 ROUNDING_ERROR_f32
bool operator!=(const quaternion &other) const
inequality operator
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
quaternion operator+(const quaternion &other) const
Add operator.
REALINLINE f32 reciprocal(const f32 f)
quaternion & fromAngleAxis(f32 angle, const vector3df &axis)
Set this quaternion to represent a rotation from angle and axis.
f32 X
Quaternion elements.
GLint GLint GLint GLint GLint GLint y
void getMatrix_transposed(matrix4 &dest) const
Creates a matrix from this quaternion.
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 & rotationFromTo(const vector3df &from, const vector3df &to)
Set quaternion to represent a rotation from one vector to another.
void getMatrixCenter(matrix4 &dest, const core::vector3df ¢er, const core::vector3df &translation) const
vector3d< T > & normalize()
Normalizes the vector.
4x4 matrix. Mostly used as transformation matrix for 3d calculations.
T dotProduct(const vector3d< T > &other) const
Get the dot product with another vector.
quaternion & operator=(const quaternion &other)
Assignment operator.
GLboolean GLboolean GLboolean b
matrix4 getMatrix() const
Creates a matrix from this quaternion.
GLint GLint GLint GLint GLint x
T Z
Z coordinate of the vector.
Quaternion class for representing rotations.
quaternion & lerpN(quaternion q1, quaternion q2, f32 time)
Set this quaternion to the linear interpolation between two quaternions and normalize the result.
GLubyte GLubyte GLubyte GLubyte w
T getLength() const
Get length of the vector.
REALINLINE f64 reciprocal_squareroot(const f64 x)
quaternion & makeInverse()
Inverts this quaternion.
quaternion & set(f32 x, f32 y, f32 z, f32 w)
Sets new quaternion.
quaternion()
Default Constructor.
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
quaternion & lerp(quaternion q1, quaternion q2, f32 time)
Set this quaternion to the linear interpolation between two quaternions.