5#ifndef NIRT_QUATERNION_HPP_INCLUDED
6#define NIRT_QUATERNION_HPP_INCLUDED
8#include <nirtcpp/core/engine/nirt_types.hpp>
9#include <nirtcpp/core/engine/irrMath.hpp>
10#include <nirtcpp/core/engine/matrix4.hpp>
11#include <nirtcpp/core/engine/vector3d.hpp>
47#ifndef NIRT_TEST_BROKEN_QUATERNION_USE
58#ifndef NIRT_TEST_BROKEN_QUATERNION_USE
104#ifndef NIRT_TEST_BROKEN_QUATERNION_USE
218#ifndef NIRT_TEST_BROKEN_QUATERNION_USE
238 return !(*
this ==
other);
242#ifndef NIRT_TEST_BROKEN_QUATERNION_USE
253 X = (
m[6] -
m[9]) / scale;
254 Y = (
m[8] -
m[2]) / scale;
255 Z = (
m[1] -
m[4]) / scale;
260 if (
m[0]>
m[5] &&
m[0]>
m[10])
264 const f32 scale =
sqrtf(1.0f +
m[0] -
m[5] -
m[10]) * 2.0f;
268 Y = (
m[4] +
m[1]) / scale;
269 Z = (
m[2] +
m[8]) / scale;
270 W = (
m[6] -
m[9]) / scale;
276 const f32 scale =
sqrtf(1.0f +
m[5] -
m[0] -
m[10]) * 2.0f;
279 X = (
m[4] +
m[1]) / scale;
281 Z = (
m[9] +
m[6]) / scale;
282 W = (
m[8] -
m[2]) / scale;
288 const f32 scale =
sqrtf(1.0f +
m[10] -
m[0] -
m[5]) * 2.0f;
291 X = (
m[8] +
m[2]) / scale;
292 Y = (
m[9] +
m[6]) / scale;
294 W = (
m[1] -
m[4]) / scale;
337 return (*
this =
other * (*
this));
346#ifndef NIRT_TEST_BROKEN_QUATERNION_USE
362 dest[0] = 1.0f - 2.0f*Y*Y - 2.0f*Z*Z;
363 dest[1] = 2.0f*
X*Y + 2.0f*Z*W;
364 dest[2] = 2.0f*
X*Z - 2.0f*Y*W;
367 dest[4] = 2.0f*
X*Y - 2.0f*Z*W;
368 dest[5] = 1.0f - 2.0f*
X*
X - 2.0f*Z*Z;
369 dest[6] = 2.0f*Z*Y + 2.0f*
X*W;
372 dest[8] = 2.0f*
X*Z + 2.0f*Y*W;
373 dest[9] = 2.0f*Z*Y - 2.0f*
X*W;
374 dest[10] = 1.0f - 2.0f*
X*
X - 2.0f*Y*Y;
382 dest.setDefinitelyIdentityMatrix(
false);
401 dest[0] = 1.0f - 2.0f*Y*Y - 2.0f*Z*Z;
402 dest[1] = 2.0f*
X*Y + 2.0f*Z*W;
403 dest[2] = 2.0f*
X*Z - 2.0f*Y*W;
406 dest[4] = 2.0f*
X*Y - 2.0f*Z*W;
407 dest[5] = 1.0f - 2.0f*
X*
X - 2.0f*Z*Z;
408 dest[6] = 2.0f*Z*Y + 2.0f*
X*W;
411 dest[8] = 2.0f*
X*Z + 2.0f*Y*W;
412 dest[9] = 2.0f*Z*Y - 2.0f*
X*W;
413 dest[10] = 1.0f - 2.0f*
X*
X - 2.0f*Y*Y;
421 dest.setDefinitelyIdentityMatrix (
false );
448 dest[0] = 1.0f - 2.0f*Y*Y - 2.0f*Z*Z;
449 dest[1] = 2.0f*
X*Y + 2.0f*Z*W;
450 dest[2] = 2.0f*
X*Z - 2.0f*Y*W;
453 dest[4] = 2.0f*
X*Y - 2.0f*Z*W;
454 dest[5] = 1.0f - 2.0f*
X*
X - 2.0f*Z*Z;
455 dest[6] = 2.0f*Z*Y + 2.0f*
X*W;
458 dest[8] = 2.0f*
X*Z + 2.0f*Y*W;
459 dest[9] = 2.0f*Z*Y - 2.0f*
X*W;
460 dest[10] = 1.0f - 2.0f*
X*
X - 2.0f*Y*Y;
476 dest[0] = 1.0f - 2.0f*Y*Y - 2.0f*Z*Z;
477 dest[4] = 2.0f*
X*Y + 2.0f*Z*W;
478 dest[8] = 2.0f*
X*Z - 2.0f*Y*W;
481 dest[1] = 2.0f*
X*Y - 2.0f*Z*W;
482 dest[5] = 1.0f - 2.0f*
X*
X - 2.0f*Z*Z;
483 dest[9] = 2.0f*Z*Y + 2.0f*
X*W;
486 dest[2] = 2.0f*
X*Z + 2.0f*Y*W;
487 dest[6] = 2.0f*Z*Y - 2.0f*
X*W;
488 dest[10] = 1.0f - 2.0f*
X*
X - 2.0f*Y*Y;
496 dest.setDefinitelyIdentityMatrix(
false);
503 X = -
X; Y = -Y; Z = -Z;
577 return (*
this *= (
f32)reciprocal_squareroot ( (
f64)(
X*
X + Y*Y + Z*Z + W*W) ));
584 return (*
this = (
q1*scale) + (
q2*
time));
622 return (
X *
q2.X) + (Y *
q2.Y) + (Z *
q2.Z) + (W *
q2.W);
704 uv =
qvec.crossProduct(v);
740 if (
axis.getLength()==0)
742 axis.set(0.f,1.f,0.f);
4x4 matrix. Mostly used as transformation matrix for 3d calculations.
Definition matrix4.hpp:49
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
Quaternion class for representing rotations.
Definition quaternion.hpp:32
void toAngleAxis(f32 &angle, core::vector3df &axis) const
Fills an angle (radians) around an axis (unit vector)
Definition quaternion.hpp:639
quaternion & set(f32 x, f32 y, f32 z, f32 w)
Sets new quaternion.
Definition quaternion.hpp:509
quaternion & fromAngleAxis(f32 angle, const vector3df &axis)
Set this quaternion to represent a rotation from angle and axis.
Definition quaternion.hpp:627
quaternion & operator*=(f32 s)
Multiplication operator with scalar.
Definition quaternion.hpp:325
quaternion & rotationFromTo(const vector3df &from, const vector3df &to)
Set quaternion to represent a rotation from one vector to another.
Definition quaternion.hpp:722
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.hpp:563
quaternion(f32 x, f32 y, f32 z, f32 w)
Constructor.
Definition quaternion.hpp:39
quaternion operator+(const quaternion &other) const
Add operator.
Definition quaternion.hpp:341
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.hpp:595
void getMatrix_transposed(matrix4 &dest) const
Creates a matrix from this quaternion.
Definition quaternion.hpp:467
quaternion & makeInverse()
Inverts this quaternion.
Definition quaternion.hpp:501
quaternion operator*(const quaternion &other) const
Definition quaternion.hpp:304
void getMatrixFast(matrix4 &dest) const
Faster method to create a rotation matrix, you should normalize the quaternion before!
Definition quaternion.hpp:357
bool operator==(const quaternion &other) const
Equality operator.
Definition quaternion.hpp:227
matrix4 getMatrix() const
Creates a matrix from this quaternion.
Definition quaternion.hpp:348
quaternion & operator=(const matrix4 &other)
Matrix assignment operator.
Definition quaternion.hpp:244
quaternion & lerpN(quaternion q1, quaternion q2, f32 time)
Set this quaternion to the linear interpolation between two quaternions and normalize the result.
Definition quaternion.hpp:588
quaternion & lerp(quaternion q1, quaternion q2, f32 time)
Set this quaternion to the linear interpolation between two quaternions.
Definition quaternion.hpp:581
void getMatrixCenter(matrix4 &dest, const core::vector3df ¢er, const core::vector3df &translation) const
Definition quaternion.hpp:437
f32 dotProduct(const quaternion &other) const
Calculates the dot product.
Definition quaternion.hpp:620
quaternion()
Default Constructor.
Definition quaternion.hpp:36
void toEuler(vector3df &euler) const
Output this quaternion to an Euler angle (radians)
Definition quaternion.hpp:660
bool operator!=(const quaternion &other) const
inequality operator
Definition quaternion.hpp:236
f32 X
Quaternion elements.
Definition quaternion.hpp:198
quaternion & makeIdentity()
Set quaternion to identity.
Definition quaternion.hpp:713
quaternion & normalize()
Normalizes the quaternion.
Definition quaternion.hpp:573
T Y
Y coordinate of the vector.
Definition vector3d.hpp:453
T X
X coordinate of the vector.
Definition vector3d.hpp:450
T Z
Z coordinate of the vector.
Definition vector3d.hpp:456
bool iszero(const f64 a, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals zero, taking rounding errors into account
Definition irrMath.hpp:304
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition irrMath.hpp:164
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
Definition irrMath.hpp:243
const f64 PI64
Constant for 64bit PI.
Definition irrMath.hpp:66
As of Nirtcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
double f64
64 bit floating point variable.
Definition irrTypes.hpp:114
float f32
32 bit floating point variable.
Definition irrTypes.hpp:110