5 #ifndef __IRR_MATRIX_H_INCLUDED__ 6 #define __IRR_MATRIX_H_INCLUDED__ 24 #if defined( USE_MATRIX_TEST_DEBUG ) 28 MatrixTest () : ID(0), Calls(0) {}
33 static MatrixTest MTest;
65 CMatrix4(
const T& r0c0,
const T& r0c1,
const T& r0c2,
const T& r0c3,
66 const T& r1c0,
const T& r1c1,
const T& r1c2,
const T& r1c3,
67 const T& r2c0,
const T& r2c1,
const T& r2c2,
const T& r2c3,
68 const T& r3c0,
const T& r3c1,
const T& r3c2,
const T& r3c3)
70 M[0] = r0c0; M[1] = r0c1; M[2] = r0c2; M[3] = r0c3;
71 M[4] = r1c0; M[5] = r1c1; M[6] = r1c2; M[7] = r1c3;
72 M[8] = r2c0; M[9] = r2c1; M[10] = r2c2; M[11] = r2c3;
73 M[12] = r3c0; M[13] = r3c1; M[14] = r3c2; M[15] = r3c3;
84 #if defined ( USE_MATRIX_TEST ) 85 definitelyIdentityMatrix=
false;
87 return M[
row * 4 + col ];
96 #if defined ( USE_MATRIX_TEST ) 97 definitelyIdentityMatrix=
false;
115 #if defined ( USE_MATRIX_TEST ) 116 definitelyIdentityMatrix=
false;
446 #if defined ( USE_MATRIX_TEST ) 447 mutable u32 definitelyIdentityMatrix;
450 #if defined ( USE_MATRIX_TEST_DEBUG ) 460 #if defined ( USE_MATRIX_TEST ) 461 : definitelyIdentityMatrix(BIT_UNTESTED)
463 #if defined ( USE_MATRIX_TEST_DEBUG ) 464 ,
id ( MTest.ID++), calls ( 0 )
467 switch ( constructor )
469 case EM4CONST_NOTHING:
472 case EM4CONST_IDENTITY:
473 case EM4CONST_INVERSE:
483 #if defined ( USE_MATRIX_TEST ) 484 : definitelyIdentityMatrix(BIT_UNTESTED)
486 #if defined ( USE_MATRIX_TEST_DEBUG ) 487 ,
id ( MTest.ID++), calls ( 0 )
490 switch ( constructor )
492 case EM4CONST_IDENTITY:
495 case EM4CONST_NOTHING:
500 case EM4CONST_TRANSPOSED:
503 case EM4CONST_INVERSE:
505 memset(M, 0, 16*
sizeof(T));
507 case EM4CONST_INVERSE_TRANSPOSED:
509 memset(M, 0, 16*
sizeof(T));
511 *
this=getTransposed();
522 temp[0] = M[0]+other[0];
523 temp[1] = M[1]+other[1];
524 temp[2] = M[2]+other[2];
525 temp[3] = M[3]+other[3];
526 temp[4] = M[4]+other[4];
527 temp[5] = M[5]+other[5];
528 temp[6] = M[6]+other[6];
529 temp[7] = M[7]+other[7];
530 temp[8] = M[8]+other[8];
531 temp[9] = M[9]+other[9];
532 temp[10] = M[10]+other[10];
533 temp[11] = M[11]+other[11];
534 temp[12] = M[12]+other[12];
535 temp[13] = M[13]+other[13];
536 temp[14] = M[14]+other[14];
537 temp[15] = M[15]+other[15];
572 temp[0] = M[0]-other[0];
573 temp[1] = M[1]-other[1];
574 temp[2] = M[2]-other[2];
575 temp[3] = M[3]-other[3];
576 temp[4] = M[4]-other[4];
577 temp[5] = M[5]-other[5];
578 temp[6] = M[6]-other[6];
579 temp[7] = M[7]-other[7];
580 temp[8] = M[8]-other[8];
581 temp[9] = M[9]-other[9];
582 temp[10] = M[10]-other[10];
583 temp[11] = M[11]-other[11];
584 temp[12] = M[12]-other[12];
585 temp[13] = M[13]-other[13];
586 temp[14] = M[14]-other[14];
587 temp[15] = M[15]-other[15];
622 temp[0] = M[0]*scalar;
623 temp[1] = M[1]*scalar;
624 temp[2] = M[2]*scalar;
625 temp[3] = M[3]*scalar;
626 temp[4] = M[4]*scalar;
627 temp[5] = M[5]*scalar;
628 temp[6] = M[6]*scalar;
629 temp[7] = M[7]*scalar;
630 temp[8] = M[8]*scalar;
631 temp[9] = M[9]*scalar;
632 temp[10] = M[10]*scalar;
633 temp[11] = M[11]*scalar;
634 temp[12] = M[12]*scalar;
635 temp[13] = M[13]*scalar;
636 temp[14] = M[14]*scalar;
637 temp[15] = M[15]*scalar;
670 #if defined ( USE_MATRIX_TEST ) 674 if ( this->isIdentity() )
676 return (*
this = other);
681 return setbyproduct_nocheck( temp, other );
687 return setbyproduct_nocheck( temp, other );
697 const T *m1 = other_a.M;
698 const T *m2 = other_b.M;
700 M[0] = m1[0]*m2[0] + m1[4]*m2[1] + m1[8]*m2[2] + m1[12]*m2[3];
701 M[1] = m1[1]*m2[0] + m1[5]*m2[1] + m1[9]*m2[2] + m1[13]*m2[3];
702 M[2] = m1[2]*m2[0] + m1[6]*m2[1] + m1[10]*m2[2] + m1[14]*m2[3];
703 M[3] = m1[3]*m2[0] + m1[7]*m2[1] + m1[11]*m2[2] + m1[15]*m2[3];
705 M[4] = m1[0]*m2[4] + m1[4]*m2[5] + m1[8]*m2[6] + m1[12]*m2[7];
706 M[5] = m1[1]*m2[4] + m1[5]*m2[5] + m1[9]*m2[6] + m1[13]*m2[7];
707 M[6] = m1[2]*m2[4] + m1[6]*m2[5] + m1[10]*m2[6] + m1[14]*m2[7];
708 M[7] = m1[3]*m2[4] + m1[7]*m2[5] + m1[11]*m2[6] + m1[15]*m2[7];
710 M[8] = m1[0]*m2[8] + m1[4]*m2[9] + m1[8]*m2[10] + m1[12]*m2[11];
711 M[9] = m1[1]*m2[8] + m1[5]*m2[9] + m1[9]*m2[10] + m1[13]*m2[11];
712 M[10] = m1[2]*m2[8] + m1[6]*m2[9] + m1[10]*m2[10] + m1[14]*m2[11];
713 M[11] = m1[3]*m2[8] + m1[7]*m2[9] + m1[11]*m2[10] + m1[15]*m2[11];
715 M[12] = m1[0]*m2[12] + m1[4]*m2[13] + m1[8]*m2[14] + m1[12]*m2[15];
716 M[13] = m1[1]*m2[12] + m1[5]*m2[13] + m1[9]*m2[14] + m1[13]*m2[15];
717 M[14] = m1[2]*m2[12] + m1[6]*m2[13] + m1[10]*m2[14] + m1[14]*m2[15];
718 M[15] = m1[3]*m2[12] + m1[7]*m2[13] + m1[11]*m2[14] + m1[15]*m2[15];
719 #if defined ( USE_MATRIX_TEST ) 720 definitelyIdentityMatrix=
false;
732 #if defined ( USE_MATRIX_TEST ) 734 return (*
this = other_b);
737 return (*
this = other_a);
739 return setbyproduct_nocheck(other_a,other_b);
741 return setbyproduct_nocheck(other_a,other_b);
749 #if defined ( USE_MATRIX_TEST ) 751 if ( this->isIdentity() )
761 m3[0] = m1[0]*m2[0] + m1[4]*m2[1] + m1[8]*m2[2] + m1[12]*m2[3];
762 m3[1] = m1[1]*m2[0] + m1[5]*m2[1] + m1[9]*m2[2] + m1[13]*m2[3];
763 m3[2] = m1[2]*m2[0] + m1[6]*m2[1] + m1[10]*m2[2] + m1[14]*m2[3];
764 m3[3] = m1[3]*m2[0] + m1[7]*m2[1] + m1[11]*m2[2] + m1[15]*m2[3];
766 m3[4] = m1[0]*m2[4] + m1[4]*m2[5] + m1[8]*m2[6] + m1[12]*m2[7];
767 m3[5] = m1[1]*m2[4] + m1[5]*m2[5] + m1[9]*m2[6] + m1[13]*m2[7];
768 m3[6] = m1[2]*m2[4] + m1[6]*m2[5] + m1[10]*m2[6] + m1[14]*m2[7];
769 m3[7] = m1[3]*m2[4] + m1[7]*m2[5] + m1[11]*m2[6] + m1[15]*m2[7];
771 m3[8] = m1[0]*m2[8] + m1[4]*m2[9] + m1[8]*m2[10] + m1[12]*m2[11];
772 m3[9] = m1[1]*m2[8] + m1[5]*m2[9] + m1[9]*m2[10] + m1[13]*m2[11];
773 m3[10] = m1[2]*m2[8] + m1[6]*m2[9] + m1[10]*m2[10] + m1[14]*m2[11];
774 m3[11] = m1[3]*m2[8] + m1[7]*m2[9] + m1[11]*m2[10] + m1[15]*m2[11];
776 m3[12] = m1[0]*m2[12] + m1[4]*m2[13] + m1[8]*m2[14] + m1[12]*m2[15];
777 m3[13] = m1[1]*m2[12] + m1[5]*m2[13] + m1[9]*m2[14] + m1[13]*m2[15];
778 m3[14] = m1[2]*m2[12] + m1[6]*m2[13] + m1[10]*m2[14] + m1[14]*m2[15];
779 m3[15] = m1[3]*m2[12] + m1[7]*m2[13] + m1[11]*m2[14] + m1[15]*m2[15];
795 M[12] = translation.
X;
796 M[13] = translation.
Y;
797 M[14] = translation.
Z;
798 #if defined ( USE_MATRIX_TEST ) 799 definitelyIdentityMatrix=
false;
807 M[12] = -translation.
X;
808 M[13] = -translation.
Y;
809 M[14] = -translation.
Z;
810 #if defined ( USE_MATRIX_TEST ) 811 definitelyIdentityMatrix=
false;
822 #if defined ( USE_MATRIX_TEST ) 823 definitelyIdentityMatrix=
false;
849 return vector3d<T>(sqrtf(M[0] * M[0] + M[1] * M[1] + M[2] * M[2]),
850 sqrtf(M[4] * M[4] + M[5] * M[5] + M[6] * M[6]),
851 sqrtf(M[8] * M[8] + M[9] * M[9] + M[10] * M[10]));
869 const f64 cr = cos( rotation.
X );
870 const f64 sr = sin( rotation.
X );
871 const f64 cp = cos( rotation.
Y );
872 const f64 sp = sin( rotation.
Y );
873 const f64 cy = cos( rotation.
Z );
874 const f64 sy = sin( rotation.
Z );
880 const f64 srsp = sr*sp;
881 const f64 crsp = cr*sp;
883 M[4] = (T)( srsp*cy-cr*sy );
884 M[5] = (T)( srsp*sy+cr*cy );
887 M[8] = (T)( crsp*cy+sr*sy );
888 M[9] = (T)( crsp*sy-sr*cy );
889 M[10] = (T)( cr*cp );
890 #if defined ( USE_MATRIX_TEST ) 891 definitelyIdentityMatrix=
false;
927 const f64 C = cos(Y);
930 f64 rotx, roty, X, Z;
935 rotx = mat[10] * invC * invScale.
Z;
936 roty = mat[6] * invC * invScale.
Y;
938 rotx = mat[0] * invC * invScale.
X;
939 roty = mat[1] * invC * invScale.
X;
945 rotx = mat[5] * invScale.
Y;
946 roty = -mat[4] * invScale.
Y;
951 if (X < 0.0) X += 360.0;
952 if (Y < 0.0) Y += 360.0;
953 if (Z < 0.0) Z += 360.0;
966 return getRotationDegrees(getScale());
974 f64 cr = cos( rotation.
X );
975 f64 sr = sin( rotation.
X );
976 f64 cp = cos( rotation.
Y );
977 f64 sp = sin( rotation.
Y );
978 f64 cy = cos( rotation.
Z );
979 f64 sy = sin( rotation.
Z );
988 M[1] = (T)( srsp*cy-cr*sy );
989 M[5] = (T)( srsp*sy+cr*cy );
992 M[2] = (T)( crsp*cy+sr*sy );
993 M[6] = (T)( crsp*sy-sr*cy );
994 M[10] = (T)( cr*cp );
995 #if defined ( USE_MATRIX_TEST ) 996 definitelyIdentityMatrix=
false;
1007 const f64 t = 1.0 -
c;
1009 const f64 tx =
t * axis.
X;
1013 const f64 sx =
s * axis.
X;
1014 const f64 sy =
s * axis.
Y;
1015 const f64 sz =
s * axis.
Z;
1017 M[0] = (T)(tx * axis.
X +
c);
1018 M[1] = (T)(tx * axis.
Y + sz);
1019 M[2] = (T)(tx * axis.
Z - sy);
1021 M[4] = (T)(
ty * axis.
X - sz);
1022 M[5] = (T)(
ty * axis.
Y +
c);
1023 M[6] = (T)(
ty * axis.
Z + sx);
1025 M[8] = (T)(
tz * axis.
X + sy);
1026 M[9] = (T)(
tz * axis.
Y - sx);
1027 M[10] = (T)(
tz * axis.
Z +
c);
1029 #if defined ( USE_MATRIX_TEST ) 1030 definitelyIdentityMatrix=
false;
1041 memset(M, 0, 16*
sizeof(T));
1042 M[0] = M[5] = M[10] = M[15] = (T)1;
1043 #if defined ( USE_MATRIX_TEST ) 1044 definitelyIdentityMatrix=
true;
1057 #if defined ( USE_MATRIX_TEST ) 1058 if (definitelyIdentityMatrix)
1084 #if defined ( USE_MATRIX_TEST ) 1085 definitelyIdentityMatrix=
true;
1095 T dp=M[0] * M[4 ] + M[1] * M[5 ] + M[2 ] * M[6 ] + M[3 ] * M[7 ];
1098 dp = M[0] * M[8 ] + M[1] * M[9 ] + M[2 ] * M[10] + M[3 ] * M[11];
1101 dp = M[0] * M[12] + M[1] * M[13] + M[2 ] * M[14] + M[3 ] * M[15];
1104 dp = M[4] * M[8 ] + M[5] * M[9 ] + M[6 ] * M[10] + M[7 ] * M[11];
1107 dp = M[4] * M[12] + M[5] * M[13] + M[6 ] * M[14] + M[7 ] * M[15];
1110 dp = M[8] * M[12] + M[9] * M[13] + M[10] * M[14] + M[11] * M[15];
1124 #if defined ( USE_MATRIX_TEST ) 1125 if (definitelyIdentityMatrix)
1129 if(
IR(M[1])!=0)
return false;
1130 if(
IR(M[2])!=0)
return false;
1131 if(
IR(M[3])!=0)
return false;
1133 if(
IR(M[4])!=0)
return false;
1135 if(
IR(M[6])!=0)
return false;
1136 if(
IR(M[7])!=0)
return false;
1138 if(
IR(M[8])!=0)
return false;
1139 if(
IR(M[9])!=0)
return false;
1141 if(
IR(M[11])!=0)
return false;
1143 if(
IR(M[12])!=0)
return false;
1144 if(
IR(M[13])!=0)
return false;
1145 if(
IR(M[13])!=0)
return false;
1148 #if defined ( USE_MATRIX_TEST ) 1149 definitelyIdentityMatrix=
true;
1159 vect.
X = tmp.
X*M[0] + tmp.
Y*M[4] + tmp.
Z*M[8];
1160 vect.
Y = tmp.
X*M[1] + tmp.
Y*M[5] + tmp.
Z*M[9];
1161 vect.
Z = tmp.
X*M[2] + tmp.
Y*M[6] + tmp.
Z*M[10];
1168 out.
X =
in.X*M[0] +
in.Y*M[4] +
in.Z*M[8];
1169 out.
Y =
in.X*M[1] +
in.Y*M[5] +
in.Z*M[9];
1170 out.
Z =
in.X*M[2] +
in.Y*M[6] +
in.Z*M[10];
1177 out[0] =
in.X*M[0] +
in.Y*M[4] +
in.Z*M[8];
1178 out[1] =
in.X*M[1] +
in.Y*M[5] +
in.Z*M[9];
1179 out[2] =
in.X*M[2] +
in.Y*M[6] +
in.Z*M[10];
1186 vect.
X = tmp.
X*M[0] + tmp.
Y*M[1] + tmp.
Z*M[2];
1187 vect.
Y = tmp.
X*M[4] + tmp.
Y*M[5] + tmp.
Z*M[6];
1188 vect.
Z = tmp.
X*M[8] + tmp.
Y*M[9] + tmp.
Z*M[10];
1196 vector[0] = vect.
X*M[0] + vect.
Y*M[4] + vect.
Z*M[8] + M[12];
1197 vector[1] = vect.
X*M[1] + vect.
Y*M[5] + vect.
Z*M[9] + M[13];
1198 vector[2] = vect.
X*M[2] + vect.
Y*M[6] + vect.
Z*M[10] + M[14];
1208 out.
X =
in.X*M[0] +
in.Y*M[4] +
in.Z*M[8] + M[12];
1209 out.
Y =
in.X*M[1] +
in.Y*M[5] +
in.Z*M[9] + M[13];
1210 out.
Z =
in.X*M[2] +
in.Y*M[6] +
in.Z*M[10] + M[14];
1217 out[0] =
in.X*M[0] +
in.Y*M[4] +
in.Z*M[8] + M[12];
1218 out[1] =
in.X*M[1] +
in.Y*M[5] +
in.Z*M[9] + M[13];
1219 out[2] =
in.X*M[2] +
in.Y*M[6] +
in.Z*M[10] + M[14];
1220 out[3] =
in.X*M[3] +
in.Y*M[7] +
in.Z*M[11] + M[15];
1226 out[0] =
in[0]*M[0] +
in[1]*M[4] +
in[2]*M[8] + M[12];
1227 out[1] =
in[0]*M[1] +
in[1]*M[5] +
in[2]*M[9] + M[13];
1228 out[2] =
in[0]*M[2] +
in[1]*M[6] +
in[2]*M[10] + M[14];
1234 out[0] =
in[0]*M[0] +
in[1]*M[4] +
in[2]*M[8] +
in[3]*M[12];
1235 out[1] =
in[0]*M[1] +
in[1]*M[5] +
in[2]*M[9] +
in[3]*M[13];
1236 out[2] =
in[0]*M[2] +
in[1]*M[6] +
in[2]*M[10] +
in[3]*M[14];
1237 out[3] =
in[0]*M[3] +
in[1]*M[7] +
in[2]*M[11] +
in[3]*M[15];
1250 CMatrix4<T> transposedInverse(*
this, EM4CONST_INVERSE_TRANSPOSED);
1252 transposedInverse.rotateVect(normal);
1261 transformPlane( out );
1270 #if defined ( USE_MATRIX_TEST ) 1284 #if defined ( USE_MATRIX_TEST ) 1295 Bmin[0] = Bmax[0] = M[12];
1296 Bmin[1] = Bmax[1] = M[13];
1297 Bmin[2] = Bmax[2] = M[14];
1301 for (
u32 i = 0; i < 3; ++i)
1303 for (
u32 j = 0; j < 3; ++j)
1305 const f32 a =
m(j,i) * Amin[j];
1306 const f32 b =
m(j,i) * Amax[j];
1348 matrix[0] = M[0]*mat[0] + M[4]*mat[1] + M[8]*mat[2] + M[12]*mat[3];
1349 matrix[1] = M[1]*mat[0] + M[5]*mat[1] + M[9]*mat[2] + M[13]*mat[3];
1350 matrix[2] = M[2]*mat[0] + M[6]*mat[1] + M[10]*mat[2] + M[14]*mat[3];
1351 matrix[3] = M[3]*mat[0] + M[7]*mat[1] + M[11]*mat[2] + M[15]*mat[3];
1357 vect.
X = vect.
X-M[12];
1358 vect.
Y = vect.
Y-M[13];
1359 vect.
Z = vect.
Z-M[14];
1365 vect.
X = vect.
X+M[12];
1366 vect.
Y = vect.
Y+M[13];
1367 vect.
Z = vect.
Z+M[14];
1378 #if defined ( USE_MATRIX_TEST ) 1379 if ( this->isIdentity() )
1387 f32 d = (
m[0] *
m[5] -
m[1] *
m[4]) * (
m[10] *
m[15] -
m[11] *
m[14]) -
1388 (
m[0] *
m[6] -
m[2] *
m[4]) * (
m[9] *
m[15] -
m[11] *
m[13]) +
1389 (
m[0] *
m[7] -
m[3] *
m[4]) * (
m[9] *
m[14] -
m[10] *
m[13]) +
1390 (
m[1] *
m[6] -
m[2] *
m[5]) * (
m[8] *
m[15] -
m[11] *
m[12]) -
1391 (
m[1] *
m[7] -
m[3] *
m[5]) * (
m[8] *
m[14] -
m[10] *
m[12]) +
1392 (
m[2] *
m[7] -
m[3] *
m[6]) * (
m[8] *
m[13] -
m[9] *
m[12]);
1399 out[0] = d * (
m[5] * (
m[10] *
m[15] -
m[11] *
m[14]) +
1400 m[6] * (
m[11] *
m[13] -
m[9] *
m[15]) +
1401 m[7] * (
m[9] *
m[14] -
m[10] *
m[13]));
1402 out[1] = d * (
m[9] * (
m[2] *
m[15] -
m[3] *
m[14]) +
1403 m[10] * (
m[3] *
m[13] -
m[1] *
m[15]) +
1404 m[11] * (
m[1] *
m[14] -
m[2] *
m[13]));
1405 out[2] = d * (
m[13] * (
m[2] *
m[7] -
m[3] *
m[6]) +
1406 m[14] * (
m[3] *
m[5] -
m[1] *
m[7]) +
1407 m[15] * (
m[1] *
m[6] -
m[2] *
m[5]));
1408 out[3] = d * (
m[1] * (
m[7] *
m[10] -
m[6] *
m[11]) +
1409 m[2] * (
m[5] *
m[11] -
m[7] *
m[9]) +
1410 m[3] * (
m[6] *
m[9] -
m[5] *
m[10]));
1411 out[4] = d * (
m[6] * (
m[8] *
m[15] -
m[11] *
m[12]) +
1412 m[7] * (
m[10] *
m[12] -
m[8] *
m[14]) +
1413 m[4] * (
m[11] *
m[14] -
m[10] *
m[15]));
1414 out[5] = d * (
m[10] * (
m[0] *
m[15] -
m[3] *
m[12]) +
1415 m[11] * (
m[2] *
m[12] -
m[0] *
m[14]) +
1416 m[8] * (
m[3] *
m[14] -
m[2] *
m[15]));
1417 out[6] = d * (
m[14] * (
m[0] *
m[7] -
m[3] *
m[4]) +
1418 m[15] * (
m[2] *
m[4] -
m[0] *
m[6]) +
1419 m[12] * (
m[3] *
m[6] -
m[2] *
m[7]));
1420 out[7] = d * (
m[2] * (
m[7] *
m[8] -
m[4] *
m[11]) +
1421 m[3] * (
m[4] *
m[10] -
m[6] *
m[8]) +
1422 m[0] * (
m[6] *
m[11] -
m[7] *
m[10]));
1423 out[8] = d * (
m[7] * (
m[8] *
m[13] -
m[9] *
m[12]) +
1424 m[4] * (
m[9] *
m[15] -
m[11] *
m[13]) +
1425 m[5] * (
m[11] *
m[12] -
m[8] *
m[15]));
1426 out[9] = d * (
m[11] * (
m[0] *
m[13] -
m[1] *
m[12]) +
1427 m[8] * (
m[1] *
m[15] -
m[3] *
m[13]) +
1428 m[9] * (
m[3] *
m[12] -
m[0] *
m[15]));
1429 out[10] = d * (
m[15] * (
m[0] *
m[5] -
m[1] *
m[4]) +
1430 m[12] * (
m[1] *
m[7] -
m[3] *
m[5]) +
1431 m[13] * (
m[3] *
m[4] -
m[0] *
m[7]));
1432 out[11] = d * (
m[3] * (
m[5] *
m[8] -
m[4] *
m[9]) +
1433 m[0] * (
m[7] *
m[9] -
m[5] *
m[11]) +
1434 m[1] * (
m[4] *
m[11] -
m[7] *
m[8]));
1435 out[12] = d * (
m[4] * (
m[10] *
m[13] -
m[9] *
m[14]) +
1436 m[5] * (
m[8] *
m[14] -
m[10] *
m[12]) +
1437 m[6] * (
m[9] *
m[12] -
m[8] *
m[13]));
1438 out[13] = d * (
m[8] * (
m[2] *
m[13] -
m[1] *
m[14]) +
1439 m[9] * (
m[0] *
m[14] -
m[2] *
m[12]) +
1440 m[10] * (
m[1] *
m[12] -
m[0] *
m[13]));
1441 out[14] = d * (
m[12] * (
m[2] *
m[5] -
m[1] *
m[6]) +
1442 m[13] * (
m[0] *
m[6] -
m[2] *
m[4]) +
1443 m[14] * (
m[1] *
m[4] -
m[0] *
m[5]));
1444 out[15] = d * (
m[0] * (
m[5] *
m[10] -
m[6] *
m[9]) +
1445 m[1] * (
m[6] *
m[8] -
m[4] *
m[10]) +
1446 m[2] * (
m[4] *
m[9] -
m[5] *
m[8]));
1448 #if defined ( USE_MATRIX_TEST ) 1449 out.definitelyIdentityMatrix = definitelyIdentityMatrix;
1475 out.M[12] = (T)-(M[12]*M[0] + M[13]*M[1] + M[14]*M[2]);
1476 out.M[13] = (T)-(M[12]*M[4] + M[13]*M[5] + M[14]*M[6]);
1477 out.M[14] = (T)-(M[12]*M[8] + M[13]*M[9] + M[14]*M[10]);
1480 #if defined ( USE_MATRIX_TEST ) 1481 out.definitelyIdentityMatrix = definitelyIdentityMatrix;
1491 #if defined ( USE_MATRIX_TEST ) 1492 if (definitelyIdentityMatrix)
1497 if (getInverse(temp))
1512 memcpy(M, other.M, 16*
sizeof(T));
1513 #if defined ( USE_MATRIX_TEST ) 1514 definitelyIdentityMatrix=other.definitelyIdentityMatrix;
1523 for (
s32 i = 0; i < 16; ++i)
1526 #if defined ( USE_MATRIX_TEST ) 1527 definitelyIdentityMatrix=
false;
1536 #if defined ( USE_MATRIX_TEST ) 1537 if (definitelyIdentityMatrix && other.definitelyIdentityMatrix)
1540 for (
s32 i = 0; i < 16; ++i)
1541 if (M[i] != other.M[i])
1551 return !(*
this == other);
1562 const T
w = static_cast<T>(
h / aspectRatio);
1585 if ( zClipFromZero )
1596 #if defined ( USE_MATRIX_TEST ) 1597 definitelyIdentityMatrix=
false;
1610 const T
w = static_cast<T>(
h / aspectRatio);
1633 if ( zClipFromZero )
1644 #if defined ( USE_MATRIX_TEST ) 1645 definitelyIdentityMatrix=
false;
1658 const T
w = static_cast<T>(
h / aspectRatio);
1672 M[10] = (T)(1.
f-epsilon);
1677 M[14] = (T)(
zNear*(epsilon-1.
f));
1680 #if defined ( USE_MATRIX_TEST ) 1681 definitelyIdentityMatrix=
false;
1695 M[0] = (T)(2/widthOfViewVolume);
1701 M[5] = (T)(2/heightOfViewVolume);
1715 if ( zClipFromZero )
1726 #if defined ( USE_MATRIX_TEST ) 1727 definitelyIdentityMatrix=
false;
1741 M[0] = (T)(2/widthOfViewVolume);
1747 M[5] = (T)(2/heightOfViewVolume);
1761 if ( zClipFromZero )
1772 #if defined ( USE_MATRIX_TEST ) 1773 definitelyIdentityMatrix=
false;
1787 M[0] = (T)(2*
zNear/widthOfViewVolume);
1793 M[5] = (T)(2*
zNear/heightOfViewVolume);
1807 if ( zClipFromZero )
1818 #if defined ( USE_MATRIX_TEST ) 1819 definitelyIdentityMatrix=
false;
1833 M[0] = (T)(2*
zNear/widthOfViewVolume);
1839 M[5] = (T)(2*
zNear/heightOfViewVolume);
1853 if ( zClipFromZero )
1864 #if defined ( USE_MATRIX_TEST ) 1865 definitelyIdentityMatrix=
false;
1878 M[ 0] = (T)(-plane.
Normal.
X * light.
X + d);
1879 M[ 1] = (T)(-plane.
Normal.
X * light.
Y);
1880 M[ 2] = (T)(-plane.
Normal.
X * light.
Z);
1881 M[ 3] = (T)(-plane.
Normal.
X * point);
1883 M[ 4] = (T)(-plane.
Normal.
Y * light.
X);
1884 M[ 5] = (T)(-plane.
Normal.
Y * light.
Y + d);
1885 M[ 6] = (T)(-plane.
Normal.
Y * light.
Z);
1886 M[ 7] = (T)(-plane.
Normal.
Y * point);
1888 M[ 8] = (T)(-plane.
Normal.
Z * light.
X);
1889 M[ 9] = (T)(-plane.
Normal.
Z * light.
Y);
1890 M[10] = (T)(-plane.
Normal.
Z * light.
Z + d);
1891 M[11] = (T)(-plane.
Normal.
Z * point);
1893 M[12] = (T)(-plane.
D * light.
X);
1894 M[13] = (T)(-plane.
D * light.
Y);
1895 M[14] = (T)(-plane.
D * light.
Z);
1896 M[15] = (T)(-plane.
D * point + d);
1897 #if defined ( USE_MATRIX_TEST ) 1898 definitelyIdentityMatrix=
false;
1937 #if defined ( USE_MATRIX_TEST ) 1938 definitelyIdentityMatrix=
false;
1978 #if defined ( USE_MATRIX_TEST ) 1979 definitelyIdentityMatrix=
false;
1991 for (
u32 i=0; i < 16; i += 4)
1993 mat.M[i+0] = (T)(M[i+0] + (
b.M[i+0] - M[i+0] ) * time);
1994 mat.M[i+1] = (T)(M[i+1] + (
b.M[i+1] - M[i+1] ) * time);
1995 mat.M[i+2] = (T)(M[i+2] + (
b.M[i+2] - M[i+2] ) * time);
1996 mat.M[i+3] = (T)(M[i+3] + (
b.M[i+3] - M[i+3] ) * time);
2007 getTransposed (
t );
2035 #if defined ( USE_MATRIX_TEST ) 2036 o.definitelyIdentityMatrix=definitelyIdentityMatrix;
2045 const f32 scaleX = (viewport.
getWidth() - 0.75f ) * 0.5
f;
2080 T ca =
f.dotProduct(
t);
2084 M[0] = vt.
X *
v.X + ca;
2085 M[5] = vt.
Y *
v.Y + ca;
2086 M[10] = vt.
Z *
v.Z + ca;
2145 M[0] = static_cast<T>(vt.
X * up.
X + ca);
2146 M[5] = static_cast<T>(vt.
Y * up.
Y + ca);
2147 M[10] = static_cast<T>(vt.
Z * up.
Z + ca);
2153 M[1] = static_cast<T>(vt.
X - vs.
Z);
2154 M[2] = static_cast<T>(vt.
Z + vs.
Y);
2157 M[4] = static_cast<T>(vt.
X + vs.
Z);
2158 M[6] = static_cast<T>(vt.
Y - vs.
X);
2161 M[8] = static_cast<T>(vt.
Z - vs.
Y);
2162 M[9] = static_cast<T>(vt.
Y + vs.
X);
2165 setRotationCenter(center, translation);
2173 M[12] = -M[0]*center.
X - M[4]*center.
Y - M[8]*center.
Z + (center.
X - translation.
X );
2174 M[13] = -M[1]*center.
X - M[5]*center.
Y - M[9]*center.
Z + (center.
Y - translation.
Y );
2175 M[14] = -M[2]*center.
X - M[6]*center.
Y - M[10]*center.
Z + (center.
Z - translation.
Z );
2177 #if defined ( USE_MATRIX_TEST ) 2178 definitelyIdentityMatrix=
false;
2200 const f32 c = cosf(rotateRad);
2201 const f32 s = sinf(rotateRad);
2208 M[4] = (T)(-
s *
scale.X);
2213 M[8] = (T)(
c *
scale.X * rotatecenter.
X + -
s * rotatecenter.
Y + translate.
X);
2214 M[9] = (T)(
s *
scale.Y * rotatecenter.
X +
c * rotatecenter.
Y + translate.
Y);
2222 #if defined ( USE_MATRIX_TEST ) 2223 definitelyIdentityMatrix=
false;
2233 const f32 c = cosf(rotateRad);
2234 const f32 s = sinf(rotateRad);
2241 M[8] = (T)(0.5
f * (
s -
c) + 0.5f);
2242 M[9] = (T)(-0.5
f * (
s +
c) + 0.5f);
2244 #if defined ( USE_MATRIX_TEST ) 2245 definitelyIdentityMatrix = definitelyIdentityMatrix && (rotateRad==0.0f);
2257 #if defined ( USE_MATRIX_TEST ) 2258 definitelyIdentityMatrix = definitelyIdentityMatrix && (
x==0.0f) && (
y==0.0
f);
2276 #if defined ( USE_MATRIX_TEST ) 2277 definitelyIdentityMatrix = definitelyIdentityMatrix && (
x==0.0f) && (
y==0.0
f);
2287 #if defined ( USE_MATRIX_TEST ) 2288 definitelyIdentityMatrix = definitelyIdentityMatrix && (sx==1.0f) && (sy==1.0
f);
2305 M[8] = (T)(0.5
f - 0.5
f * sx);
2306 M[9] = (T)(0.5
f - 0.5
f * sy);
2308 #if defined ( USE_MATRIX_TEST ) 2309 definitelyIdentityMatrix = definitelyIdentityMatrix && (sx==1.0f) && (sy==1.0
f);
2319 memcpy(M,
data, 16*
sizeof(T));
2321 #if defined ( USE_MATRIX_TEST ) 2322 definitelyIdentityMatrix=
false;
2332 #if defined ( USE_MATRIX_TEST ) 2333 definitelyIdentityMatrix = isDefinitelyIdentityMatrix;
2335 (
void)isDefinitelyIdentityMatrix;
2344 #if defined ( USE_MATRIX_TEST ) 2345 return definitelyIdentityMatrix;
2356 #if defined ( USE_MATRIX_TEST ) 2357 if (definitelyIdentityMatrix && other.definitelyIdentityMatrix)
2360 for (
s32 i = 0; i < 16; ++i)
CMatrix4< T > & buildProjectionMatrixPerspectiveRH(f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero=true)
Builds a right-handed perspective projection matrix.
bool equals(const core::CMatrix4< T > &other, const T tolerance=(T) ROUNDING_ERROR_f64) const
Compare two matrices using the equal method.
GLenum GLenum GLenum GLenum GLenum scale
const f64 RADTODEG64
64bit constant for converting from radians to degrees
vector3d< T > crossProduct(const vector3d< T > &p) const
Calculates the cross product with another vector.
CMatrix4< T > & buildCameraLookAtMatrixLH(const vector3df &position, const vector3df &target, const vector3df &upVector)
Builds a left-handed look-at matrix.
vector3d< T > MaxEdge
The far edge.
T Y
Y coordinate of the vector.
bool iszero(const f64 a, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals zero, taking rounding errors into account
vector3d< T > getMemberPoint() const
Gets a member point of the plane.
#define _IRR_DEPRECATED_
Defines a deprecated macro which generates a warning at compile time.
IRRLICHT_API const matrix4 IdentityMatrix
global const identity matrix
void setDefinitelyIdentityMatrix(bool isDefinitelyIdentityMatrix)
Sets if the matrix is definitely identity matrix.
void multiplyWith1x4Matrix(T *matrix) const
Multiplies this matrix by a 1x4 matrix.
CMatrix4< T > & setTextureTranslateTransposed(f32 x, f32 y)
Set texture transformation translation, using a transposed representation.
CMatrix4< T > getTransposed() const
Gets transposed matrix.
float f32
32 bit floating point variable.
CMatrix4< T > & setTextureTranslate(f32 x, f32 y)
Set texture transformation translation.
CMatrix4< T > & setScale(const T scale)
Set Scale.
void transformPlane(core::plane3d< f32 > &plane) const
Transforms a plane by this matrix.
vector3d< T > Normal
Normal vector of the plane.
core::vector3d< T > getScale() const
Get Scale.
GLfloat GLfloat GLfloat GLfloat h
position2d< T > UpperLeftCorner
Upper left corner.
const T & operator[](u32 index) const
Simple operator for linearly accessing every element of the matrix.
CMatrix4< T > & buildProjectionMatrixPerspectiveFovRH(f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero=true)
Builds a right-handed perspective projection matrix based on a field of view.
CMatrix4< T > & operator+=(const CMatrix4< T > &other)
Add another matrix.
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
bool isIdentity() const
Returns true if the matrix is the identity matrix.
T Y
Y coordinate of vector.
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...
#define IRRLICHT_API
Set FPU settings.
T X
X coordinate of the vector.
CMatrix4< T > & setRotationAxisRadians(const T &angle, const vector3d< T > &axis)
Make a rotation matrix from angle and axis, assuming left handed rotation.
CMatrix4< T > & buildProjectionMatrixOrthoLH(f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero=true)
Builds a left-handed orthogonal projection matrix.
GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar
CMatrix4< T > & setInverseRotationRadians(const vector3d< T > &rotation)
Make an inverted rotation matrix from Euler angles.
Everything in the Irrlicht Engine can be found in this namespace.
3d vector template class with lots of operators and methods.
CMatrix4(const T &r0c0, const T &r0c1, const T &r0c2, const T &r0c3, const T &r1c0, const T &r1c1, const T &r1c2, const T &r1c3, const T &r2c0, const T &r2c1, const T &r2c2, const T &r2c3, const T &r3c0, const T &r3c1, const T &r3c2, const T &r3c3)
Constructor with value initialization.
CMatrix4< T > & setTextureRotationCenter(f32 radAngle)
Set texture transformation rotation.
CMatrix4< T > & buildNDCToDCMatrix(const core::rect< s32 > &area, f32 zScale)
Builds a matrix which transforms a normalized Device Coordinate to Device Coordinates.
double f64
64 bit floating point variable.
void rotateVect(vector3df &vect) const
Rotate a vector by the rotation part of this matrix.
bool operator!=(const CMatrix4< T > &other) const
Returns true if other matrix is not equal to this matrix.
position2d< T > LowerRightCorner
Lower right corner.
CMatrix4< T > & buildTextureTransform(f32 rotateRad, const core::vector2df &rotatecenter, const core::vector2df &translate, const core::vector2df &scale)
Set to a texture transformation matrix with the given parameters.
CMatrix4< T > operator *(const T scalar, const CMatrix4< T > &mat)
void transformBox(core::aabbox3d< f32 > &box) const
Transforms a axis aligned bounding box.
CMatrix4< T > & setbyproduct_nocheck(const CMatrix4< T > &other_a, const CMatrix4< T > &other_b)
Set this matrix to the product of two matrices.
void inverseTranslateVect(vector3df &vect) const
Translate a vector by the inverse of the translation part of this matrix.
CMatrix4< T > & setInverseRotationDegrees(const vector3d< T > &rotation)
Make an inverted rotation matrix from Euler angles.
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
CMatrix4< T > & setScale(const vector3d< T > &scale)
Set Scale.
CMatrix4< T > & setbyproduct(const CMatrix4< T > &other_a, const CMatrix4< T > &other_b)
set this matrix to the product of two matrices
vector3d< T > getTranslation() const
Gets the current translation.
void getTextureTranslate(f32 &x, f32 &y) const
Get texture transformation translation.
const f64 ROUNDING_ERROR_f64
signed int s32
32 bit signed variable.
CMatrix4< T > & buildCameraLookAtMatrixRH(const vector3df &position, const vector3df &target, const vector3df &upVector)
Builds a right-handed look-at matrix.
REALINLINE f32 reciprocal(const f32 f)
void setPlane(const vector3d< T > &point, const vector3d< T > &nvector)
CMatrix4< T > & setTextureScale(f32 sx, f32 sy)
Set texture transformation scale.
CMatrix4< T > & buildRotateFromTo(const core::vector3df &from, const core::vector3df &to)
Builds a matrix that rotates from one vector to another.
CMatrix4< T > & setRotationDegrees(const vector3d< T > &rotation)
Make a rotation matrix from Euler angles. The 4th row and column are unmodified.
bool getDefinitelyIdentityMatrix() const
Gets if the matrix is definitely identity matrix.
unsigned int u32
32 bit unsigned variable.
T getHeight() const
Get height of rectangle.
CMatrix4< T > operator *(const CMatrix4< T > &other) const
Multiply by another matrix.
bool isOrthogonal() const
Returns true if the matrix is orthogonal.
CMatrix4< T > & buildShadowMatrix(const core::vector3df &light, core::plane3df plane, f32 point=1.0f)
Builds a matrix that flattens geometry into a plane.
CMatrix4(eConstructor constructor=EM4CONST_IDENTITY)
Default constructor.
void transformVect(vector3df &vect) const
Transforms the vector by this matrix.
GLdouble GLdouble GLdouble GLdouble GLdouble zNear
#define _IRR_DEBUG_BREAK_IF(_CONDITION_)
define a break macro for debugging.
CMatrix4< T > & operator=(const CMatrix4< T > &other)
Sets this matrix equal to the other matrix.
CMatrix4< T > & setInverseTranslation(const vector3d< T > &translation)
Set the inverse translation of the current matrix. Will erase any previous values.
T getWidth() const
Get width of rectangle.
GLint GLint GLint GLint GLint GLint y
const f32 DEGTORAD
32bit Constant for converting from degrees to radians
GLenum GLuint GLenum GLsizei const GLchar * buf
const T * pointer() const
Returns pointer to internal array.
void inverseRotateVect(vector3df &vect) const
Rotate a vector by the inverse of the rotation part of this matrix.
CMatrix4< T > & buildProjectionMatrixPerspectiveFovLH(f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero=true)
Builds a left-handed perspective projection matrix based on a field of view.
vector3d< T > & normalize()
Normalizes the vector.
const T & operator()(const s32 row, const s32 col) const
Simple operator for directly accessing every element of the matrix.
CMatrix4< T > & operator *=(const CMatrix4< T > &other)
Multiply by another matrix.
vector3d< T > MinEdge
The near edge.
CMatrix4< T > & buildProjectionMatrixOrthoRH(f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero=true)
Builds a right-handed orthogonal projection matrix.
4x4 matrix. Mostly used as transformation matrix for 3d calculations.
T dotProduct(const vector3d< T > &other) const
Get the dot product with another vector.
void transformVec4(T *out, const T *in) const
An alternate transform vector method, reading from and writing to an array of 4 floats.
CMatrix4< T > & setTranslation(const vector3d< T > &translation)
Set the translation of the current matrix. Will erase any previous values.
void transformVec3(T *out, const T *in) const
An alternate transform vector method, reading from and writing to an array of 3 floats.
GLboolean GLboolean GLboolean b
bool makeInverse()
Calculates inverse of matrix. Slow.
CMatrix4< T > & setTextureScaleCenter(f32 sx, f32 sy)
Set texture transformation scale, and recenter at (0.5,0.5)
GLint GLint GLint GLint GLint x
CMatrix4< T > & buildProjectionMatrixPerspectiveFovInfinityLH(f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 epsilon=0)
Builds a left-handed perspective projection matrix based on a field of view, with far plane at infini...
void buildAxisAlignedBillboard(const core::vector3df &camPos, const core::vector3df ¢er, const core::vector3df &translation, const core::vector3df &axis, const core::vector3df &from)
Builds a matrix which rotates a source vector to a look vector over an arbitrary axis.
T & operator[](u32 index)
Simple operator for linearly accessing every element of the matrix.
T Z
Z coordinate of the vector.
void translateVect(vector3df &vect) const
Translate a vector by the translation part of this matrix.
CMatrix4< T > operator+(const CMatrix4< T > &other) const
Add another matrix.
CMatrix4< T > operator-(const CMatrix4< T > &other) const
Subtract another matrix.
bool isIdentity_integer_base() const
Returns true if the matrix is the identity matrix.
GLboolean GLboolean GLboolean GLboolean a
bool getInverse(CMatrix4< T > &out) const
Gets the inverse matrix of this one.
GLubyte GLubyte GLubyte GLubyte w
CMatrix4< f32 > matrix4
Typedef for f32 matrix.
eConstructor
Constructor Flags.
void repair()
Repairs the box.
void getTextureScale(f32 &sx, f32 &sy) const
Get texture transformation scale.
CMatrix4< T > & setRotationRadians(const vector3d< T > &rotation)
Make a rotation matrix from Euler angles. The 4th row and column are unmodified.
CMatrix4< T > & setM(const T *data)
Sets all matrix data members at once.
CMatrix4< T > interpolate(const core::CMatrix4< T > &b, f32 time) const
Creates a new matrix as interpolated matrix from two other ones.
CMatrix4< T > & buildProjectionMatrixPerspectiveLH(f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero=true)
Builds a left-handed perspective projection matrix.
core::vector3d< T > getRotationDegrees() const
Returns the rotation, as set by setRotation().
CMatrix4< T > & makeIdentity()
Set matrix to identity.
T & operator()(const s32 row, const s32 col)
Simple operator for directly accessing every element of the matrix.
bool operator==(const CMatrix4< T > &other) const
Returns true if other matrix is equal to this matrix.
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
CMatrix4< T > & operator-=(const CMatrix4< T > &other)
Subtract another matrix.
void transformBoxEx(core::aabbox3d< f32 > &box) const
Transforms a axis aligned bounding box.
T X
X coordinate of vector.
bool getInversePrimitive(CMatrix4< T > &out) const
Inverts a primitive matrix which only contains a translation and a rotation.