arsa  2.7
quaternion.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
4 
5 #ifndef __IRR_QUATERNION_H_INCLUDED__
6 #define __IRR_QUATERNION_H_INCLUDED__
7 
8 #include "irrTypes.h"
9 #include "irrMath.h"
10 #include "matrix4.h"
11 #include "vector3d.h"
12 
13 // NOTE: You *only* need this when updating an application from Irrlicht before 1.8 to Irrlicht 1.8 or later.
14 // Between Irrlicht 1.7 and Irrlicht 1.8 the quaternion-matrix conversions changed.
15 // Before the fix they had mixed left- and right-handed rotations.
16 // To test if your code was affected by the change enable IRR_TEST_BROKEN_QUATERNION_USE and try to compile your application.
17 // This defines removes those functions so you get compile errors anywhere you use them in your code.
18 // For every line with a compile-errors you have to change the corresponding lines like that:
19 // - When you pass the matrix to the quaternion constructor then replace the matrix by the transposed matrix.
20 // - For uses of getMatrix() you have to use quaternion::getMatrix_transposed instead.
21 // #define IRR_TEST_BROKEN_QUATERNION_USE
22 
23 namespace irr
24 {
25 namespace core
26 {
27 
29 
32 {
33  public:
34 
36  quaternion() : X(0.0f), Y(0.0f), Z(0.0f), W(1.0f) {}
37 
39  quaternion(f32 x, f32 y, f32 z, f32 w) : X(x), Y(y), Z(z), W(w) { }
40 
42  quaternion(f32 x, f32 y, f32 z);
43 
45  quaternion(const vector3df& vec);
46 
47 #ifndef IRR_TEST_BROKEN_QUATERNION_USE
48  quaternion(const matrix4& mat);
50 #endif
51 
53  bool operator==(const quaternion& other) const;
54 
56  bool operator!=(const quaternion& other) const;
57 
59  inline quaternion& operator=(const quaternion& other);
60 
61 #ifndef IRR_TEST_BROKEN_QUATERNION_USE
62  inline quaternion& operator=(const matrix4& other);
64 #endif
65 
67  quaternion operator+(const quaternion& other) const;
68 
71  quaternion operator*(const quaternion& other) const;
72 
74  quaternion operator*(f32 s) const;
75 
78 
80  vector3df operator*(const vector3df& v) const;
81 
83  quaternion& operator*=(const quaternion& other);
84 
86  inline f32 dotProduct(const quaternion& other) const;
87 
89  inline quaternion& set(f32 x, f32 y, f32 z, f32 w);
90 
92  inline quaternion& set(f32 x, f32 y, f32 z);
93 
95  inline quaternion& set(const core::vector3df& vec);
96 
98  inline quaternion& set(const core::quaternion& quat);
99 
101  inline bool equals(const quaternion& other,
102  const f32 tolerance = ROUNDING_ERROR_f32 ) const;
103 
105  inline quaternion& normalize();
106 
107 #ifndef IRR_TEST_BROKEN_QUATERNION_USE
108  matrix4 getMatrix() const;
110 #endif
111  void getMatrixFast(matrix4 &dest) const;
113 
115  void getMatrix( matrix4 &dest, const core::vector3df &translation=core::vector3df() ) const;
116 
134  void getMatrixCenter( matrix4 &dest, const core::vector3df &center, const core::vector3df &translation ) const;
135 
137  inline void getMatrix_transposed( matrix4 &dest ) const;
138 
141 
143 
152  quaternion& lerp(quaternion q1, quaternion q2, f32 time);
153 
155 
162  quaternion& lerpN(quaternion q1, quaternion q2, f32 time);
163 
165 
177  f32 time, f32 threshold=.05f);
178 
180 
185  quaternion& fromAngleAxis (f32 angle, const vector3df& axis);
186 
188  void toAngleAxis (f32 &angle, core::vector3df& axis) const;
189 
191  void toEuler(vector3df& euler) const;
192 
195 
197  quaternion& rotationFromTo(const vector3df& from, const vector3df& to);
198 
200  f32 X; // vectorial (imaginary) part
203  f32 W; // real part
204 };
205 
206 
207 // Constructor which converts Euler angles to a quaternion
209 {
210  set(x,y,z);
211 }
212 
213 
214 // Constructor which converts Euler angles to a quaternion
216 {
217  set(vec.X,vec.Y,vec.Z);
218 }
219 
220 #ifndef IRR_TEST_BROKEN_QUATERNION_USE
221 // Constructor which converts a matrix to a quaternion
222 inline quaternion::quaternion(const matrix4& mat)
223 {
224  (*this) = mat;
225 }
226 #endif
227 
228 // equal operator
229 inline bool quaternion::operator==(const quaternion& other) const
230 {
231  return ((X == other.X) &&
232  (Y == other.Y) &&
233  (Z == other.Z) &&
234  (W == other.W));
235 }
236 
237 // inequality operator
238 inline bool quaternion::operator!=(const quaternion& other) const
239 {
240  return !(*this == other);
241 }
242 
243 // assignment operator
245 {
246  X = other.X;
247  Y = other.Y;
248  Z = other.Z;
249  W = other.W;
250  return *this;
251 }
252 
253 #ifndef IRR_TEST_BROKEN_QUATERNION_USE
254 // matrix assignment operator
256 {
257  const f32 diag = m[0] + m[5] + m[10] + 1;
258 
259  if( diag > 0.0f )
260  {
261  const f32 scale = sqrtf(diag) * 2.0f; // get scale from diagonal
262 
263  // TODO: speed this up
264  X = (m[6] - m[9]) / scale;
265  Y = (m[8] - m[2]) / scale;
266  Z = (m[1] - m[4]) / scale;
267  W = 0.25f * scale;
268  }
269  else
270  {
271  if (m[0]>m[5] && m[0]>m[10])
272  {
273  // 1st element of diag is greatest value
274  // find scale according to 1st element, and double it
275  const f32 scale = sqrtf(1.0f + m[0] - m[5] - m[10]) * 2.0f;
276 
277  // TODO: speed this up
278  X = 0.25f * scale;
279  Y = (m[4] + m[1]) / scale;
280  Z = (m[2] + m[8]) / scale;
281  W = (m[6] - m[9]) / scale;
282  }
283  else if (m[5]>m[10])
284  {
285  // 2nd element of diag is greatest value
286  // find scale according to 2nd element, and double it
287  const f32 scale = sqrtf(1.0f + m[5] - m[0] - m[10]) * 2.0f;
288 
289  // TODO: speed this up
290  X = (m[4] + m[1]) / scale;
291  Y = 0.25f * scale;
292  Z = (m[9] + m[6]) / scale;
293  W = (m[8] - m[2]) / scale;
294  }
295  else
296  {
297  // 3rd element of diag is greatest value
298  // find scale according to 3rd element, and double it
299  const f32 scale = sqrtf(1.0f + m[10] - m[0] - m[5]) * 2.0f;
300 
301  // TODO: speed this up
302  X = (m[8] + m[2]) / scale;
303  Y = (m[9] + m[6]) / scale;
304  Z = 0.25f * scale;
305  W = (m[1] - m[4]) / scale;
306  }
307  }
308 
309  return normalize();
310 }
311 #endif
312 
313 
314 // multiplication operator
315 inline quaternion quaternion::operator*(const quaternion& other) const
316 {
317  quaternion tmp;
318 
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);
323 
324  return tmp;
325 }
326 
327 
328 // multiplication operator
330 {
331  return quaternion(s*X, s*Y, s*Z, s*W);
332 }
333 
334 
335 // multiplication operator
337 {
338  X*=s;
339  Y*=s;
340  Z*=s;
341  W*=s;
342  return *this;
343 }
344 
345 // multiplication operator
347 {
348  return (*this = other * (*this));
349 }
350 
351 // add operator
353 {
354  return quaternion(X+b.X, Y+b.Y, Z+b.Z, W+b.W);
355 }
356 
357 #ifndef IRR_TEST_BROKEN_QUATERNION_USE
358 // Creates a matrix from this quaternion
360 {
362  getMatrix(m);
363  return m;
364 }
365 #endif
366 
368 inline void quaternion::getMatrixFast( matrix4 &dest) const
369 {
370  // TODO:
371  // gpu quaternion skinning => fast Bones transform chain O_O YEAH!
372  // http://www.mrelusive.com/publications/papers/SIMD-From-Quaternion-to-Matrix-and-Back.pdf
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;
376  dest[3] = 0.0f;
377 
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;
381  dest[7] = 0.0f;
382 
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;
386  dest[11] = 0.0f;
387 
388  dest[12] = 0.f;
389  dest[13] = 0.f;
390  dest[14] = 0.f;
391  dest[15] = 1.f;
392 
393  dest.setDefinitelyIdentityMatrix(false);
394 }
395 
399 inline void quaternion::getMatrix(matrix4 &dest,
400  const core::vector3df &center) const
401 {
402  // ok creating a copy may be slower, but at least avoid internal
403  // state chance (also because otherwise we cannot keep this method "const").
404 
405  quaternion q( *this);
406  q.normalize();
407  f32 X = q.X;
408  f32 Y = q.Y;
409  f32 Z = q.Z;
410  f32 W = q.W;
411 
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;
415  dest[3] = 0.0f;
416 
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;
420  dest[7] = 0.0f;
421 
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;
425  dest[11] = 0.0f;
426 
427  dest[12] = center.X;
428  dest[13] = center.Y;
429  dest[14] = center.Z;
430  dest[15] = 1.f;
431 
432  dest.setDefinitelyIdentityMatrix ( false );
433 }
434 
435 
449  const core::vector3df &center,
450  const core::vector3df &translation) const
451 {
452  quaternion q(*this);
453  q.normalize();
454  f32 X = q.X;
455  f32 Y = q.Y;
456  f32 Z = q.Z;
457  f32 W = q.W;
458 
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;
462  dest[3] = 0.0f;
463 
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;
467  dest[7] = 0.0f;
468 
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;
472  dest[11] = 0.0f;
473 
474  dest.setRotationCenter ( center, translation );
475 }
476 
477 // Creates a matrix from this quaternion
479 {
480  quaternion q(*this);
481  q.normalize();
482  f32 X = q.X;
483  f32 Y = q.Y;
484  f32 Z = q.Z;
485  f32 W = q.W;
486 
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;
490  dest[12] = 0.0f;
491 
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;
495  dest[13] = 0.0f;
496 
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;
500  dest[14] = 0.0f;
501 
502  dest[3] = 0.f;
503  dest[7] = 0.f;
504  dest[11] = 0.f;
505  dest[15] = 1.f;
506 
507  dest.setDefinitelyIdentityMatrix(false);
508 }
509 
510 
511 // Inverts this quaternion
513 {
514  X = -X; Y = -Y; Z = -Z;
515  return *this;
516 }
517 
518 
519 // sets new quaternion
521 {
522  X = x;
523  Y = y;
524  Z = z;
525  W = w;
526  return *this;
527 }
528 
529 
530 // sets new quaternion based on Euler angles
532 {
533  f64 angle;
534 
535  angle = x * 0.5;
536  const f64 sr = sin(angle);
537  const f64 cr = cos(angle);
538 
539  angle = y * 0.5;
540  const f64 sp = sin(angle);
541  const f64 cp = cos(angle);
542 
543  angle = z * 0.5;
544  const f64 sy = sin(angle);
545  const f64 cy = cos(angle);
546 
547  const f64 cpcy = cp * cy;
548  const f64 spcy = sp * cy;
549  const f64 cpsy = cp * sy;
550  const f64 spsy = sp * sy;
551 
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);
556 
557  return normalize();
558 }
559 
560 // sets new quaternion based on Euler angles
562 {
563  return set( vec.X, vec.Y, vec.Z);
564 }
565 
566 // sets new quaternion based on other quaternion
568 {
569  return (*this=quat);
570 }
571 
572 
574 inline bool quaternion::equals(const quaternion& other, const f32 tolerance) const
575 {
576  return core::equals( X, other.X, tolerance) &&
577  core::equals( Y, other.Y, tolerance) &&
578  core::equals( Z, other.Z, tolerance) &&
579  core::equals( W, other.W, tolerance);
580 }
581 
582 
583 // normalizes the quaternion
585 {
586  // removed conditional branch since it may slow down and anyway the condition was
587  // false even after normalization in some cases.
588  return (*this *= (f32)reciprocal_squareroot ( (f64)(X*X + Y*Y + Z*Z + W*W) ));
589 }
590 
591 // Set this quaternion to the result of the linear interpolation between two quaternions
593 {
594  const f32 scale = 1.0f - time;
595  return (*this = (q1*scale) + (q2*time));
596 }
597 
598 // Set this quaternion to the result of the linear interpolation between two quaternions and normalize the result
600 {
601  const f32 scale = 1.0f - time;
602  return (*this = ((q1*scale) + (q2*time)).normalize() );
603 }
604 
605 // set this quaternion to the result of the interpolation between two quaternions
606 inline quaternion& quaternion::slerp( quaternion q1, quaternion q2, f32 time, f32 threshold)
607 {
608  f32 angle = q1.dotProduct(q2);
609 
610  // make sure we use the short rotation
611  if (angle < 0.0f)
612  {
613  q1 *= -1.0f;
614  angle *= -1.0f;
615  }
616 
617  if (angle <= (1-threshold)) // spherical interpolation
618  {
619  const f32 theta = acosf(angle);
620  const f32 invsintheta = reciprocal(sinf(theta));
621  const f32 scale = sinf(theta * (1.0f-time)) * invsintheta;
622  const f32 invscale = sinf(theta * time) * invsintheta;
623  return (*this = (q1*scale) + (q2*invscale));
624  }
625  else // linear interpolation
626  return lerpN(q1,q2,time);
627 }
628 
629 
630 // calculates the dot product
631 inline f32 quaternion::dotProduct(const quaternion& q2) const
632 {
633  return (X * q2.X) + (Y * q2.Y) + (Z * q2.Z) + (W * q2.W);
634 }
635 
636 
639 {
640  const f32 fHalfAngle = 0.5f*angle;
641  const f32 fSin = sinf(fHalfAngle);
642  W = cosf(fHalfAngle);
643  X = fSin*axis.X;
644  Y = fSin*axis.Y;
645  Z = fSin*axis.Z;
646  return *this;
647 }
648 
649 
651 {
652  const f32 scale = sqrtf(X*X + Y*Y + Z*Z);
653 
654  if (core::iszero(scale) || W > 1.0f || W < -1.0f)
655  {
656  angle = 0.0f;
657  axis.X = 0.0f;
658  axis.Y = 1.0f;
659  axis.Z = 0.0f;
660  }
661  else
662  {
663  const f32 invscale = reciprocal(scale);
664  angle = 2.0f * acosf(W);
665  axis.X = X * invscale;
666  axis.Y = Y * invscale;
667  axis.Z = Z * invscale;
668  }
669 }
670 
671 inline void quaternion::toEuler(vector3df& euler) const
672 {
673  const f64 sqw = W*W;
674  const f64 sqx = X*X;
675  const f64 sqy = Y*Y;
676  const f64 sqz = Z*Z;
677  const f64 test = 2.0 * (Y*W - X*Z);
678 
679  if (core::equals(test, 1.0, 0.000001))
680  {
681  // heading = rotation about z-axis
682  euler.Z = (f32) (-2.0*atan2(X, W));
683  // bank = rotation about x-axis
684  euler.X = 0;
685  // attitude = rotation about y-axis
686  euler.Y = (f32) (core::PI64/2.0);
687  }
688  else if (core::equals(test, -1.0, 0.000001))
689  {
690  // heading = rotation about z-axis
691  euler.Z = (f32) (2.0*atan2(X, W));
692  // bank = rotation about x-axis
693  euler.X = 0;
694  // attitude = rotation about y-axis
695  euler.Y = (f32) (core::PI64/-2.0);
696  }
697  else
698  {
699  // heading = rotation about z-axis
700  euler.Z = (f32) atan2(2.0 * (X*Y +Z*W),(sqx - sqy - sqz + sqw));
701  // bank = rotation about x-axis
702  euler.X = (f32) atan2(2.0 * (Y*Z +X*W),(-sqx - sqy + sqz + sqw));
703  // attitude = rotation about y-axis
704  euler.Y = (f32) asin( clamp(test, -1.0, 1.0) );
705  }
706 }
707 
708 
710 {
711  // nVidia SDK implementation
712 
713  vector3df uv, uuv;
714  const vector3df qvec(X, Y, Z);
715  uv = qvec.crossProduct(v);
716  uuv = qvec.crossProduct(uv);
717  uv *= (2.0f * W);
718  uuv *= 2.0f;
719 
720  return v + uv + uuv;
721 }
722 
723 // set quaternion to identity
725 {
726  W = 1.f;
727  X = 0.f;
728  Y = 0.f;
729  Z = 0.f;
730  return *this;
731 }
732 
734 {
735  // Based on Stan Melax's article in Game Programming Gems
736  // Copy, since cannot modify local
737  vector3df v0 = from;
738  vector3df v1 = to;
739  v0.normalize();
740  v1.normalize();
741 
742  const f32 d = v0.dotProduct(v1);
743  if (d >= 1.0f) // If dot == 1, vectors are the same
744  {
745  return makeIdentity();
746  }
747  else if (d <= -1.0f) // exactly opposite
748  {
749  core::vector3df axis(1.0f, 0.f, 0.f);
750  axis = axis.crossProduct(v0);
751  if (axis.getLength()==0)
752  {
753  axis.set(0.f,1.f,0.f);
754  axis = axis.crossProduct(v0);
755  }
756  // same as fromAngleAxis(core::PI, axis).normalize();
757  return set(axis.X, axis.Y, axis.Z, 0).normalize();
758  }
759 
760  const f32 s = sqrtf( (1+d)*2 ); // optimize inv_sqrt
761  const f32 invs = 1.f / s;
762  const vector3df c = v0.crossProduct(v1)*invs;
763  return set(c.X, c.Y, c.Z, s * 0.5f).normalize();
764 }
765 
766 
767 } // end namespace core
768 } // end namespace irr
769 
770 #endif
771 
GLenum GLenum GLenum GLenum GLenum scale
f32 dotProduct(const quaternion &other) const
Calculates the dot product.
Definition: quaternion.h:631
vector3d< T > crossProduct(const vector3d< T > &p) const
Calculates the cross product with another vector.
Definition: vector3d.h:161
quaternion & makeIdentity()
Set quaternion to identity.
Definition: quaternion.h:724
void toEuler(vector3df &euler) const
Output this quaternion to an Euler angle (radians)
Definition: quaternion.h:671
const f64 PI64
Constant for 64bit PI.
Definition: irrMath.h:69
T Y
Y coordinate of the vector.
Definition: vector3d.h:427
bool iszero(const f64 a, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals zero, taking rounding errors into account
Definition: irrMath.h:307
void getMatrixFast(matrix4 &dest) const
Faster method to create a rotation matrix, you should normalize the quaternion before!
Definition: quaternion.h:368
void setDefinitelyIdentityMatrix(bool isDefinitelyIdentityMatrix)
Sets if the matrix is definitely identity matrix.
Definition: matrix4.h:2330
float f32
32 bit floating point variable.
Definition: irrTypes.h:108
GLdouble GLdouble GLdouble GLdouble q
Definition: SDL_opengl.h:2087
const GLfloat * m
void toAngleAxis(f32 &angle, core::vector3df &axis) const
Fills an angle (radians) around an axis (unit vector)
Definition: quaternion.h:650
void setRotationCenter(const core::vector3df &center, const core::vector3df &translate)
Builds a combined matrix which translates to a center before rotation and translates from origin afte...
Definition: matrix4.h:2171
T X
X coordinate of the vector.
Definition: vector3d.h:424
quaternion & normalize()
Normalizes the quaternion.
Definition: quaternion.h:584
vector3d< T > & set(const T nx, const T ny, const T nz)
Definition: vector3d.h:127
Everything in the Irrlicht Engine can be found in this namespace.
Definition: CARSADPad.h:6
bool operator==(const quaternion &other) const
Equality operator.
Definition: quaternion.h:229
quaternion & operator *=(f32 s)
Multiplication operator with scalar.
Definition: quaternion.h:336
quaternion(f32 x, f32 y, f32 z, f32 w)
Constructor.
Definition: quaternion.h:39
double f64
64 bit floating point variable.
Definition: irrTypes.h:112
quaternion operator *(const quaternion &other) const
Definition: quaternion.h:315
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:574
const GLdouble * v
Definition: SDL_opengl.h:2064
const f32 ROUNDING_ERROR_f32
Definition: irrMath.h:50
bool operator!=(const quaternion &other) const
inequality operator
Definition: quaternion.h:238
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.h:246
quaternion operator+(const quaternion &other) const
Add operator.
Definition: quaternion.h:352
REALINLINE f32 reciprocal(const f32 f)
Definition: irrMath.h:562
GLfloat f
quaternion & fromAngleAxis(f32 angle, const vector3df &axis)
Set this quaternion to represent a rotation from angle and axis.
Definition: quaternion.h:638
f32 X
Quaternion elements.
Definition: quaternion.h:200
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
void getMatrix_transposed(matrix4 &dest) const
Creates a matrix from this quaternion.
Definition: quaternion.h:478
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:606
quaternion & rotationFromTo(const vector3df &from, const vector3df &to)
Set quaternion to represent a rotation from one vector to another.
Definition: quaternion.h:733
void getMatrixCenter(matrix4 &dest, const core::vector3df &center, const core::vector3df &translation) const
Definition: quaternion.h:448
vector3d< T > & normalize()
Normalizes the vector.
Definition: vector3d.h:182
4x4 matrix. Mostly used as transformation matrix for 3d calculations.
Definition: matrix4.h:45
T dotProduct(const vector3d< T > &other) const
Get the dot product with another vector.
Definition: vector3d.h:139
quaternion & operator=(const quaternion &other)
Assignment operator.
Definition: quaternion.h:244
GLboolean GLboolean GLboolean b
GLdouble s
Definition: SDL_opengl.h:2063
matrix4 getMatrix() const
Creates a matrix from this quaternion.
Definition: quaternion.h:359
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
T Z
Z coordinate of the vector.
Definition: vector3d.h:430
GLfloat v0
GLfloat angle
Quaternion class for representing rotations.
Definition: quaternion.h:31
quaternion & lerpN(quaternion q1, quaternion q2, f32 time)
Set this quaternion to the linear interpolation between two quaternions and normalize the result.
Definition: quaternion.h:599
GLubyte GLubyte GLubyte GLubyte w
T getLength() const
Get length of the vector.
Definition: vector3d.h:131
const GLubyte * c
GLfloat GLfloat v1
REALINLINE f64 reciprocal_squareroot(const f64 x)
Definition: irrMath.h:521
GLdouble GLdouble z
quaternion & makeInverse()
Inverts this quaternion.
Definition: quaternion.h:512
quaternion & set(f32 x, f32 y, f32 z, f32 w)
Sets new quaternion.
Definition: quaternion.h:520
quaternion()
Default Constructor.
Definition: quaternion.h:36
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition: irrMath.h:167
quaternion & lerp(quaternion q1, quaternion q2, f32 time)
Set this quaternion to the linear interpolation between two quaternions.
Definition: quaternion.h:592