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;
57 EM4CONST_INVERSE_TRANSPOSED
71 #if defined ( USE_MATRIX_TEST ) 72 definitelyIdentityMatrix=
false;
74 return M[ row * 4 + col ];
83 #if defined ( USE_MATRIX_TEST ) 84 definitelyIdentityMatrix=
false;
102 #if defined ( USE_MATRIX_TEST ) 103 definitelyIdentityMatrix=
false;
153 inline bool isIdentity()
const;
156 inline bool isOrthogonal()
const;
159 bool isIdentity_integer_base ()
const;
202 void inverseTranslateVect(
vector3df& vect )
const;
205 void inverseRotateVect(
vector3df& vect )
const;
208 void rotateVect(
vector3df& vect )
const;
217 void transformVect(
vector3df& vect)
const;
226 void transformVec3(T *out,
const T * in)
const;
229 void translateVect(
vector3df& vect )
const;
248 void multiplyWith1x4Matrix(T* matrix)
const;
257 bool getInversePrimitive (
CMatrix4<T>& out )
const;
265 CMatrix4<T>& buildProjectionMatrixPerspectiveFovRH(
f32 fieldOfViewRadians,
f32 aspectRatio,
f32 zNear,
f32 zFar);
268 CMatrix4<T>& buildProjectionMatrixPerspectiveFovLH(
f32 fieldOfViewRadians,
f32 aspectRatio,
f32 zNear,
f32 zFar);
271 CMatrix4<T>& buildProjectionMatrixPerspectiveFovInfinityLH(
f32 fieldOfViewRadians,
f32 aspectRatio,
f32 zNear,
f32 epsilon=0);
274 CMatrix4<T>& buildProjectionMatrixPerspectiveRH(
f32 widthOfViewVolume,
f32 heightOfViewVolume,
f32 zNear,
f32 zFar);
277 CMatrix4<T>& buildProjectionMatrixPerspectiveLH(
f32 widthOfViewVolume,
f32 heightOfViewVolume,
f32 zNear,
f32 zFar);
317 inline void getTransposed(
CMatrix4<T>& dest )
const;
393 void setDefinitelyIdentityMatrix(
bool isDefinitelyIdentityMatrix);
396 bool getDefinitelyIdentityMatrix()
const;
404 #if defined ( USE_MATRIX_TEST ) 405 mutable u32 definitelyIdentityMatrix;
408 #if defined ( USE_MATRIX_TEST_DEBUG ) 418 #if defined ( USE_MATRIX_TEST ) 419 : definitelyIdentityMatrix(BIT_UNTESTED)
421 #if defined ( USE_MATRIX_TEST_DEBUG ) 422 ,id ( MTest.ID++), calls ( 0 )
425 switch ( constructor )
427 case EM4CONST_NOTHING:
430 case EM4CONST_IDENTITY:
431 case EM4CONST_INVERSE:
441 #if defined ( USE_MATRIX_TEST ) 442 : definitelyIdentityMatrix(BIT_UNTESTED)
444 #if defined ( USE_MATRIX_TEST_DEBUG ) 445 ,id ( MTest.ID++), calls ( 0 )
448 switch ( constructor )
450 case EM4CONST_IDENTITY:
453 case EM4CONST_NOTHING:
458 case EM4CONST_TRANSPOSED:
461 case EM4CONST_INVERSE:
463 memset(M, 0, 16*
sizeof(T));
465 case EM4CONST_INVERSE_TRANSPOSED:
467 memset(M, 0, 16*
sizeof(T));
469 *
this=getTransposed();
480 temp[0] = M[0]+other[0];
481 temp[1] = M[1]+other[1];
482 temp[2] = M[2]+other[2];
483 temp[3] = M[3]+other[3];
484 temp[4] = M[4]+other[4];
485 temp[5] = M[5]+other[5];
486 temp[6] = M[6]+other[6];
487 temp[7] = M[7]+other[7];
488 temp[8] = M[8]+other[8];
489 temp[9] = M[9]+other[9];
490 temp[10] = M[10]+other[10];
491 temp[11] = M[11]+other[11];
492 temp[12] = M[12]+other[12];
493 temp[13] = M[13]+other[13];
494 temp[14] = M[14]+other[14];
495 temp[15] = M[15]+other[15];
530 temp[0] = M[0]-other[0];
531 temp[1] = M[1]-other[1];
532 temp[2] = M[2]-other[2];
533 temp[3] = M[3]-other[3];
534 temp[4] = M[4]-other[4];
535 temp[5] = M[5]-other[5];
536 temp[6] = M[6]-other[6];
537 temp[7] = M[7]-other[7];
538 temp[8] = M[8]-other[8];
539 temp[9] = M[9]-other[9];
540 temp[10] = M[10]-other[10];
541 temp[11] = M[11]-other[11];
542 temp[12] = M[12]-other[12];
543 temp[13] = M[13]-other[13];
544 temp[14] = M[14]-other[14];
545 temp[15] = M[15]-other[15];
580 temp[0] = M[0]*scalar;
581 temp[1] = M[1]*scalar;
582 temp[2] = M[2]*scalar;
583 temp[3] = M[3]*scalar;
584 temp[4] = M[4]*scalar;
585 temp[5] = M[5]*scalar;
586 temp[6] = M[6]*scalar;
587 temp[7] = M[7]*scalar;
588 temp[8] = M[8]*scalar;
589 temp[9] = M[9]*scalar;
590 temp[10] = M[10]*scalar;
591 temp[11] = M[11]*scalar;
592 temp[12] = M[12]*scalar;
593 temp[13] = M[13]*scalar;
594 temp[14] = M[14]*scalar;
595 temp[15] = M[15]*scalar;
628 #if defined ( USE_MATRIX_TEST ) 632 if ( this->isIdentity() )
634 return (*
this = other);
639 return setbyproduct_nocheck( temp, other );
645 return setbyproduct_nocheck( temp, other );
655 const T *m1 = other_a.M;
656 const T *m2 = other_b.M;
658 M[0] = m1[0]*m2[0] + m1[4]*m2[1] + m1[8]*m2[2] + m1[12]*m2[3];
659 M[1] = m1[1]*m2[0] + m1[5]*m2[1] + m1[9]*m2[2] + m1[13]*m2[3];
660 M[2] = m1[2]*m2[0] + m1[6]*m2[1] + m1[10]*m2[2] + m1[14]*m2[3];
661 M[3] = m1[3]*m2[0] + m1[7]*m2[1] + m1[11]*m2[2] + m1[15]*m2[3];
663 M[4] = m1[0]*m2[4] + m1[4]*m2[5] + m1[8]*m2[6] + m1[12]*m2[7];
664 M[5] = m1[1]*m2[4] + m1[5]*m2[5] + m1[9]*m2[6] + m1[13]*m2[7];
665 M[6] = m1[2]*m2[4] + m1[6]*m2[5] + m1[10]*m2[6] + m1[14]*m2[7];
666 M[7] = m1[3]*m2[4] + m1[7]*m2[5] + m1[11]*m2[6] + m1[15]*m2[7];
668 M[8] = m1[0]*m2[8] + m1[4]*m2[9] + m1[8]*m2[10] + m1[12]*m2[11];
669 M[9] = m1[1]*m2[8] + m1[5]*m2[9] + m1[9]*m2[10] + m1[13]*m2[11];
670 M[10] = m1[2]*m2[8] + m1[6]*m2[9] + m1[10]*m2[10] + m1[14]*m2[11];
671 M[11] = m1[3]*m2[8] + m1[7]*m2[9] + m1[11]*m2[10] + m1[15]*m2[11];
673 M[12] = m1[0]*m2[12] + m1[4]*m2[13] + m1[8]*m2[14] + m1[12]*m2[15];
674 M[13] = m1[1]*m2[12] + m1[5]*m2[13] + m1[9]*m2[14] + m1[13]*m2[15];
675 M[14] = m1[2]*m2[12] + m1[6]*m2[13] + m1[10]*m2[14] + m1[14]*m2[15];
676 M[15] = m1[3]*m2[12] + m1[7]*m2[13] + m1[11]*m2[14] + m1[15]*m2[15];
677 #if defined ( USE_MATRIX_TEST ) 678 definitelyIdentityMatrix=
false;
690 #if defined ( USE_MATRIX_TEST ) 692 return (*
this = other_b);
695 return (*
this = other_a);
697 return setbyproduct_nocheck(other_a,other_b);
699 return setbyproduct_nocheck(other_a,other_b);
707 #if defined ( USE_MATRIX_TEST ) 709 if ( this->isIdentity() )
719 m3[0] = m1[0]*m2[0] + m1[4]*m2[1] + m1[8]*m2[2] + m1[12]*m2[3];
720 m3[1] = m1[1]*m2[0] + m1[5]*m2[1] + m1[9]*m2[2] + m1[13]*m2[3];
721 m3[2] = m1[2]*m2[0] + m1[6]*m2[1] + m1[10]*m2[2] + m1[14]*m2[3];
722 m3[3] = m1[3]*m2[0] + m1[7]*m2[1] + m1[11]*m2[2] + m1[15]*m2[3];
724 m3[4] = m1[0]*m2[4] + m1[4]*m2[5] + m1[8]*m2[6] + m1[12]*m2[7];
725 m3[5] = m1[1]*m2[4] + m1[5]*m2[5] + m1[9]*m2[6] + m1[13]*m2[7];
726 m3[6] = m1[2]*m2[4] + m1[6]*m2[5] + m1[10]*m2[6] + m1[14]*m2[7];
727 m3[7] = m1[3]*m2[4] + m1[7]*m2[5] + m1[11]*m2[6] + m1[15]*m2[7];
729 m3[8] = m1[0]*m2[8] + m1[4]*m2[9] + m1[8]*m2[10] + m1[12]*m2[11];
730 m3[9] = m1[1]*m2[8] + m1[5]*m2[9] + m1[9]*m2[10] + m1[13]*m2[11];
731 m3[10] = m1[2]*m2[8] + m1[6]*m2[9] + m1[10]*m2[10] + m1[14]*m2[11];
732 m3[11] = m1[3]*m2[8] + m1[7]*m2[9] + m1[11]*m2[10] + m1[15]*m2[11];
734 m3[12] = m1[0]*m2[12] + m1[4]*m2[13] + m1[8]*m2[14] + m1[12]*m2[15];
735 m3[13] = m1[1]*m2[12] + m1[5]*m2[13] + m1[9]*m2[14] + m1[13]*m2[15];
736 m3[14] = m1[2]*m2[12] + m1[6]*m2[13] + m1[10]*m2[14] + m1[14]*m2[15];
737 m3[15] = m1[3]*m2[12] + m1[7]*m2[13] + m1[11]*m2[14] + m1[15]*m2[15];
753 M[12] = translation.
X;
754 M[13] = translation.
Y;
755 M[14] = translation.
Z;
756 #if defined ( USE_MATRIX_TEST ) 757 definitelyIdentityMatrix=
false;
765 M[12] = -translation.
X;
766 M[13] = -translation.
Y;
767 M[14] = -translation.
Z;
768 #if defined ( USE_MATRIX_TEST ) 769 definitelyIdentityMatrix=
false;
780 #if defined ( USE_MATRIX_TEST ) 781 definitelyIdentityMatrix=
false;
807 return vector3d<T>(sqrtf(M[0] * M[0] + M[1] * M[1] + M[2] * M[2]),
808 sqrtf(M[4] * M[4] + M[5] * M[5] + M[6] * M[6]),
809 sqrtf(M[8] * M[8] + M[9] * M[9] + M[10] * M[10]));
827 const f64 cr = cos( rotation.
X );
828 const f64 sr = sin( rotation.
X );
829 const f64 cp = cos( rotation.
Y );
830 const f64 sp = sin( rotation.
Y );
831 const f64 cy = cos( rotation.
Z );
832 const f64 sy = sin( rotation.
Z );
838 const f64 srsp = sr*sp;
839 const f64 crsp = cr*sp;
841 M[4] = (T)( srsp*cy-cr*sy );
842 M[5] = (T)( srsp*sy+cr*cy );
845 M[8] = (T)( crsp*cy+sr*sy );
846 M[9] = (T)( crsp*sy-sr*cy );
847 M[10] = (T)( cr*cp );
848 #if defined ( USE_MATRIX_TEST ) 849 definitelyIdentityMatrix=
false;
865 if (scale.
Y<0 && scale.
Z<0)
870 else if (scale.
X<0 && scale.
Z<0)
875 else if (scale.
X<0 && scale.
Y<0)
883 const f64 C = cos(Y);
886 f64 rotx, roty, X, Z;
891 rotx = mat[10] * invC * invScale.
Z;
892 roty = mat[6] * invC * invScale.
Y;
894 rotx = mat[0] * invC * invScale.
X;
895 roty = mat[1] * invC * invScale.
X;
901 rotx = mat[5] * invScale.
Y;
902 roty = -mat[4] * invScale.
Y;
907 if (X < 0.0) X += 360.0;
908 if (Y < 0.0) Y += 360.0;
909 if (Z < 0.0) Z += 360.0;
919 f64 cr = cos( rotation.
X );
920 f64 sr = sin( rotation.
X );
921 f64 cp = cos( rotation.
Y );
922 f64 sp = sin( rotation.
Y );
923 f64 cy = cos( rotation.
Z );
924 f64 sy = sin( rotation.
Z );
933 M[1] = (T)( srsp*cy-cr*sy );
934 M[5] = (T)( srsp*sy+cr*cy );
937 M[2] = (T)( crsp*cy+sr*sy );
938 M[6] = (T)( crsp*sy-sr*cy );
939 M[10] = (T)( cr*cp );
940 #if defined ( USE_MATRIX_TEST ) 941 definitelyIdentityMatrix=
false;
950 const f64 c = cos(angle);
951 const f64 s = sin(angle);
952 const f64 t = 1.0 - c;
954 const f64 tx = t * axis.
X;
955 const f64 ty = t * axis.
Y;
956 const f64 tz = t * axis.
Z;
958 const f64 sx = s * axis.
X;
959 const f64 sy = s * axis.
Y;
960 const f64 sz = s * axis.
Z;
962 M[0] = (T)(tx * axis.
X + c);
963 M[1] = (T)(tx * axis.
Y + sz);
964 M[2] = (T)(tx * axis.
Z - sy);
966 M[4] = (T)(ty * axis.
X - sz);
967 M[5] = (T)(ty * axis.
Y + c);
968 M[6] = (T)(ty * axis.
Z + sx);
970 M[8] = (T)(tz * axis.
X + sy);
971 M[9] = (T)(tz * axis.
Y - sx);
972 M[10] = (T)(tz * axis.
Z + c);
974 #if defined ( USE_MATRIX_TEST ) 975 definitelyIdentityMatrix=
false;
986 memset(M, 0, 16*
sizeof(T));
987 M[0] = M[5] = M[10] = M[15] = (T)1;
988 #if defined ( USE_MATRIX_TEST ) 989 definitelyIdentityMatrix=
true;
1002 #if defined ( USE_MATRIX_TEST ) 1003 if (definitelyIdentityMatrix)
1029 #if defined ( USE_MATRIX_TEST ) 1030 definitelyIdentityMatrix=
true;
1040 T dp=M[0] * M[4 ] + M[1] * M[5 ] + M[2 ] * M[6 ] + M[3 ] * M[7 ];
1043 dp = M[0] * M[8 ] + M[1] * M[9 ] + M[2 ] * M[10] + M[3 ] * M[11];
1046 dp = M[0] * M[12] + M[1] * M[13] + M[2 ] * M[14] + M[3 ] * M[15];
1049 dp = M[4] * M[8 ] + M[5] * M[9 ] + M[6 ] * M[10] + M[7 ] * M[11];
1052 dp = M[4] * M[12] + M[5] * M[13] + M[6 ] * M[14] + M[7 ] * M[15];
1055 dp = M[8] * M[12] + M[9] * M[13] + M[10] * M[14] + M[11] * M[15];
1069 #if defined ( USE_MATRIX_TEST ) 1070 if (definitelyIdentityMatrix)
1074 if(
IR(M[1])!=0)
return false;
1075 if(
IR(M[2])!=0)
return false;
1076 if(
IR(M[3])!=0)
return false;
1078 if(
IR(M[4])!=0)
return false;
1080 if(
IR(M[6])!=0)
return false;
1081 if(
IR(M[7])!=0)
return false;
1083 if(
IR(M[8])!=0)
return false;
1084 if(
IR(M[9])!=0)
return false;
1086 if(
IR(M[11])!=0)
return false;
1088 if(
IR(M[12])!=0)
return false;
1089 if(
IR(M[13])!=0)
return false;
1090 if(
IR(M[13])!=0)
return false;
1093 #if defined ( USE_MATRIX_TEST ) 1094 definitelyIdentityMatrix=
true;
1104 vect.
X = tmp.
X*M[0] + tmp.
Y*M[4] + tmp.
Z*M[8];
1105 vect.
Y = tmp.
X*M[1] + tmp.
Y*M[5] + tmp.
Z*M[9];
1106 vect.
Z = tmp.
X*M[2] + tmp.
Y*M[6] + tmp.
Z*M[10];
1113 out.
X = in.
X*M[0] + in.
Y*M[4] + in.
Z*M[8];
1114 out.
Y = in.
X*M[1] + in.
Y*M[5] + in.
Z*M[9];
1115 out.
Z = in.
X*M[2] + in.
Y*M[6] + in.
Z*M[10];
1122 out[0] = in.
X*M[0] + in.
Y*M[4] + in.
Z*M[8];
1123 out[1] = in.
X*M[1] + in.
Y*M[5] + in.
Z*M[9];
1124 out[2] = in.
X*M[2] + in.
Y*M[6] + in.
Z*M[10];
1131 vect.
X = tmp.
X*M[0] + tmp.
Y*M[1] + tmp.
Z*M[2];
1132 vect.
Y = tmp.
X*M[4] + tmp.
Y*M[5] + tmp.
Z*M[6];
1133 vect.
Z = tmp.
X*M[8] + tmp.
Y*M[9] + tmp.
Z*M[10];
1141 vector[0] = vect.
X*M[0] + vect.
Y*M[4] + vect.
Z*M[8] + M[12];
1142 vector[1] = vect.
X*M[1] + vect.
Y*M[5] + vect.
Z*M[9] + M[13];
1143 vector[2] = vect.
X*M[2] + vect.
Y*M[6] + vect.
Z*M[10] + M[14];
1153 out.
X = in.
X*M[0] + in.
Y*M[4] + in.
Z*M[8] + M[12];
1154 out.
Y = in.
X*M[1] + in.
Y*M[5] + in.
Z*M[9] + M[13];
1155 out.
Z = in.
X*M[2] + in.
Y*M[6] + in.
Z*M[10] + M[14];
1162 out[0] = in.
X*M[0] + in.
Y*M[4] + in.
Z*M[8] + M[12];
1163 out[1] = in.
X*M[1] + in.
Y*M[5] + in.
Z*M[9] + M[13];
1164 out[2] = in.
X*M[2] + in.
Y*M[6] + in.
Z*M[10] + M[14];
1165 out[3] = in.
X*M[3] + in.
Y*M[7] + in.
Z*M[11] + M[15];
1171 out[0] = in[0]*M[0] + in[1]*M[4] + in[2]*M[8] + M[12];
1172 out[1] = in[0]*M[1] + in[1]*M[5] + in[2]*M[9] + M[13];
1173 out[2] = in[0]*M[2] + in[1]*M[6] + in[2]*M[10] + M[14];
1186 CMatrix4<T> transposedInverse(*
this, EM4CONST_INVERSE_TRANSPOSED);
1188 transposedInverse.transformVect(normal);
1198 transformPlane( out );
1207 #if defined ( USE_MATRIX_TEST ) 1221 #if defined ( USE_MATRIX_TEST ) 1232 Bmin[0] = Bmax[0] = M[12];
1233 Bmin[1] = Bmax[1] = M[13];
1234 Bmin[2] = Bmax[2] = M[14];
1238 for (
u32 i = 0; i < 3; ++i)
1240 for (
u32 j = 0; j < 3; ++j)
1242 const f32 a = m(j,i) * Amin[j];
1243 const f32 b = m(j,i) * Amax[j];
1285 matrix[0] = M[0]*mat[0] + M[4]*mat[1] + M[8]*mat[2] + M[12]*mat[3];
1286 matrix[1] = M[1]*mat[0] + M[5]*mat[1] + M[9]*mat[2] + M[13]*mat[3];
1287 matrix[2] = M[2]*mat[0] + M[6]*mat[1] + M[10]*mat[2] + M[14]*mat[3];
1288 matrix[3] = M[3]*mat[0] + M[7]*mat[1] + M[11]*mat[2] + M[15]*mat[3];
1294 vect.
X = vect.
X-M[12];
1295 vect.
Y = vect.
Y-M[13];
1296 vect.
Z = vect.
Z-M[14];
1302 vect.
X = vect.
X+M[12];
1303 vect.
Y = vect.
Y+M[13];
1304 vect.
Z = vect.
Z+M[14];
1315 #if defined ( USE_MATRIX_TEST ) 1316 if ( this->isIdentity() )
1324 f32 d = (m(0, 0) * m(1, 1) - m(0, 1) * m(1, 0)) * (m(2, 2) * m(3, 3) - m(2, 3) * m(3, 2)) -
1325 (m(0, 0) * m(1, 2) - m(0, 2) * m(1, 0)) * (m(2, 1) * m(3, 3) - m(2, 3) * m(3, 1)) +
1326 (m(0, 0) * m(1, 3) - m(0, 3) * m(1, 0)) * (m(2, 1) * m(3, 2) - m(2, 2) * m(3, 1)) +
1327 (m(0, 1) * m(1, 2) - m(0, 2) * m(1, 1)) * (m(2, 0) * m(3, 3) - m(2, 3) * m(3, 0)) -
1328 (m(0, 1) * m(1, 3) - m(0, 3) * m(1, 1)) * (m(2, 0) * m(3, 2) - m(2, 2) * m(3, 0)) +
1329 (m(0, 2) * m(1, 3) - m(0, 3) * m(1, 2)) * (m(2, 0) * m(3, 1) - m(2, 1) * m(3, 0));
1336 out(0, 0) = d * (m(1, 1) * (m(2, 2) * m(3, 3) - m(2, 3) * m(3, 2)) +
1337 m(1, 2) * (m(2, 3) * m(3, 1) - m(2, 1) * m(3, 3)) +
1338 m(1, 3) * (m(2, 1) * m(3, 2) - m(2, 2) * m(3, 1)));
1339 out(0, 1) = d * (m(2, 1) * (m(0, 2) * m(3, 3) - m(0, 3) * m(3, 2)) +
1340 m(2, 2) * (m(0, 3) * m(3, 1) - m(0, 1) * m(3, 3)) +
1341 m(2, 3) * (m(0, 1) * m(3, 2) - m(0, 2) * m(3, 1)));
1342 out(0, 2) = d * (m(3, 1) * (m(0, 2) * m(1, 3) - m(0, 3) * m(1, 2)) +
1343 m(3, 2) * (m(0, 3) * m(1, 1) - m(0, 1) * m(1, 3)) +
1344 m(3, 3) * (m(0, 1) * m(1, 2) - m(0, 2) * m(1, 1)));
1345 out(0, 3) = d * (m(0, 1) * (m(1, 3) * m(2, 2) - m(1, 2) * m(2, 3)) +
1346 m(0, 2) * (m(1, 1) * m(2, 3) - m(1, 3) * m(2, 1)) +
1347 m(0, 3) * (m(1, 2) * m(2, 1) - m(1, 1) * m(2, 2)));
1348 out(1, 0) = d * (m(1, 2) * (m(2, 0) * m(3, 3) - m(2, 3) * m(3, 0)) +
1349 m(1, 3) * (m(2, 2) * m(3, 0) - m(2, 0) * m(3, 2)) +
1350 m(1, 0) * (m(2, 3) * m(3, 2) - m(2, 2) * m(3, 3)));
1351 out(1, 1) = d * (m(2, 2) * (m(0, 0) * m(3, 3) - m(0, 3) * m(3, 0)) +
1352 m(2, 3) * (m(0, 2) * m(3, 0) - m(0, 0) * m(3, 2)) +
1353 m(2, 0) * (m(0, 3) * m(3, 2) - m(0, 2) * m(3, 3)));
1354 out(1, 2) = d * (m(3, 2) * (m(0, 0) * m(1, 3) - m(0, 3) * m(1, 0)) +
1355 m(3, 3) * (m(0, 2) * m(1, 0) - m(0, 0) * m(1, 2)) +
1356 m(3, 0) * (m(0, 3) * m(1, 2) - m(0, 2) * m(1, 3)));
1357 out(1, 3) = d * (m(0, 2) * (m(1, 3) * m(2, 0) - m(1, 0) * m(2, 3)) +
1358 m(0, 3) * (m(1, 0) * m(2, 2) - m(1, 2) * m(2, 0)) +
1359 m(0, 0) * (m(1, 2) * m(2, 3) - m(1, 3) * m(2, 2)));
1360 out(2, 0) = d * (m(1, 3) * (m(2, 0) * m(3, 1) - m(2, 1) * m(3, 0)) +
1361 m(1, 0) * (m(2, 1) * m(3, 3) - m(2, 3) * m(3, 1)) +
1362 m(1, 1) * (m(2, 3) * m(3, 0) - m(2, 0) * m(3, 3)));
1363 out(2, 1) = d * (m(2, 3) * (m(0, 0) * m(3, 1) - m(0, 1) * m(3, 0)) +
1364 m(2, 0) * (m(0, 1) * m(3, 3) - m(0, 3) * m(3, 1)) +
1365 m(2, 1) * (m(0, 3) * m(3, 0) - m(0, 0) * m(3, 3)));
1366 out(2, 2) = d * (m(3, 3) * (m(0, 0) * m(1, 1) - m(0, 1) * m(1, 0)) +
1367 m(3, 0) * (m(0, 1) * m(1, 3) - m(0, 3) * m(1, 1)) +
1368 m(3, 1) * (m(0, 3) * m(1, 0) - m(0, 0) * m(1, 3)));
1369 out(2, 3) = d * (m(0, 3) * (m(1, 1) * m(2, 0) - m(1, 0) * m(2, 1)) +
1370 m(0, 0) * (m(1, 3) * m(2, 1) - m(1, 1) * m(2, 3)) +
1371 m(0, 1) * (m(1, 0) * m(2, 3) - m(1, 3) * m(2, 0)));
1372 out(3, 0) = d * (m(1, 0) * (m(2, 2) * m(3, 1) - m(2, 1) * m(3, 2)) +
1373 m(1, 1) * (m(2, 0) * m(3, 2) - m(2, 2) * m(3, 0)) +
1374 m(1, 2) * (m(2, 1) * m(3, 0) - m(2, 0) * m(3, 1)));
1375 out(3, 1) = d * (m(2, 0) * (m(0, 2) * m(3, 1) - m(0, 1) * m(3, 2)) +
1376 m(2, 1) * (m(0, 0) * m(3, 2) - m(0, 2) * m(3, 0)) +
1377 m(2, 2) * (m(0, 1) * m(3, 0) - m(0, 0) * m(3, 1)));
1378 out(3, 2) = d * (m(3, 0) * (m(0, 2) * m(1, 1) - m(0, 1) * m(1, 2)) +
1379 m(3, 1) * (m(0, 0) * m(1, 2) - m(0, 2) * m(1, 0)) +
1380 m(3, 2) * (m(0, 1) * m(1, 0) - m(0, 0) * m(1, 1)));
1381 out(3, 3) = d * (m(0, 0) * (m(1, 1) * m(2, 2) - m(1, 2) * m(2, 1)) +
1382 m(0, 1) * (m(1, 2) * m(2, 0) - m(1, 0) * m(2, 2)) +
1383 m(0, 2) * (m(1, 0) * m(2, 1) - m(1, 1) * m(2, 0)));
1385 #if defined ( USE_MATRIX_TEST ) 1386 out.definitelyIdentityMatrix = definitelyIdentityMatrix;
1412 out.M[12] = (T)-(M[12]*M[0] + M[13]*M[1] + M[14]*M[2]);
1413 out.M[13] = (T)-(M[12]*M[4] + M[13]*M[5] + M[14]*M[6]);
1414 out.M[14] = (T)-(M[12]*M[8] + M[13]*M[9] + M[14]*M[10]);
1417 #if defined ( USE_MATRIX_TEST ) 1418 out.definitelyIdentityMatrix = definitelyIdentityMatrix;
1428 #if defined ( USE_MATRIX_TEST ) 1429 if (definitelyIdentityMatrix)
1434 if (getInverse(temp))
1449 memcpy(M, other.M, 16*
sizeof(T));
1450 #if defined ( USE_MATRIX_TEST ) 1451 definitelyIdentityMatrix=other.definitelyIdentityMatrix;
1460 for (
s32 i = 0; i < 16; ++i)
1463 #if defined ( USE_MATRIX_TEST ) 1464 definitelyIdentityMatrix=
false;
1473 #if defined ( USE_MATRIX_TEST ) 1474 if (definitelyIdentityMatrix && other.definitelyIdentityMatrix)
1477 for (
s32 i = 0; i < 16; ++i)
1478 if (M[i] != other.M[i])
1488 return !(*
this == other);
1495 f32 fieldOfViewRadians,
f32 aspectRatio,
f32 zNear,
f32 zFar)
1499 const T w =
static_cast<T
>(h / aspectRatio);
1514 M[10] = (T)(zFar/(zNear-zFar));
1520 M[14] = (T)(zNear*zFar/(zNear-zFar));
1524 #if defined ( USE_MATRIX_TEST ) 1525 definitelyIdentityMatrix=
false;
1534 f32 fieldOfViewRadians,
f32 aspectRatio,
f32 zNear,
f32 zFar)
1538 const T w =
static_cast<T
>(h / aspectRatio);
1553 M[10] = (T)(zFar/(zFar-zNear));
1558 M[14] = (T)(-zNear*zFar/(zFar-zNear));
1561 #if defined ( USE_MATRIX_TEST ) 1562 definitelyIdentityMatrix=
false;
1571 f32 fieldOfViewRadians,
f32 aspectRatio,
f32 zNear,
f32 epsilon)
1575 const T w =
static_cast<T
>(h / aspectRatio);
1589 M[10] = (T)(1.f-epsilon);
1594 M[14] = (T)(zNear*(epsilon-1.f));
1597 #if defined ( USE_MATRIX_TEST ) 1598 definitelyIdentityMatrix=
false;
1607 f32 widthOfViewVolume,
f32 heightOfViewVolume,
f32 zNear,
f32 zFar)
1612 M[0] = (T)(2/widthOfViewVolume);
1618 M[5] = (T)(2/heightOfViewVolume);
1624 M[10] = (T)(1/(zFar-zNear));
1629 M[14] = (T)(zNear/(zNear-zFar));
1632 #if defined ( USE_MATRIX_TEST ) 1633 definitelyIdentityMatrix=
false;
1642 f32 widthOfViewVolume,
f32 heightOfViewVolume,
f32 zNear,
f32 zFar)
1647 M[0] = (T)(2/widthOfViewVolume);
1653 M[5] = (T)(2/heightOfViewVolume);
1659 M[10] = (T)(1/(zNear-zFar));
1664 M[14] = (T)(zNear/(zNear-zFar));
1667 #if defined ( USE_MATRIX_TEST ) 1668 definitelyIdentityMatrix=
false;
1677 f32 widthOfViewVolume,
f32 heightOfViewVolume,
f32 zNear,
f32 zFar)
1682 M[0] = (T)(2*zNear/widthOfViewVolume);
1688 M[5] = (T)(2*zNear/heightOfViewVolume);
1694 M[10] = (T)(zFar/(zNear-zFar));
1699 M[14] = (T)(zNear*zFar/(zNear-zFar));
1702 #if defined ( USE_MATRIX_TEST ) 1703 definitelyIdentityMatrix=
false;
1712 f32 widthOfViewVolume,
f32 heightOfViewVolume,
f32 zNear,
f32 zFar)
1717 M[0] = (T)(2*zNear/widthOfViewVolume);
1723 M[5] = (T)(2*zNear/heightOfViewVolume);
1729 M[10] = (T)(zFar/(zFar-zNear));
1734 M[14] = (T)(zNear*zFar/(zNear-zFar));
1736 #if defined ( USE_MATRIX_TEST ) 1737 definitelyIdentityMatrix=
false;
1750 M[ 0] = (T)(-plane.
Normal.
X * light.
X + d);
1751 M[ 1] = (T)(-plane.
Normal.
X * light.
Y);
1752 M[ 2] = (T)(-plane.
Normal.
X * light.
Z);
1753 M[ 3] = (T)(-plane.
Normal.
X * point);
1755 M[ 4] = (T)(-plane.
Normal.
Y * light.
X);
1756 M[ 5] = (T)(-plane.
Normal.
Y * light.
Y + d);
1757 M[ 6] = (T)(-plane.
Normal.
Y * light.
Z);
1758 M[ 7] = (T)(-plane.
Normal.
Y * point);
1760 M[ 8] = (T)(-plane.
Normal.
Z * light.
X);
1761 M[ 9] = (T)(-plane.
Normal.
Z * light.
Y);
1762 M[10] = (T)(-plane.
Normal.
Z * light.
Z + d);
1763 M[11] = (T)(-plane.
Normal.
Z * point);
1765 M[12] = (T)(-plane.
D * light.
X);
1766 M[13] = (T)(-plane.
D * light.
Y);
1767 M[14] = (T)(-plane.
D * light.
Z);
1768 M[15] = (T)(-plane.
D * point + d);
1769 #if defined ( USE_MATRIX_TEST ) 1770 definitelyIdentityMatrix=
false;
1809 #if defined ( USE_MATRIX_TEST ) 1810 definitelyIdentityMatrix=
false;
1850 #if defined ( USE_MATRIX_TEST ) 1851 definitelyIdentityMatrix=
false;
1863 for (
u32 i=0; i < 16; i += 4)
1865 mat.M[i+0] = (T)(M[i+0] + ( b.M[i+0] - M[i+0] ) * time);
1866 mat.M[i+1] = (T)(M[i+1] + ( b.M[i+1] - M[i+1] ) * time);
1867 mat.M[i+2] = (T)(M[i+2] + ( b.M[i+2] - M[i+2] ) * time);
1868 mat.M[i+3] = (T)(M[i+3] + ( b.M[i+3] - M[i+3] ) * time);
1879 getTransposed ( t );
1907 #if defined ( USE_MATRIX_TEST ) 1908 o.definitelyIdentityMatrix=definitelyIdentityMatrix;
1917 const f32 scaleX = (viewport.
getWidth() - 0.75f ) * 0.5f;
1918 const f32 scaleY = -(viewport.
getHeight() - 0.75f ) * 0.5f;
1956 M[0] = vt.
X * v.X + ca;
1957 M[5] = vt.
Y * v.Y + ca;
1958 M[10] = vt.
Z * v.Z + ca;
2017 M[0] =
static_cast<T
>(vt.
X * up.
X + ca);
2018 M[5] =
static_cast<T
>(vt.
Y * up.
Y + ca);
2019 M[10] =
static_cast<T
>(vt.
Z * up.
Z + ca);
2025 M[1] =
static_cast<T
>(vt.
X - vs.
Z);
2026 M[2] =
static_cast<T
>(vt.
Z + vs.
Y);
2029 M[4] =
static_cast<T
>(vt.
X + vs.
Z);
2030 M[6] =
static_cast<T
>(vt.
Y - vs.
X);
2033 M[8] =
static_cast<T
>(vt.
Z - vs.
Y);
2034 M[9] =
static_cast<T
>(vt.
Y + vs.
X);
2037 setRotationCenter(center, translation);
2045 M[12] = -M[0]*center.
X - M[4]*center.
Y - M[8]*center.
Z + (center.
X - translation.
X );
2046 M[13] = -M[1]*center.
X - M[5]*center.
Y - M[9]*center.
Z + (center.
Y - translation.
Y );
2047 M[14] = -M[2]*center.
X - M[6]*center.
Y - M[10]*center.
Z + (center.
Z - translation.
Z );
2049 #if defined ( USE_MATRIX_TEST ) 2050 definitelyIdentityMatrix=
false;
2072 const f32 c = cosf(rotateRad);
2073 const f32 s = sinf(rotateRad);
2075 M[0] = (T)(c * scale.
X);
2076 M[1] = (T)(s * scale.
Y);
2080 M[4] = (T)(-s * scale.
X);
2081 M[5] = (T)(c * scale.
Y);
2085 M[8] = (T)(c * scale.
X * rotatecenter.
X + -s * rotatecenter.
Y + translate.
X);
2086 M[9] = (T)(s * scale.
Y * rotatecenter.
X + c * rotatecenter.
Y + translate.
Y);
2094 #if defined ( USE_MATRIX_TEST ) 2095 definitelyIdentityMatrix=
false;
2105 const f32 c = cosf(rotateRad);
2106 const f32 s = sinf(rotateRad);
2113 M[8] = (T)(0.5f * ( s - c) + 0.5f);
2114 M[9] = (T)(-0.5f * ( s + c) + 0.5f);
2116 #if defined ( USE_MATRIX_TEST ) 2117 definitelyIdentityMatrix = definitelyIdentityMatrix && (rotateRad==0.0f);
2129 #if defined ( USE_MATRIX_TEST ) 2130 definitelyIdentityMatrix = definitelyIdentityMatrix && (x==0.0f) && (y==0.0f);
2142 #if defined ( USE_MATRIX_TEST ) 2143 definitelyIdentityMatrix = definitelyIdentityMatrix && (x==0.0f) && (y==0.0f) ;
2153 #if defined ( USE_MATRIX_TEST ) 2154 definitelyIdentityMatrix = definitelyIdentityMatrix && (sx==1.0f) && (sy==1.0f);
2165 M[8] = (T)(0.5f - 0.5f * sx);
2166 M[9] = (T)(0.5f - 0.5f * sy);
2168 #if defined ( USE_MATRIX_TEST ) 2169 definitelyIdentityMatrix = definitelyIdentityMatrix && (sx==1.0f) && (sy==1.0f);
2179 memcpy(M,data, 16*
sizeof(T));
2181 #if defined ( USE_MATRIX_TEST ) 2182 definitelyIdentityMatrix=
false;
2192 #if defined ( USE_MATRIX_TEST ) 2193 definitelyIdentityMatrix = isDefinitelyIdentityMatrix;
2202 #if defined ( USE_MATRIX_TEST ) 2203 return definitelyIdentityMatrix;
2214 #if defined ( USE_MATRIX_TEST ) 2215 if (definitelyIdentityMatrix && other.definitelyIdentityMatrix)
2218 for (
s32 i = 0; i < 16; ++i)
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.
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
CMatrix4< T > getTransposed() const
Gets transposed matrix.
float f32
32 bit floating point variable.
CMatrix4< T > & setScale(const T scale)
Set Scale.
vector3d< T > Normal
Normal vector of the plane.
position2d< T > UpperLeftCorner
Upper left corner.
const T & operator[](u32 index) const
Simple operator for linearly accessing every element of the matrix.
bool isIdentity() const
Returns true if the matrix is the identity matrix.
T Y
Y coordinate of vector.
#define IRRLICHT_API
Set FPU settings.
T X
X coordinate of the vector.
Everything in the Irrlicht Engine can be found in this namespace.
3d vector template class with lots of operators and methods.
double f64
64 bit floating point variable.
position2d< T > LowerRightCorner
Lower right corner.
const f64 ROUNDING_ERROR_f64
signed int s32
32 bit signed variable.
REALINLINE f32 reciprocal(const f32 f)
void setPlane(const vector3d< T > &point, const vector3d< T > &nvector)
unsigned int u32
32 bit unsigned variable.
T getHeight() const
Get height of rectangle.
#define _IRR_DEBUG_BREAK_IF(_CONDITION_)
define a break macro for debugging.
T getWidth() const
Get width of rectangle.
const f32 DEGTORAD
32bit Constant for converting from degrees to radians
const T * pointer() const
Returns pointer to internal array.
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.
vector3d< T > MinEdge
The near edge.
4x4 matrix. Mostly used as transformation matrix for 3d calculations.
T dotProduct(const vector3d< T > &other) const
Get the dot product with another vector.
T & operator[](u32 index)
Simple operator for linearly accessing every element of the matrix.
T Z
Z coordinate of the vector.
bool getInverse(CMatrix4< T > &out) const
Gets the inversed matrix of this one.
CMatrix4< f32 > matrix4
Typedef for f32 matrix.
eConstructor
Constructor Flags.
CMatrix4< T > operator*(const T scalar, const CMatrix4< T > &mat)
void repair()
Repairs the box.
bool equals(const f64 a, const f64 b, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals b, taking possible rounding errors into account
T & operator()(const s32 row, const s32 col)
Simple operator for directly accessing every element of the matrix.
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
T X
X coordinate of vector.