26 template <
int N,
typename Real>
220 template <
int N,
typename Real>
226 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
229 template <
int N,
typename Real>
235 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
238 template <
int N,
typename Real>
244 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
247 template <
int N,
typename Real>
253 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
256 template <
int N,
typename Real>
259 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
279 template <
int N,
typename Real>
282 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
302 template <
int N,
typename Real>
305 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
325 template <
int N,
typename Real>
329 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
353 template <
int N,
typename Real>
357 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
362 Real dif10 =
r(1, 1) -
r(0, 0);
363 Real omr22 = (Real)1 - r22;
364 if (dif10 <= (Real)0)
366 Real fourXSqr = omr22 - dif10;
367 Real inv4x = ((Real)0.5) / sqrt(fourXSqr);
368 q[0] = fourXSqr*inv4x;
369 q[1] = (
r(0, 1) +
r(1, 0))*inv4x;
370 q[2] = (
r(0, 2) +
r(2, 0))*inv4x;
371 #if defined(GTE_USE_MAT_VEC) 372 q[3] = (
r(2, 1) -
r(1, 2))*inv4x;
374 q[3] = (
r(1, 2) -
r(2, 1))*inv4x;
379 Real fourYSqr = omr22 + dif10;
380 Real inv4y = ((Real)0.5) / sqrt(fourYSqr);
381 q[0] = (
r(0, 1) +
r(1, 0))*inv4y;
382 q[1] = fourYSqr*inv4y;
383 q[2] = (
r(1, 2) +
r(2, 1))*inv4y;
384 #if defined(GTE_USE_MAT_VEC) 385 q[3] = (
r(0, 2) -
r(2, 0))*inv4y;
387 q[3] = (
r(2, 0) -
r(0, 2))*inv4y;
393 Real sum10 =
r(1, 1) +
r(0, 0);
394 Real opr22 = (Real)1 + r22;
395 if (sum10 <= (Real)0)
397 Real fourZSqr = opr22 - sum10;
398 Real inv4z = ((Real)0.5) / sqrt(fourZSqr);
399 q[0] = (
r(0, 2) +
r(2, 0))*inv4z;
400 q[1] = (
r(1, 2) +
r(2, 1))*inv4z;
401 q[2] = fourZSqr*inv4z;
402 #if defined(GTE_USE_MAT_VEC) 403 q[3] = (
r(1, 0) -
r(0, 1))*inv4z;
405 q[3] = (
r(0, 1) -
r(1, 0))*inv4z;
410 Real fourWSqr = opr22 + sum10;
411 Real inv4w = ((Real)0.5) / sqrt(fourWSqr);
412 #if defined(GTE_USE_MAT_VEC) 413 q[0] = (
r(2, 1) -
r(1, 2))*inv4w;
414 q[1] = (
r(0, 2) -
r(2, 0))*inv4w;
415 q[2] = (
r(1, 0) -
r(0, 1))*inv4w;
417 q[0] = (
r(1, 2) -
r(2, 1))*inv4w;
418 q[1] = (
r(2, 0) -
r(0, 2))*inv4w;
419 q[2] = (
r(0, 1) -
r(1, 0))*inv4w;
421 q[3] = fourWSqr*inv4w;
426 template <
int N,
typename Real>
429 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
433 Real twoX = ((Real)2)*q[0];
434 Real twoY = ((Real)2)*q[1];
435 Real twoZ = ((Real)2)*q[2];
436 Real twoXX = twoX*q[0];
437 Real twoXY = twoX*q[1];
438 Real twoXZ = twoX*q[2];
439 Real twoXW = twoX*q[3];
440 Real twoYY = twoY*q[1];
441 Real twoYZ = twoY*q[2];
442 Real twoYW = twoY*q[3];
443 Real twoZZ = twoZ*q[2];
444 Real twoZW = twoZ*q[3];
446 #if defined(GTE_USE_MAT_VEC) 447 r(0, 0) = (Real)1 - twoYY - twoZZ;
448 r(0, 1) = twoXY - twoZW;
449 r(0, 2) = twoXZ + twoYW;
450 r(1, 0) = twoXY + twoZW;
451 r(1, 1) = (Real)1 - twoXX - twoZZ;
452 r(1, 2) = twoYZ - twoXW;
453 r(2, 0) = twoXZ - twoYW;
454 r(2, 1) = twoYZ + twoXW;
455 r(2, 2) = (Real)1 - twoXX - twoYY;
457 r(0, 0) = (Real)1 - twoYY - twoZZ;
458 r(1, 0) = twoXY - twoZW;
459 r(2, 0) = twoXZ + twoYW;
460 r(0, 1) = twoXY + twoZW;
461 r(1, 1) = (Real)1 - twoXX - twoZZ;
462 r(2, 1) = twoYZ - twoXW;
463 r(0, 2) = twoXZ - twoYW;
464 r(1, 2) = twoYZ + twoXW;
465 r(2, 2) = (Real)1 - twoXX - twoYY;
469 template <
int N,
typename Real>
473 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
475 Real trace =
r(0, 0) +
r(1, 1) +
r(2, 2);
476 Real half = (Real)0.5;
477 Real cs = half*(trace - (Real)1);
478 cs = std::max(std::min(cs, (Real)1), (Real)-1);
482 if (a.
angle > (Real)0)
487 #if defined(GTE_USE_MAT_VEC) 488 a.
axis[0] =
r(2, 1) -
r(1, 2);
489 a.
axis[1] =
r(0, 2) -
r(2, 0);
490 a.
axis[2] =
r(1, 0) -
r(0, 1);
493 a.
axis[0] =
r(1, 2) -
r(2, 1);
494 a.
axis[1] =
r(2, 0) -
r(0, 2);
495 a.
axis[2] =
r(0, 1) -
r(1, 0);
508 if (
r(0, 0) >=
r(1, 1))
510 if (
r(0, 0) >=
r(2, 2))
513 a.
axis[0] =
r(0, 0) + one;
514 a.
axis[1] = half*(
r(0, 1) +
r(1, 0));
515 a.
axis[2] = half*(
r(0, 2) +
r(2, 0));
520 a.
axis[0] = half*(
r(2, 0) +
r(0, 2));
521 a.
axis[1] = half*(
r(2, 1) +
r(1, 2));
522 a.
axis[2] =
r(2, 2) + one;
527 if (
r(1, 1) >=
r(2, 2))
530 a.
axis[0] = half*(
r(1, 0) +
r(0, 1));
531 a.
axis[1] =
r(1, 1) + one;
532 a.
axis[2] = half*(
r(1, 2) +
r(2, 1));
537 a.
axis[0] = half*(
r(2, 0) +
r(0, 2));
538 a.
axis[1] = half*(
r(2, 1) +
r(1, 2));
539 a.
axis[2] =
r(2, 2) + one;
553 template <
int N,
typename Real>
557 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
561 Real cs = cos(a.
angle);
562 Real sn = sin(a.
angle);
563 Real oneMinusCos = ((Real)1) - cs;
567 Real x0x1m = a.
axis[0] * a.
axis[1] * oneMinusCos;
568 Real x0x2m = a.
axis[0] * a.
axis[2] * oneMinusCos;
569 Real x1x2m = a.
axis[1] * a.
axis[2] * oneMinusCos;
570 Real x0Sin = a.
axis[0] * sn;
571 Real x1Sin = a.
axis[1] * sn;
572 Real x2Sin = a.
axis[2] * sn;
574 #if defined(GTE_USE_MAT_VEC) 575 r(0, 0) = x0sqr*oneMinusCos + cs;
576 r(0, 1) = x0x1m - x2Sin;
577 r(0, 2) = x0x2m + x1Sin;
578 r(1, 0) = x0x1m + x2Sin;
579 r(1, 1) = x1sqr*oneMinusCos + cs;
580 r(1, 2) = x1x2m - x0Sin;
581 r(2, 0) = x0x2m - x1Sin;
582 r(2, 1) = x1x2m + x0Sin;
583 r(2, 2) = x2sqr*oneMinusCos + cs;
585 r(0, 0) = x0sqr*oneMinusCos + cs;
586 r(1, 0) = x0x1m - x2Sin;
587 r(2, 0) = x0x2m + x1Sin;
588 r(0, 1) = x0x1m + x2Sin;
589 r(1, 1) = x1sqr*oneMinusCos + cs;
590 r(2, 1) = x1x2m - x0Sin;
591 r(0, 2) = x0x2m - x1Sin;
592 r(1, 2) = x1x2m + x0Sin;
593 r(2, 2) = x2sqr*oneMinusCos + cs;
597 template <
int N,
typename Real>
601 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
611 #if defined(GTE_USE_MAT_VEC) 614 int parity = (((e.
axis[2] | (e.
axis[1] << 2)) >> e.
axis[0]) & 1);
615 Real
const sgn = (parity & 1 ? (Real)-1 : (Real)+1);
630 e.
angle[2] = (Real)0;
639 e.
angle[2] = (Real)0;
648 int parity = (((e.
axis[0] | (e.
axis[1] << 2)) >> e.
axis[2]) & 1);
649 Real
const sgn = (parity & 1 ? (Real)+1 : (Real)-1);
664 e.
angle[0] = (Real)0;
673 e.
angle[0] = (Real)0;
683 #if defined(GTE_USE_MAT_VEC) 687 int parity = (((b0 | (e.
axis[1] << 2)) >> e.
axis[2]) & 1);
688 Real
const sgn = (parity & 1 ? (Real)+1 : (Real)-1);
695 sgn*r(b0, e.
axis[2]));
698 -sgn*r(e.
axis[2], b0));
703 e.
angle[2] = (Real)0;
712 e.
angle[2] = (Real)0;
713 e.
angle[1] = (Real)0;
722 int parity = (((b2 | (e.
axis[1] << 2)) >> e.
axis[0]) & 1);
723 Real
const sgn = (parity & 1 ? (Real)-1 : (Real)+1);
730 sgn*r(b2, e.
axis[0]));
733 -sgn*r(e.
axis[0], b2));
738 e.
angle[0] = (Real)0;
747 e.
angle[0] = (Real)0;
748 e.
angle[1] = (Real)0;
759 e.
angle[0] = (Real)0;
760 e.
angle[1] = (Real)0;
761 e.
angle[2] = (Real)0;
766 template <
int N,
typename Real>
770 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
785 #if defined(GTE_USE_MAT_VEC) 798 template <
int N,
typename Real>
802 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
806 Real axisSqrLen = q[0] * q[0] + q[1] * q[1] + q[2] * q[2];
807 if (axisSqrLen > (Real)0)
809 #if defined(GTE_USE_MAT_VEC) 810 Real adjust = ((Real)1) / sqrt(axisSqrLen);
812 Real adjust = ((Real)-1) / sqrt(axisSqrLen);
814 a.
axis[0] = q[0] * adjust;
815 a.
axis[1] = q[1] * adjust;
816 a.
axis[2] = q[2] * adjust;
817 Real cs = std::max(std::min(q[3], (Real)1), (Real)-1);
818 a.
angle = ((Real)2)*acos(cs);
829 template <
int N,
typename Real>
833 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
835 #if defined(GTE_USE_MAT_VEC) 836 Real halfAngle = ((Real)0.5)*a.
angle;
838 Real halfAngle = ((Real)-0.5)*a.
angle;
840 Real sn = sin(halfAngle);
844 q[3] = cos(halfAngle);
847 template <
int N,
typename Real>
851 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
858 template <
int N,
typename Real>
862 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
869 template <
int N,
typename Real>
873 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
880 template <
int N,
typename Real>
884 static_assert(N == 3 || N == 4,
"Dimension must be 3 or 4.");
static void Convert(Matrix< N, N, Real > const &r, Quaternion< Real > &q)
EulerAngles< Real > mEulerAngles
Rotation(Matrix< N, N, Real > const &matrix)
AxisAngle< N, Real > mAxisAngle
GLboolean GLboolean GLboolean GLboolean a
Matrix< N, N, Real > mMatrix
Real Normalize(GVector< Real > &v, bool robust=false)
GLdouble GLdouble GLdouble GLdouble q
Quaternion< Real > mQuaternion
EulerAngles< Real > const & operator()(int i0, int i1, int i2) const