4 #ifndef OPENVDB_MATH_MAT4_H_HAS_BEEN_INCLUDED 5 #define OPENVDB_MATH_MAT4_H_HAS_BEEN_INCLUDED 24 template<
typename T>
class Vec4;
50 template<
typename Source>
53 for (
int i = 0; i < 16; i++) {
54 MyBase::mm[i] =
static_cast<T
>(a[i]);
65 template<
typename Source>
66 Mat4(Source a, Source b, Source c, Source d,
67 Source e, Source f, Source g, Source h,
68 Source i, Source j, Source k, Source l,
69 Source m, Source n, Source o, Source p)
71 MyBase::mm[ 0] =
static_cast<T
>(a);
72 MyBase::mm[ 1] =
static_cast<T
>(b);
73 MyBase::mm[ 2] =
static_cast<T
>(c);
74 MyBase::mm[ 3] =
static_cast<T
>(d);
76 MyBase::mm[ 4] =
static_cast<T
>(e);
77 MyBase::mm[ 5] =
static_cast<T
>(f);
78 MyBase::mm[ 6] =
static_cast<T
>(g);
79 MyBase::mm[ 7] =
static_cast<T
>(h);
81 MyBase::mm[ 8] =
static_cast<T
>(i);
82 MyBase::mm[ 9] =
static_cast<T
>(j);
83 MyBase::mm[10] =
static_cast<T
>(k);
84 MyBase::mm[11] =
static_cast<T
>(l);
86 MyBase::mm[12] =
static_cast<T
>(m);
87 MyBase::mm[13] =
static_cast<T
>(n);
88 MyBase::mm[14] =
static_cast<T
>(o);
89 MyBase::mm[15] =
static_cast<T
>(p);
94 template<
typename Source>
99 this->setRows(v1, v2, v3, v4);
101 this->setColumns(v1, v2, v3, v4);
106 template<
typename Source>
111 for (
int i=0; i<16; ++i) {
112 MyBase::mm[i] =
static_cast<T
>(src[i]);
143 MyBase::mm[i4+0] = v[0];
144 MyBase::mm[i4+1] = v[1];
145 MyBase::mm[i4+2] = v[2];
146 MyBase::mm[i4+3] = v[3];
153 return Vec4<T>((*this)(i,0), (*
this)(i,1), (*
this)(i,2), (*
this)(i,3));
160 MyBase::mm[ 0+j] = v[0];
161 MyBase::mm[ 4+j] = v[1];
162 MyBase::mm[ 8+j] = v[2];
163 MyBase::mm[12+j] = v[3];
170 return Vec4<T>((*this)(0,j), (*
this)(1,j), (*
this)(2,j), (*
this)(3,j));
180 return MyBase::mm[4*i+j];
190 return MyBase::mm[4*i+j];
197 MyBase::mm[ 0] = v1[0];
198 MyBase::mm[ 1] = v1[1];
199 MyBase::mm[ 2] = v1[2];
200 MyBase::mm[ 3] = v1[3];
202 MyBase::mm[ 4] = v2[0];
203 MyBase::mm[ 5] = v2[1];
204 MyBase::mm[ 6] = v2[2];
205 MyBase::mm[ 7] = v2[3];
207 MyBase::mm[ 8] = v3[0];
208 MyBase::mm[ 9] = v3[1];
209 MyBase::mm[10] = v3[2];
210 MyBase::mm[11] = v3[3];
212 MyBase::mm[12] = v4[0];
213 MyBase::mm[13] = v4[1];
214 MyBase::mm[14] = v4[2];
215 MyBase::mm[15] = v4[3];
222 MyBase::mm[ 0] = v1[0];
223 MyBase::mm[ 1] = v2[0];
224 MyBase::mm[ 2] = v3[0];
225 MyBase::mm[ 3] = v4[0];
227 MyBase::mm[ 4] = v1[1];
228 MyBase::mm[ 5] = v2[1];
229 MyBase::mm[ 6] = v3[1];
230 MyBase::mm[ 7] = v4[1];
232 MyBase::mm[ 8] = v1[2];
233 MyBase::mm[ 9] = v2[2];
234 MyBase::mm[10] = v3[2];
235 MyBase::mm[11] = v4[2];
237 MyBase::mm[12] = v1[3];
238 MyBase::mm[13] = v2[3];
239 MyBase::mm[14] = v3[3];
240 MyBase::mm[15] = v4[3];
292 for (
int i = 0; i < 3; i++)
293 for (
int j=0; j < 3; j++)
294 MyBase::mm[i*4+j] = m[i][j];
301 for (
int i = 0; i < 3; i++)
302 for (
int j = 0; j < 3; j++)
303 m[i][j] = MyBase::mm[i*4+j];
311 return Vec3<T>(MyBase::mm[12], MyBase::mm[13], MyBase::mm[14]);
316 MyBase::mm[12] = t[0];
317 MyBase::mm[13] = t[1];
318 MyBase::mm[14] = t[2];
322 template<
typename Source>
328 std::copy(src, (src + this->numElements()), MyBase::mm);
333 bool eq(
const Mat4 &m, T eps=1.0e-8)
const 335 for (
int i = 0; i < 16; i++) {
346 -MyBase::mm[ 0], -MyBase::mm[ 1], -MyBase::mm[ 2], -MyBase::mm[ 3],
347 -MyBase::mm[ 4], -MyBase::mm[ 5], -MyBase::mm[ 6], -MyBase::mm[ 7],
348 -MyBase::mm[ 8], -MyBase::mm[ 9], -MyBase::mm[10], -MyBase::mm[11],
349 -MyBase::mm[12], -MyBase::mm[13], -MyBase::mm[14], -MyBase::mm[15]
354 template <
typename S>
357 MyBase::mm[ 0] *= scalar;
358 MyBase::mm[ 1] *= scalar;
359 MyBase::mm[ 2] *= scalar;
360 MyBase::mm[ 3] *= scalar;
362 MyBase::mm[ 4] *= scalar;
363 MyBase::mm[ 5] *= scalar;
364 MyBase::mm[ 6] *= scalar;
365 MyBase::mm[ 7] *= scalar;
367 MyBase::mm[ 8] *= scalar;
368 MyBase::mm[ 9] *= scalar;
369 MyBase::mm[10] *= scalar;
370 MyBase::mm[11] *= scalar;
372 MyBase::mm[12] *= scalar;
373 MyBase::mm[13] *= scalar;
374 MyBase::mm[14] *= scalar;
375 MyBase::mm[15] *= scalar;
380 template <
typename S>
385 MyBase::mm[ 0] += s[ 0];
386 MyBase::mm[ 1] += s[ 1];
387 MyBase::mm[ 2] += s[ 2];
388 MyBase::mm[ 3] += s[ 3];
390 MyBase::mm[ 4] += s[ 4];
391 MyBase::mm[ 5] += s[ 5];
392 MyBase::mm[ 6] += s[ 6];
393 MyBase::mm[ 7] += s[ 7];
395 MyBase::mm[ 8] += s[ 8];
396 MyBase::mm[ 9] += s[ 9];
397 MyBase::mm[10] += s[10];
398 MyBase::mm[11] += s[11];
400 MyBase::mm[12] += s[12];
401 MyBase::mm[13] += s[13];
402 MyBase::mm[14] += s[14];
403 MyBase::mm[15] += s[15];
409 template <
typename S>
414 MyBase::mm[ 0] -= s[ 0];
415 MyBase::mm[ 1] -= s[ 1];
416 MyBase::mm[ 2] -= s[ 2];
417 MyBase::mm[ 3] -= s[ 3];
419 MyBase::mm[ 4] -= s[ 4];
420 MyBase::mm[ 5] -= s[ 5];
421 MyBase::mm[ 6] -= s[ 6];
422 MyBase::mm[ 7] -= s[ 7];
424 MyBase::mm[ 8] -= s[ 8];
425 MyBase::mm[ 9] -= s[ 9];
426 MyBase::mm[10] -= s[10];
427 MyBase::mm[11] -= s[11];
429 MyBase::mm[12] -= s[12];
430 MyBase::mm[13] -= s[13];
431 MyBase::mm[14] -= s[14];
432 MyBase::mm[15] -= s[15];
438 template <
typename S>
446 for (
int i = 0; i < 4; i++) {
448 MyBase::mm[i4+0] =
static_cast<T
>(s0[i4+0] * s1[ 0] +
453 MyBase::mm[i4+1] =
static_cast<T
>(s0[i4+0] * s1[ 1] +
458 MyBase::mm[i4+2] =
static_cast<T
>(s0[i4+0] * s1[ 2] +
463 MyBase::mm[i4+3] =
static_cast<T
>(s0[i4+0] * s1[ 3] +
475 MyBase::mm[ 0], MyBase::mm[ 4], MyBase::mm[ 8], MyBase::mm[12],
476 MyBase::mm[ 1], MyBase::mm[ 5], MyBase::mm[ 9], MyBase::mm[13],
477 MyBase::mm[ 2], MyBase::mm[ 6], MyBase::mm[10], MyBase::mm[14],
478 MyBase::mm[ 3], MyBase::mm[ 7], MyBase::mm[11], MyBase::mm[15]
508 T m0011 = m[0][0] * m[1][1];
509 T m0012 = m[0][0] * m[1][2];
510 T m0110 = m[0][1] * m[1][0];
511 T m0210 = m[0][2] * m[1][0];
512 T m0120 = m[0][1] * m[2][0];
513 T m0220 = m[0][2] * m[2][0];
515 T detA = m0011 * m[2][2] - m0012 * m[2][1] - m0110 * m[2][2]
516 + m0210 * m[2][1] + m0120 * m[1][2] - m0220 * m[1][1];
518 bool hasPerspective =
525 if (hasPerspective) {
526 det = m[0][3] * det3(m, 1,2,3, 0,2,1)
527 + m[1][3] * det3(m, 2,0,3, 0,2,1)
528 + m[2][3] * det3(m, 3,0,1, 0,2,1)
531 det = detA * m[3][3];
542 invertible = m.invert(inv, tolerance);
551 inv[0][0] = detA * ( m[1][1] * m[2][2] - m[1][2] * m[2][1]);
552 inv[0][1] = detA * (-m[0][1] * m[2][2] + m[0][2] * m[2][1]);
553 inv[0][2] = detA * ( m[0][1] * m[1][2] - m[0][2] * m[1][1]);
555 inv[1][0] = detA * (-m[1][0] * m[2][2] + m[1][2] * m[2][0]);
556 inv[1][1] = detA * ( m[0][0] * m[2][2] - m0220);
557 inv[1][2] = detA * ( m0210 - m0012);
559 inv[2][0] = detA * ( m[1][0] * m[2][1] - m[1][1] * m[2][0]);
560 inv[2][1] = detA * ( m0120 - m[0][0] * m[2][1]);
561 inv[2][2] = detA * ( m0011 - m0110);
563 if (hasPerspective) {
568 r[0] = m[3][0] * inv[0][0] + m[3][1] * inv[1][0]
569 + m[3][2] * inv[2][0];
570 r[1] = m[3][0] * inv[0][1] + m[3][1] * inv[1][1]
571 + m[3][2] * inv[2][1];
572 r[2] = m[3][0] * inv[0][2] + m[3][1] * inv[1][2]
573 + m[3][2] * inv[2][2];
576 p[0] = inv[0][0] * m[0][3] + inv[0][1] * m[1][3]
577 + inv[0][2] * m[2][3];
578 p[1] = inv[1][0] * m[0][3] + inv[1][1] * m[1][3]
579 + inv[1][2] * m[2][3];
580 p[2] = inv[2][0] * m[0][3] + inv[2][1] * m[1][3]
581 + inv[2][2] * m[2][3];
583 T h = m[3][3] - p.
dot(
Vec3<T>(m[3][0],m[3][1],m[3][2]));
594 inv[3][0] = -h * r[0];
595 inv[3][1] = -h * r[1];
596 inv[3][2] = -h * r[2];
598 inv[0][3] = -h * p[0];
599 inv[1][3] = -h * p[1];
600 inv[2][3] = -h * p[2];
606 inv[0][0] += p[0] * r[0];
607 inv[0][1] += p[0] * r[1];
608 inv[0][2] += p[0] * r[2];
609 inv[1][0] += p[1] * r[0];
610 inv[1][1] += p[1] * r[1];
611 inv[1][2] += p[1] * r[2];
612 inv[2][0] += p[2] * r[0];
613 inv[2][1] += p[2] * r[1];
614 inv[2][2] += p[2] * r[2];
618 inv[3][0] = - (m[3][0] * inv[0][0] + m[3][1] * inv[1][0]
619 + m[3][2] * inv[2][0]);
620 inv[3][1] = - (m[3][0] * inv[0][1] + m[3][1] * inv[1][1]
621 + m[3][2] * inv[2][1]);
622 inv[3][2] = - (m[3][0] * inv[0][2] + m[3][1] * inv[1][2]
623 + m[3][2] * inv[2][2]);
647 for (i = 0; i < 4; i++) {
648 ap = &MyBase::mm[ 0];
650 for (j = 0; j < 4; j++) {
651 for (k = 0; k < 4; k++) {
652 if ((k != i) && (j != 0)) {
659 det += T(sign) * MyBase::mm[i] * submat.
det();
670 T(1), T(0), T(0), T(0),
671 T(0), T(1), T(0), T(0),
672 T(0), T(0), T(1), T(0),
673 T(v.
x()), T(v.
y()),T(v.
z()), T(1));
677 template <
typename T0>
695 MyBase::mm[12] = v.
x();
696 MyBase::mm[13] = v.
y();
697 MyBase::mm[14] = v.
z();
702 template <
typename T0>
708 *
this = Tr * (*this);
713 template <
typename T0>
719 *
this = (*this) * Tr;
725 template <
typename T0>
729 MyBase::mm[ 0] = v.
x();
730 MyBase::mm[ 5] = v.
y();
731 MyBase::mm[10] = v.
z();
735 template <
typename T0>
738 MyBase::mm[ 0] *= v.
x();
739 MyBase::mm[ 1] *= v.
x();
740 MyBase::mm[ 2] *= v.
x();
741 MyBase::mm[ 3] *= v.
x();
743 MyBase::mm[ 4] *= v.
y();
744 MyBase::mm[ 5] *= v.
y();
745 MyBase::mm[ 6] *= v.
y();
746 MyBase::mm[ 7] *= v.
y();
748 MyBase::mm[ 8] *= v.
z();
749 MyBase::mm[ 9] *= v.
z();
750 MyBase::mm[10] *= v.
z();
751 MyBase::mm[11] *= v.
z();
757 template <
typename T0>
761 MyBase::mm[ 0] *= v.
x();
762 MyBase::mm[ 1] *= v.
y();
763 MyBase::mm[ 2] *= v.
z();
765 MyBase::mm[ 4] *= v.
x();
766 MyBase::mm[ 5] *= v.
y();
767 MyBase::mm[ 6] *= v.
z();
769 MyBase::mm[ 8] *= v.
x();
770 MyBase::mm[ 9] *= v.
y();
771 MyBase::mm[10] *= v.
z();
773 MyBase::mm[12] *= v.
x();
774 MyBase::mm[13] *= v.
y();
775 MyBase::mm[14] *= v.
z();
800 T c =
static_cast<T
>(cos(angle));
801 T s = -
static_cast<T
>(sin(angle));
808 a4 = c * MyBase::mm[ 4] - s * MyBase::mm[ 8];
809 a5 = c * MyBase::mm[ 5] - s * MyBase::mm[ 9];
810 a6 = c * MyBase::mm[ 6] - s * MyBase::mm[10];
811 a7 = c * MyBase::mm[ 7] - s * MyBase::mm[11];
814 MyBase::mm[ 8] = s * MyBase::mm[ 4] + c * MyBase::mm[ 8];
815 MyBase::mm[ 9] = s * MyBase::mm[ 5] + c * MyBase::mm[ 9];
816 MyBase::mm[10] = s * MyBase::mm[ 6] + c * MyBase::mm[10];
817 MyBase::mm[11] = s * MyBase::mm[ 7] + c * MyBase::mm[11];
830 a0 = c * MyBase::mm[ 0] + s * MyBase::mm[ 8];
831 a1 = c * MyBase::mm[ 1] + s * MyBase::mm[ 9];
832 a2 = c * MyBase::mm[ 2] + s * MyBase::mm[10];
833 a3 = c * MyBase::mm[ 3] + s * MyBase::mm[11];
835 MyBase::mm[ 8] = -s * MyBase::mm[ 0] + c * MyBase::mm[ 8];
836 MyBase::mm[ 9] = -s * MyBase::mm[ 1] + c * MyBase::mm[ 9];
837 MyBase::mm[10] = -s * MyBase::mm[ 2] + c * MyBase::mm[10];
838 MyBase::mm[11] = -s * MyBase::mm[ 3] + c * MyBase::mm[11];
852 a0 = c * MyBase::mm[ 0] - s * MyBase::mm[ 4];
853 a1 = c * MyBase::mm[ 1] - s * MyBase::mm[ 5];
854 a2 = c * MyBase::mm[ 2] - s * MyBase::mm[ 6];
855 a3 = c * MyBase::mm[ 3] - s * MyBase::mm[ 7];
857 MyBase::mm[ 4] = s * MyBase::mm[ 0] + c * MyBase::mm[ 4];
858 MyBase::mm[ 5] = s * MyBase::mm[ 1] + c * MyBase::mm[ 5];
859 MyBase::mm[ 6] = s * MyBase::mm[ 2] + c * MyBase::mm[ 6];
860 MyBase::mm[ 7] = s * MyBase::mm[ 3] + c * MyBase::mm[ 7];
880 T c =
static_cast<T
>(cos(angle));
881 T s = -
static_cast<T
>(sin(angle));
890 a2 = c * MyBase::mm[ 2] - s * MyBase::mm[ 1];
891 a6 = c * MyBase::mm[ 6] - s * MyBase::mm[ 5];
892 a10 = c * MyBase::mm[10] - s * MyBase::mm[ 9];
893 a14 = c * MyBase::mm[14] - s * MyBase::mm[13];
896 MyBase::mm[ 1] = c * MyBase::mm[ 1] + s * MyBase::mm[ 2];
897 MyBase::mm[ 5] = c * MyBase::mm[ 5] + s * MyBase::mm[ 6];
898 MyBase::mm[ 9] = c * MyBase::mm[ 9] + s * MyBase::mm[10];
899 MyBase::mm[13] = c * MyBase::mm[13] + s * MyBase::mm[14];
903 MyBase::mm[10] = a10;
904 MyBase::mm[14] = a14;
912 a2 = c * MyBase::mm[ 2] + s * MyBase::mm[ 0];
913 a6 = c * MyBase::mm[ 6] + s * MyBase::mm[ 4];
914 a10 = c * MyBase::mm[10] + s * MyBase::mm[ 8];
915 a14 = c * MyBase::mm[14] + s * MyBase::mm[12];
917 MyBase::mm[ 0] = c * MyBase::mm[ 0] - s * MyBase::mm[ 2];
918 MyBase::mm[ 4] = c * MyBase::mm[ 4] - s * MyBase::mm[ 6];
919 MyBase::mm[ 8] = c * MyBase::mm[ 8] - s * MyBase::mm[10];
920 MyBase::mm[12] = c * MyBase::mm[12] - s * MyBase::mm[14];
924 MyBase::mm[10] = a10;
925 MyBase::mm[14] = a14;
933 a1 = c * MyBase::mm[ 1] - s * MyBase::mm[ 0];
934 a5 = c * MyBase::mm[ 5] - s * MyBase::mm[ 4];
935 a9 = c * MyBase::mm[ 9] - s * MyBase::mm[ 8];
936 a13 = c * MyBase::mm[13] - s * MyBase::mm[12];
938 MyBase::mm[ 0] = c * MyBase::mm[ 0] + s * MyBase::mm[ 1];
939 MyBase::mm[ 4] = c * MyBase::mm[ 4] + s * MyBase::mm[ 5];
940 MyBase::mm[ 8] = c * MyBase::mm[ 8] + s * MyBase::mm[ 9];
941 MyBase::mm[12] = c * MyBase::mm[12] + s * MyBase::mm[13];
946 MyBase::mm[13] = a13;
962 *
this = shear<Mat4<T> >(axis0, axis1, shearby);
970 int index0 =
static_cast<int>(axis0);
971 int index1 =
static_cast<int>(axis1);
974 MyBase::mm[index1 * 4 + 0] += shear * MyBase::mm[index0 * 4 + 0];
975 MyBase::mm[index1 * 4 + 1] += shear * MyBase::mm[index0 * 4 + 1];
976 MyBase::mm[index1 * 4 + 2] += shear * MyBase::mm[index0 * 4 + 2];
977 MyBase::mm[index1 * 4 + 3] += shear * MyBase::mm[index0 * 4 + 3];
985 int index0 =
static_cast<int>(axis0);
986 int index1 =
static_cast<int>(axis1);
989 MyBase::mm[index0 + 0] += shear * MyBase::mm[index1 + 0];
990 MyBase::mm[index0 + 4] += shear * MyBase::mm[index1 + 4];
991 MyBase::mm[index0 + 8] += shear * MyBase::mm[index1 + 8];
992 MyBase::mm[index0 + 12] += shear * MyBase::mm[index1 + 12];
997 template<
typename T0>
1000 return static_cast< Vec4<T0> >(v * *
this);
1004 template<
typename T0>
1007 return static_cast< Vec3<T0> >(v * *
this);
1011 template<
typename T0>
1014 return static_cast< Vec4<T0> >(*
this * v);
1018 template<
typename T0>
1021 return static_cast< Vec3<T0> >(*
this * v);
1025 template<
typename T0>
1031 w =
static_cast<T0
>(p[0] * MyBase::mm[ 3] + p[1] * MyBase::mm[ 7]
1032 + p[2] * MyBase::mm[11] + MyBase::mm[15]);
1035 return Vec3<T0>(
static_cast<T0
>((p[0] * MyBase::mm[ 0] + p[1] * MyBase::mm[ 4] +
1036 p[2] * MyBase::mm[ 8] + MyBase::mm[12]) / w),
1037 static_cast<T0
>((p[0] * MyBase::mm[ 1] + p[1] * MyBase::mm[ 5] +
1038 p[2] * MyBase::mm[ 9] + MyBase::mm[13]) / w),
1039 static_cast<T0
>((p[0] * MyBase::mm[ 2] + p[1] * MyBase::mm[ 6] +
1040 p[2] * MyBase::mm[10] + MyBase::mm[14]) / w));
1047 template<
typename T0>
1053 w = p[0] * MyBase::mm[12] + p[1] * MyBase::mm[13] + p[2] * MyBase::mm[14] + MyBase::mm[15];
1056 return Vec3<T0>(
static_cast<T0
>((p[0] * MyBase::mm[ 0] + p[1] * MyBase::mm[ 1] +
1057 p[2] * MyBase::mm[ 2] + MyBase::mm[ 3]) / w),
1058 static_cast<T0
>((p[0] * MyBase::mm[ 4] + p[1] * MyBase::mm[ 5] +
1059 p[2] * MyBase::mm[ 6] + MyBase::mm[ 7]) / w),
1060 static_cast<T0
>((p[0] * MyBase::mm[ 8] + p[1] * MyBase::mm[ 9] +
1061 p[2] * MyBase::mm[10] + MyBase::mm[11]) / w));
1068 template<
typename T0>
1072 static_cast<T0
>(v[0] * MyBase::mm[ 0] + v[1] * MyBase::mm[ 4] + v[2] * MyBase::mm[ 8]),
1073 static_cast<T0>(v[0] * MyBase::mm[ 1] + v[1] * MyBase::mm[ 5] + v[2] * MyBase::mm[ 9]),
1074 static_cast<T0
>(v[0] * MyBase::mm[ 2] + v[1] * MyBase::mm[ 6] + v[2] * MyBase::mm[10]));
1079 bool invert(
Mat4<T> &inverse, T tolerance)
const;
1081 T det2(
const Mat4<T> &a,
int i0,
int i1,
int j0,
int j1)
const {
1084 return a.
mm[i0row+j0]*a.
mm[i1row+j1] - a.
mm[i0row+j1]*a.
mm[i1row+j0];
1087 T det3(
const Mat4<T> &a,
int i0,
int i1,
int i2,
1088 int j0,
int j1,
int j2)
const {
1090 return a.
mm[i0row+j0]*det2(a, i1,i2, j1,j2) +
1091 a.
mm[i0row+j1]*det2(a, i1,i2, j2,j0) +
1092 a.
mm[i0row+j2]*det2(a, i1,i2, j0,j1);
1099 template <
typename T0,
typename T1>
1105 for (
int i=0; i<16; ++i)
if (!
isExactlyEqual(t0[i], t1[i]))
return false;
1111 template <
typename T0,
typename T1>
1116 template <
typename S,
typename T>
1124 template <
typename S,
typename T>
1134 template<
typename T,
typename MT>
1141 _v[0]*m[0] + _v[1]*m[1] + _v[2]*m[2] + _v[3]*m[3],
1142 _v[0]*m[4] + _v[1]*m[5] + _v[2]*m[6] + _v[3]*m[7],
1143 _v[0]*m[8] + _v[1]*m[9] + _v[2]*m[10] + _v[3]*m[11],
1144 _v[0]*m[12] + _v[1]*m[13] + _v[2]*m[14] + _v[3]*m[15]);
1149 template<
typename T,
typename MT>
1156 _v[0]*m[0] + _v[1]*m[4] + _v[2]*m[8] + _v[3]*m[12],
1157 _v[0]*m[1] + _v[1]*m[5] + _v[2]*m[9] + _v[3]*m[13],
1158 _v[0]*m[2] + _v[1]*m[6] + _v[2]*m[10] + _v[3]*m[14],
1159 _v[0]*m[3] + _v[1]*m[7] + _v[2]*m[11] + _v[3]*m[15]);
1164 template<
typename T,
typename MT>
1170 _v[0]*m[0] + _v[1]*m[1] + _v[2]*m[2] + m[3],
1171 _v[0]*m[4] + _v[1]*m[5] + _v[2]*m[6] + m[7],
1172 _v[0]*m[8] + _v[1]*m[9] + _v[2]*m[10] + m[11]);
1177 template<
typename T,
typename MT>
1183 _v[0]*m[0] + _v[1]*m[4] + _v[2]*m[8] + m[12],
1184 _v[0]*m[1] + _v[1]*m[5] + _v[2]*m[9] + m[13],
1185 _v[0]*m[2] + _v[1]*m[6] + _v[2]*m[10] + m[14]);
1190 template <
typename T0,
typename T1>
1201 template <
typename T0,
typename T1>
1212 template <
typename T0,
typename T1>
1225 template<
typename T0,
typename T1>
1229 static_cast<T1
>(m[0][0]*n[0] + m[0][1]*n[1] + m[0][2]*n[2]),
1230 static_cast<T1>(m[1][0]*n[0] + m[1][1]*n[1] + m[1][2]*n[2]),
1231 static_cast<T1
>(m[2][0]*n[0] + m[2][1]*n[1] + m[2][2]*n[2]));
1236 template<
typename T>
1244 for (
int i = 0; i < 4; ++i) {
1246 double max = fabs(temp[i][i]);
1248 for (
int k = i+1; k < 4; ++k) {
1249 if (fabs(temp[k][i]) > max) {
1251 max = fabs(temp[k][i]);
1260 for (
int k = 0; k < 4; ++k) {
1261 std::swap(temp[row][k], temp[i][k]);
1262 std::swap(inverse[row][k], inverse[i][k]);
1266 double pivot = temp[i][i];
1270 for (
int k = 0; k < 4; ++k) {
1271 temp[i][k] /=
pivot;
1272 inverse[i][k] /=
pivot;
1276 for (
int j = i+1; j < 4; ++j) {
1277 double t = temp[j][i];
1280 for (
int k = 0; k < 4; ++k) {
1281 temp[j][k] -= temp[i][k] * t;
1282 inverse[j][k] -= inverse[i][k] * t;
1289 for (
int i = 3; i > 0; --i) {
1290 for (
int j = 0; j < i; ++j) {
1291 double t = temp[j][i];
1294 for (
int k = 0; k < 4; ++k) {
1295 inverse[j][k] -= inverse[i][k]*t;
1300 return det*det >= tolerance*tolerance;
1303 template <
typename T>
1308 template <
typename T>
1313 template<
typename T>
1320 for (
unsigned i = 0; i < 16; ++i, ++op, ++ip) *op =
math::Abs(*ip);
1324 template<
typename Type1,
typename Type2>
1331 for (
unsigned i = 0; i < 16; ++i, ++op, ++ip) {
1339 template<
typename T>
1343 return cwiseLessThan<4, T>(m0, m1);
1346 template<
typename T>
1350 return cwiseGreaterThan<4, T>(m0, m1);
1364 template<>
inline math::Mat4d zeroVal<math::Mat4d>() {
return math::Mat4d::zero(); }
1369 #endif // OPENVDB_UTIL_MAT4_H_HAS_BEEN_INCLUDED Mat4< typename promote< T0, T1 >::type > operator-(const Mat4< T0 > &m0, const Mat4< T1 > &m1)
Subtract corresponding elements of m0 and m1 and return the result.
Definition: Mat4.h:1203
void setIdentity()
Set this matrix to identity.
Definition: Mat4.h:265
void setToScale(const Vec3< T0 > &v)
Sets the matrix to a matrix that scales by v.
Definition: Mat4.h:726
bool cwiseGreaterThan(const Mat4< T > &m0, const Mat4< T > &m1)
Definition: Mat4.h:1348
Vec4< T > row(int i) const
Get ith row, e.g. Vec4f v = m.row(1);.
Definition: Mat4.h:150
void setColumns(const Vec4< T > &v1, const Vec4< T > &v2, const Vec4< T > &v3, const Vec4< T > &v4)
Set the columns of this matrix to the vectors v1, v2, v3, v4.
Definition: Mat4.h:219
void pivot(int i, int j, Mat3< T > &S, Vec3< T > &D, Mat3< T > &Q)
Definition: Mat3.h:668
T operator()(int i, int j) const
Definition: Mat4.h:186
const Mat4< T > & operator-=(const Mat4< S > &m1)
Subtract each element of the given matrix from the corresponding element of this matrix.
Definition: Mat4.h:410
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
Mat4< double > Mat4d
Definition: Mat4.h:1354
void setToRotation(Axis axis, T angle)
Sets the matrix to a rotation about the given axis.
Definition: Mat4.h:783
constexpr T zeroVal()
Return the value of type T that corresponds to zero.
Definition: Math.h:70
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:443
Mat4(Source a, Source b, Source c, Source d, Source e, Source f, Source g, Source h, Source i, Source j, Source k, Source l, Source m, Source n, Source o, Source p)
Constructor given array of elements, the ordering is in row major form:
Definition: Mat4.h:66
void postTranslate(const Vec3< T0 > &tr)
Right multiplies by the specified translation matrix, i.e. (*this) * Trans.
Definition: Mat4.h:714
Mat4(Source *a)
Constructor given array of elements, the ordering is in row major form:
Definition: Mat4.h:51
static const Mat4< T > & zero()
Predefined constant for zero matrix.
Definition: Mat4.h:128
void postShear(Axis axis0, Axis axis1, T shear)
Right multiplies a shearing transformation into the matrix.
Definition: Mat4.h:983
static const Mat4< T > & identity()
Predefined constant for identity matrix.
Definition: Mat4.h:117
Definition: Exceptions.h:56
void setRows(const Vec4< T > &v1, const Vec4< T > &v2, const Vec4< T > &v3, const Vec4< T > &v4)
Set the rows of this matrix to the vectors v1, v2, v3, v4.
Definition: Mat4.h:194
Real value_type
Definition: Mat.h:29
Vec4< typename promote< T, MT >::type > operator*(const Vec4< T > &_v, const Mat4< MT > &_m)
Multiply _v by _m and return the resulting vector.
Definition: Mat4.h:1151
Mat4(const Mat4< Source > &m)
Conversion constructor.
Definition: Mat4.h:107
void postScale(const Vec3< T0 > &v)
Definition: Mat4.h:758
void setToRotation(const Vec3< T > &axis, T angle)
Sets the matrix to a rotation about an arbitrary axis.
Definition: Mat4.h:788
const Mat4< T > & operator*=(S scalar)
Multiply each element of this matrix by scalar.
Definition: Mat4.h:355
Mat4< typename promote< T0, T1 >::type > operator+(const Mat4< T0 > &m0, const Mat4< T1 > &m1)
Add corresponding elements of m0 and m1 and return the result.
Definition: Mat4.h:1192
static Mat4 translation(const Vec3d &v)
Sets the matrix to a matrix that translates by v.
Definition: Mat4.h:667
Mat3< T > getMat3() const
Definition: Mat4.h:297
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
Definition: Vec2.h:446
Vec4< typename promote< T, MT >::type > operator*(const Mat4< MT > &_m, const Vec4< T > &_v)
Multiply _m by _v and return the resulting vector.
Definition: Mat4.h:1136
Vec3< T0 > transformH(const Vec3< T0 > &p) const
Transform a Vec3 by post-multiplication, doing homogenous divison.
Definition: Mat4.h:1026
void preRotate(Axis axis, T angle)
Left multiplies by a rotation clock-wiseabout the given axis into this matrix.
Definition: Mat4.h:798
Vec3< T1 > transformNormal(const Mat4< T0 > &m, const Vec3< T1 > &n)
Definition: Mat4.h:1226
void setCol(int j, const Vec4< T > &v)
Set jth column to vector v.
Definition: Mat4.h:157
void setToTranslation(const Vec3< T0 > &v)
Sets the matrix to a matrix that translates by v.
Definition: Mat4.h:678
bool eq(const Mat4 &m, T eps=1.0e-8) const
Return true if this matrix is equivalent to m within a tolerance of eps.
Definition: Mat4.h:333
T mm[SIZE *SIZE]
Definition: Mat.h:160
T & y()
Definition: Vec3.h:86
T & operator()(int i, int j)
Definition: Mat4.h:176
T dot(const Vec3< T > &v) const
Dot product.
Definition: Vec3.h:191
void preScale(const Vec3< T0 > &v)
Definition: Mat4.h:736
Vec3< T0 > pretransform(const Vec3< T0 > &v) const
Transform a Vec3 by pre-multiplication, without homogenous division.
Definition: Mat4.h:1019
Axis
Definition: Math.h:901
bool isAffine(const Mat4< T > &m)
Definition: Mat4.h:1304
Mat4(const Vec4< Source > &v1, const Vec4< Source > &v2, const Vec4< Source > &v3, const Vec4< Source > &v4, bool rows=true)
Definition: Mat4.h:95
Mat4 inverse(T tolerance=0) const
Definition: Mat4.h:485
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
Definition: Math.h:406
Mat4< T > Abs(const Mat4< T > &m)
Definition: Mat4.h:1315
Definition: Exceptions.h:13
T det() const
Determinant of matrix.
Definition: Mat4.h:637
void preShear(Axis axis0, Axis axis1, T shear)
Left multiplies a shearing transformation into the matrix.
Definition: Mat4.h:968
Mat4< T > operator-() const
Negation operator, for e.g. m1 = -m2;.
Definition: Mat4.h:343
void preTranslate(const Vec3< T0 > &tr)
Left multiples by the specified translation, i.e. Trans * (*this)
Definition: Mat4.h:703
Mat4< Type1 > cwiseAdd(const Mat4< Type1 > &m, const Type2 s)
Definition: Mat4.h:1326
const Mat4< T > & operator*=(const Mat4< S > &m1)
Multiply this matrix by the given matrix.
Definition: Mat4.h:439
Real ValueType
Definition: Mat.h:30
T & z()
Definition: Vec3.h:87
Mat4 transpose() const
Definition: Mat4.h:472
Vec3< typename promote< T, MT >::type > operator*(const Mat4< MT > &_m, const Vec3< T > &_v)
Multiply _m by _v and return the resulting vector.
Definition: Mat4.h:1166
3x3 matrix class.
Definition: Mat3.h:28
bool cwiseLessThan(const Mat4< T > &m0, const Mat4< T > &m1)
Definition: Mat4.h:1341
const Mat4 & operator=(const Mat4< Source > &m)
Assignment operator.
Definition: Mat4.h:323
Vec4< T > col(int j) const
Get jth column, e.g. Vec4f v = m.col(0);.
Definition: Mat4.h:167
Mat4< typename promote< S, T >::type > operator*(S scalar, const Mat4< T > &m)
Multiply each element of the given matrix by scalar and return the result.
Definition: Mat4.h:1117
Mat4< float > Mat4s
Definition: Mat4.h:1353
Vec4< T0 > transform(const Vec4< T0 > &v) const
Transform a Vec4 by post-multiplication.
Definition: Mat4.h:998
void setMat3(const Mat3< T > &m)
Set upper left to a Mat3.
Definition: Mat4.h:290
Vec4< T0 > pretransform(const Vec4< T0 > &v) const
Transform a Vec4 by pre-multiplication.
Definition: Mat4.h:1012
void setToRotation(const Vec3< T > &v1, const Vec3< T > &v2)
Sets the matrix to a rotation that maps v1 onto v2 about the cross product of v1 and v2...
Definition: Mat4.h:792
bool hasTranslation(const Mat4< T > &m)
Definition: Mat4.h:1309
T * asPointer()
Direct access to the internal data.
Definition: Mat.h:101
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
Vec3< T > getTranslation() const
Return the translation component.
Definition: Mat4.h:309
Mat4< typename promote< S, T >::type > operator*(const Mat4< T > &m, S scalar)
Multiply each element of the given matrix by scalar and return the result.
Definition: Mat4.h:1125
Vec3< T0 > pretransformH(const Vec3< T0 > &p) const
Transform a Vec3 by pre-multiplication, doing homogenous division.
Definition: Mat4.h:1048
void setRow(int i, const Vec4< T > &v)
Set ith row to vector v.
Definition: Mat4.h:139
Vec3< T0 > transform(const Vec3< T0 > &v) const
Transform a Vec3 by post-multiplication, without homogenous division.
Definition: Mat4.h:1005
void setToShear(Axis axis0, Axis axis1, T shearby)
Sets the matrix to a shear along axis0 by a fraction of axis1.
Definition: Mat4.h:960
bool operator==(const Mat4< T0 > &m0, const Mat4< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat4.h:1100
bool operator!=(const Mat4< T0 > &m0, const Mat4< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat4.h:1112
Mat4< typename promote< T0, T1 >::type > operator*(const Mat4< T0 > &m0, const Mat4< T1 > &m1)
Multiply m0 by m1 and return the resulting matrix.
Definition: Mat4.h:1214
Vec3< typename promote< T, MT >::type > operator*(const Vec3< T > &_v, const Mat4< MT > &_m)
Multiply _v by _m and return the resulting vector.
Definition: Mat4.h:1179
void postRotate(Axis axis, T angle)
Right multiplies by a rotation clock-wiseabout the given axis into this matrix.
Definition: Mat4.h:878
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:85
4x4 -matrix class.
Definition: Mat3.h:22
void setTranslation(const Vec3< T > &t)
Definition: Mat4.h:314
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:212
MatType shear(Axis axis0, Axis axis1, typename MatType::value_type shear)
Set the matrix to a shear along axis0 by a fraction of axis1.
Definition: Mat.h:688
const Mat4< T > & operator+=(const Mat4< S > &m1)
Add each element of the given matrix to the corresponding element of this matrix. ...
Definition: Mat4.h:381
void setZero()
Definition: Mat4.h:244
T det() const
Determinant of matrix.
Definition: Mat3.h:479
#define OPENVDB_IS_POD(Type)
Definition: Math.h:56
Vec3< T0 > transform3x3(const Vec3< T0 > &v) const
Transform a Vec3 by post-multiplication, without translation.
Definition: Mat4.h:1069