5#ifndef __IRR_QUATERNION_H_INCLUDED__
6#define __IRR_QUATERNION_H_INCLUDED__
16#define IRR_TEST_BROKEN_QUATERNION_USE 0
42#if !IRR_TEST_BROKEN_QUATERNION_USE
56#if !IRR_TEST_BROKEN_QUATERNION_USE
96 const f32 tolerance = ROUNDING_ERROR_f32 )
const;
101#if !IRR_TEST_BROKEN_QUATERNION_USE
157 f32 time,
f32 threshold=.05f);
200#if !IRR_TEST_BROKEN_QUATERNION_USE
211 return ((
X == other.
X) &&
220 return !(*
this == other);
233#if !IRR_TEST_BROKEN_QUATERNION_USE
237 const f32 diag = m[0] + m[5] + m[10] + 1;
241 const f32 scale = sqrtf(diag) * 2.0f;
244 X = (m[6] - m[9]) / scale;
245 Y = (m[8] - m[2]) / scale;
246 Z = (m[1] - m[4]) / scale;
251 if (m[0]>m[5] && m[0]>m[10])
255 const f32 scale = sqrtf(1.0f + m[0] - m[5] - m[10]) * 2.0f;
259 Y = (m[4] + m[1]) / scale;
260 Z = (m[2] + m[8]) / scale;
261 W = (m[6] - m[9]) / scale;
267 const f32 scale = sqrtf(1.0f + m[5] - m[0] - m[10]) * 2.0f;
270 X = (m[4] + m[1]) / scale;
272 Z = (m[9] + m[6]) / scale;
273 W = (m[8] - m[2]) / scale;
279 const f32 scale = sqrtf(1.0f + m[10] - m[0] - m[5]) * 2.0f;
282 X = (m[8] + m[2]) / scale;
283 Y = (m[9] + m[6]) / scale;
285 W = (m[1] - m[4]) / scale;
299 tmp.W = (other.W * W) - (other.
X *
X) - (other.Y * Y) - (other.Z * Z);
300 tmp.
X = (other.W *
X) + (other.
X * W) + (other.Y * Z) - (other.Z * Y);
301 tmp.Y = (other.W * Y) + (other.Y * W) + (other.Z *
X) - (other.
X * Z);
302 tmp.Z = (other.W * Z) + (other.Z * W) + (other.
X * Y) - (other.Y *
X);
328 return (*
this = other * (*
this));
337#if !IRR_TEST_BROKEN_QUATERNION_USE
354 m[0] = 1.0f - 2.0f*Y*Y - 2.0f*Z*Z;
355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*
X*
X - 2.0f*Z*Z;
450 dest[9] = 2.0f*Z*Y + 2.0f*
X*W;
453 dest[2] = 2.0f*
X*Z + 2.0f*Y*W;
454 dest[6] = 2.0f*Z*Y - 2.0f*
X*W;
455 dest[10] = 1.0f - 2.0f*
X*
X - 2.0f*Y*Y;
470 X = -
X; Y = -Y; Z = -Z;
492 const f64 sr = sin(angle);
493 const f64 cr = cos(angle);
496 const f64 sp = sin(angle);
497 const f64 cp = cos(angle);
500 const f64 sy = sin(angle);
501 const f64 cy = cos(angle);
503 const f64 cpcy = cp * cy;
504 const f64 spcy = sp * cy;
505 const f64 cpsy = cp * sy;
506 const f64 spsy = sp * sy;
508 X = (
f32)(sr * cpcy - cr * spsy);
509 Y = (
f32)(cr * spcy + sr * cpsy);
510 Z = (
f32)(cr * cpsy - sr * spcy);
511 W = (
f32)(cr * cpcy + sr * spsy);
519 return set(vec.
X, vec.
Y, vec.
Z);
542 const f32 n =
X*
X + Y*Y + Z*Z + W*W;
548 return (*
this *= reciprocal_squareroot ( n ));
555 const f32 scale = 1.0f - time;
556 return (*
this = (q1*scale) + (q2*time));
572 if (angle <= (1-threshold))
574 const f32 theta = acosf(angle);
575 const f32 invsintheta = reciprocal(sinf(theta));
576 const f32 scale = sinf(theta * (1.0f-time)) * invsintheta;
577 const f32 invscale = sinf(theta * time) * invsintheta;
578 return (*
this = (q1*scale) + (q2*invscale));
581 return lerp(q1,q2,time);
588 return (
X * q2.
X) + (Y * q2.Y) + (Z * q2.Z) + (W * q2.W);
595 const f32 fHalfAngle = 0.5f*angle;
596 const f32 fSin = sinf(fHalfAngle);
597 W = cosf(fHalfAngle);
607 const f32 scale = sqrtf(
X*
X + Y*Y + Z*Z);
618 const f32 invscale = reciprocal(scale);
619 angle = 2.0f * acosf(W);
620 axis.
X =
X * invscale;
621 axis.
Y = Y * invscale;
622 axis.
Z = Z * invscale;
632 const f64 test = 2.0 * (Y*W -
X*Z);
637 euler.
Z = (
f32) (-2.0*atan2(
X, W));
646 euler.
Z = (
f32) (2.0*atan2(
X, W));
655 euler.
Z = (
f32) atan2(2.0 * (
X*Y +Z*W),(sqx - sqy - sqz + sqw));
657 euler.
X = (
f32) atan2(2.0 * (Y*Z +
X*W),(-sqx - sqy + sqz + sqw));
659 euler.
Y = (
f32) asin(
clamp(test, -1.0, 1.0) );
717 axis.set(0.f,1.f,0.f);
724 const f32 s = sqrtf( (1+d)*2 );
725 const f32 invs = 1.f / s;
const T * pointer() const
Returns pointer to internal array.
Definition matrix4.h:99
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...
Definition matrix4.h:2049
void setDefinitelyIdentityMatrix(bool isDefinitelyIdentityMatrix)
Sets if the matrix is definitely identity matrix.
Definition matrix4.h:2196
Quaternion class for representing rotations.
Definition quaternion.h:27
quaternion & operator=(const quaternion &other)
Assignment operator.
Definition quaternion.h:224
f32 dotProduct(const quaternion &other) const
Calculates the dot product.
Definition quaternion.h:586
matrix4 getMatrix() const
Creates a matrix from this quaternion.
Definition quaternion.h:339
quaternion & makeInverse()
Inverts this quaternion.
Definition quaternion.h:468
quaternion & makeIdentity()
Set quaternion to identity.
Definition quaternion.h:688
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
Definition quaternion.h:530
quaternion & set(f32 x, f32 y, f32 z, f32 w)
Sets new quaternion.
Definition quaternion.h:476
bool operator!=(const quaternion &other) const
inequality operator
Definition quaternion.h:218
void toEuler(vector3df &euler) const
Output this quaternion to an euler angle (radians).
Definition quaternion.h:626
f32 X
Quaternion elements.
Definition quaternion.h:180
bool operator==(const quaternion &other) const
Equalilty operator.
Definition quaternion.h:209
quaternion & lerp(quaternion q1, quaternion q2, f32 time)
Set this quaternion to the linear interpolation between two quaternions.
Definition quaternion.h:553
quaternion(f32 x, f32 y, f32 z, f32 w)
Constructor.
Definition quaternion.h:34
quaternion operator+(const quaternion &other) const
Add operator.
Definition quaternion.h:332
void toAngleAxis(f32 &angle, core::vector3df &axis) const
Fills an angle (radians) around an axis (unit vector).
Definition quaternion.h:605
quaternion & slerp(quaternion q1, quaternion q2, f32 time, f32 threshold=.05f)
Set this quaternion to the result of the spherical interpolation between two quaternions.
Definition quaternion.h:561
quaternion & operator*=(f32 s)
Multiplication operator with scalar.
Definition quaternion.h:316
quaternion & rotationFromTo(const vector3df &from, const vector3df &to)
Set quaternion to represent a rotation from one vector to another.
Definition quaternion.h:697
quaternion & normalize()
Normalizes the quaternion.
Definition quaternion.h:540
void getMatrixCenter(matrix4 &dest, const core::vector3df ¢er, const core::vector3df &translation) const
Definition quaternion.h:418
quaternion & fromAngleAxis(f32 angle, const vector3df &axis)
Create quaternion from rotation angle and rotation axis.
Definition quaternion.h:593
void getMatrix_transposed(matrix4 &dest) const
Creates a matrix from this quaternion.
Definition quaternion.h:441
quaternion operator*(const quaternion &other) const
Multiplication operator.
Definition quaternion.h:295
quaternion()
Default Constructor.
Definition quaternion.h:31
vector3d< T > crossProduct(const vector3d< T > &p) const
Calculates the cross product with another vector.
Definition vector3d.h:147
T getLength() const
Get length of the vector.
Definition vector3d.h:117
T X
X coordinate of the vector.
Definition vector3d.h:408
vector3d< T > & normalize()
Normalizes the vector.
Definition vector3d.h:168
T Z
Z coordinate of the vector.
Definition vector3d.h:414
T dotProduct(const vector3d< T > &other) const
Get the dot product with another vector.
Definition vector3d.h:125
T Y
Y coordinate of the vector.
Definition vector3d.h:411
Basic classes such as vectors, planes, arrays, lists, and so on can be found in this namespace.
Definition aabbox3d.h:15
vector3d< f32 > vector3df
Typedef for a f32 3d vector.
Definition vector3d.h:445
const f64 PI64
Constant for 64bit PI.
Definition irrMath.h:68
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition irrMath.h:166
CMatrix4< f32 > matrix4
Typedef for f32 matrix.
Definition matrix4.h:2241
bool equals(const f64 a, const f64 b, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals b, taking possible rounding errors into account
Definition irrMath.h:185
bool iszero(const f64 a, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals zero, taking rounding errors into account
Definition irrMath.h:270
Everything in the Irrlicht Engine can be found in this namespace.
Definition Skylicht.h:33
float f32
32 bit floating point variable.
Definition irrTypes.h:104
double f64
64 bit floating point variable.
Definition irrTypes.h:108