7 #ifndef __math_matrix_h__ 8 #define __math_matrix_h__ 41 template<
int M,
int N,
class T>
51 template<
int I,
int J,
class U>
56 T
operator()(
unsigned int i,
unsigned int j)
const;
60 T operator[](
unsigned int index)
const;
61 T& operator[](
unsigned int index);
66 T *raw(
void) {
return m_data; }
67 const T *raw(
void)
const {
return m_data; }
74 template<
int M,
int N,
class T>
78 for(
unsigned int i = 0;i < M*N;i++)
83 template<
int M,
int N,
class T>
87 for(
unsigned int i = 0;i < M*N;i++)
88 m_data[i] = (T)other[i];
92 template<
int M,
int N,
class T>
93 template<
int I,
int J,
class U>
100 template<
int M,
int N,
class T>
103 return (0 == memcmp(reinterpret_cast<const void *>(m_data),
104 reinterpret_cast<const void *>(other.m_data), M*N*
sizeof(T)));
107 template<
int M,
int N,
class T>
111 if(i >= M || j >= N) { feX(e_invalidRange); }
113 return m_data[ j*M + i ];
116 template<
int M,
int N,
class T>
120 if(i >= M || j >= N) { feX(e_invalidRange); }
122 return m_data[ j*M + i ];
125 template<
int M,
int N,
class T>
129 if(index > M*N) { feX(e_invalidRange); }
131 return m_data[ index ];
134 template<
int M,
int N,
class T>
138 if(index > M*N) { feX(e_invalidRange); }
140 return m_data[ index ];
148 template<
int M,
int N,
class T>
157 template<
int M,
int N,
class T>
166 template<
int M,
int N,
class T>
175 template<
int M,
int N,
class T>
179 for(
unsigned int i = 0;i < M && i < N;i++)
184 template<
int M,
int N,
class T>
187 return setAll(matrix,T(0));
190 template<
int M,
int N,
class T,
class U>
193 for(
unsigned int i = 0;i < M*N;i++)
194 matrix[i] = pArray[i];
198 template<
int M,
int N,
class T,
class U>
201 for(
unsigned int i = 0;i < M*N;i++)
211 template<
int M,
int N,
class T>
215 for(
unsigned int i=0; i<M; i++)
217 for(
unsigned int j=0; j < N; j++)
219 A(j,i) = matrix(i,j);
228 template<
int M,
int N,
class T>
234 "cannot transpose non-square matrix in place");
237 for(
unsigned int i=0; i<M; i++)
239 for(
unsigned int j=i+1; j < N; j++)
242 matrix(i,j) = matrix(j,i);
252 template<
int M,
int N,
class T,
class U>
256 for(
unsigned int i = 0;i < M; i++)
258 for(
unsigned int j = 0;j < N; j++)
260 R(i,j) = A(i,j)+B(i,j);
269 template<
int M,
int N,
class T,
class U>
273 for(
unsigned int i = 0;i < M; i++)
275 for(
unsigned int j = 0;j < N; j++)
277 R(i,j) = A(i,j)-B(i,j);
286 template<
int M,
int N,
int L,
class T,
class U>
290 for(
unsigned int i = 0;i < M; i++)
292 for(
unsigned int j = 0;j < N; j++)
295 for(
unsigned int k = 0;k < L; k++)
297 sum += A(i,k)*B(k,j);
308 template<
int M,
int N,
class T,
class U>
312 for(
unsigned int i = 0;i < M; i++)
315 for(
unsigned int j = 0;j < N; j++)
327 template<
int M,
int N,
class T,
class U>
332 for(
unsigned int i = 0;i < M; i++)
335 for(
unsigned int j = 0;j < N; j++)
347 template<
int M,
int N,
class T>
352 for(
unsigned int i = 0;i < M; i++)
355 for(
unsigned int j = 0;j < N; j++)
367 template<
int M,
int N,
class T>
371 for(
unsigned int i = 0;i < M; i++)
373 for(
unsigned int j = 0;j < N; j++)
375 s.
catf(
"%6.3f ", a_m(i,j));
388 template<
int M,
int N,
class T>
392 for(
unsigned int i = 0;i < M; i++)
394 for(
unsigned int j = 0;j < N; j++)
396 fe_fprintf(a_fp,
"%6.3f ", a_m(i,j));
400 fe_fprintf(a_fp,
"\n");
409 template<
int M,
int N,
class T,
int I,
int J,
class U>
419 for(
int i = 0;i < m; i++)
421 for(
int j = 0;j < n; j++)
425 for(
int j = n;j < N; j++)
430 for(
int i = m;i < M; i++)
432 for(
int j = 0;j < N; j++)
442 template<
int M,
int N,
int I,
int J,
class T>
452 for(
int i = 0;i < m; i++)
454 for(
int j = 0;j < n; j++)
465 template<
int M,
int N,
class T,
class U>
468 for(
unsigned int i = 0;i < M*N; i++)
478 template<
int M,
int N,
class T,
class U>
482 for(
unsigned int i = 0;i < M*N; i++)
484 tmp[i] = scale * A[i];
492 template<
int M,
int N,
class T,
class U>
504 template<
int M,
int N,
class T,
class U>
516 template<
int M,
int N,
int L,
class T,
class U>
528 template<
int M,
int N,
class T>
537 template<
int M,
int N,
class T,
class U>
548 template<
int M,
int N,
class T,
class U>
557 template<
int M,
int N,
class T,
class U>
566 template<
int M,
int N,
class T>
572 for(
unsigned int i = 0; i < N-1; i++)
581 #if FE_COMPILER != FE_MICROSOFT 588 a_U(i,i) = sqrt(a_U(i,i));
589 #if FE_COMPILER != FE_MICROSOFT 596 if(a_U(i,i) <= 0.001) {
604 T z = 1.0 / a_U(i,i);
605 #if FE_COMPILER != FE_MICROSOFT 612 for(
unsigned int j = i+1; j < N; j++)
614 #if FE_COMPILER != FE_MICROSOFT 623 for(
unsigned int j = i+1; j < N; j++)
625 for(
unsigned int jj = j; jj < N; jj++)
627 a_U(j,jj) -= a_U(i,j) * a_U(i,jj);
628 #if FE_COMPILER != FE_MICROSOFT 639 #if FE_COMPILER != FE_MICROSOFT 640 if(isnan(a_U(N-1,N-1)))
647 if(a_U(N-1,N-1) < 0.0)
653 a_U(N-1,N-1) = sqrt(a_U(N-1,N-1));
654 #if FE_COMPILER != FE_MICROSOFT 655 if(isnan(a_U(N-1,N-1)))
666 arma::Mat<double> A(a_A.raw(),3,3);
668 arma::Mat<double> U(a_U.raw(),3,3,
false,
true);
672 if(!arma::chol(U, A))
687 template<
int M,
int N,
class T>
691 const unsigned int n_1 = N-1;
692 a_x[n_1] = a_b[n_1]/a_A(n_1, n_1);
694 for(
int i = N-2; i >= 0; i--)
697 for(
int j = i+1; j < N; j++)
699 a_x[i] -= a_A(i, j)*a_x[j];
701 a_x[i] = a_x[i] / a_A(i, i);
706 template<
int M,
int N,
class T>
710 a_x[0] = a_b[0]/a_A(0, 0);
711 for(
unsigned int i = 1; i < N; i++)
714 for(
unsigned int j = 0; j < i; j++)
716 a_x[i] -= a_A(j, i)*a_x[j];
718 a_x[i] = a_x[i] / a_A(i, i);
724 template <
typename T>
729 T r00, r01, r02, r10, r11, r12, r20, r21, r22;
732 r00 = a_matrix(0,0); r01 = a_matrix(0,1); r02 = a_matrix(0,2);
733 r10 = a_matrix(1,0); r11 = a_matrix(1,1); r12 = a_matrix(1,2);
734 r20 = a_matrix(2,0); r21 = a_matrix(2,1); r22 = a_matrix(2,2);
737 a_inverted(0,0) = r11*r22 - r21*r12;
738 a_inverted(1,0) = r20*r12 - r10*r22;
739 a_inverted(2,0) = r10*r21 - r20*r11;
743 1.0/(r00*a_inverted(0,0) + r01*a_inverted(1,0) + r02*a_inverted(2,0));
744 r00 *= one_over_det; r01 *= one_over_det; r02 *= one_over_det;
747 a_inverted(0,0) *= one_over_det;
748 a_inverted(1,0) *= one_over_det;
749 a_inverted(2,0) *= one_over_det;
750 a_inverted(3,0) = 0.0;
751 a_inverted(0,1) = r21*r02 - r01*r22;
752 a_inverted(1,1) = r00*r22 - r20*r02;
753 a_inverted(2,1) = r20*r01 - r00*r21;
754 a_inverted(3,1) = 0.0;
755 a_inverted(0,2) = r01*r12 - r11*r02;
756 a_inverted(1,2) = r10*r02 - r00*r12;
757 a_inverted(2,2) = r00*r11 - r10*r01;
758 a_inverted(3,2) = 0.0;
759 a_inverted(3,3) = 1.0;
772 a_inverted(0,3) = 0.0;
773 a_inverted(1,3) = 0.0;
774 a_inverted(2,3) = 0.0;
779 #define one_over_s one_over_det 787 px = a_inverted(0,0)*a + a_inverted(1,0)*b + a_inverted(2,0)*c;
788 py = a_inverted(0,1)*a + a_inverted(1,1)*b + a_inverted(2,1)*c;
789 pz = a_inverted(0,2)*a + a_inverted(1,2)*b + a_inverted(2,2)*c;
801 one_over_s = 1.0/(d - (tx*px + ty*py + tz*pz));
803 tx *= one_over_s; ty *= one_over_s; tz *= one_over_s;
806 TPinv(0,0) = tx*px + 1.0;
809 TPinv(3,0) = -px * one_over_s;
811 TPinv(1,1) = ty*py + 1.0;
813 TPinv(3,1) = -py * one_over_s;
816 TPinv(2,2) = tz*pz + 1.0;
817 TPinv(3,2) = -pz * one_over_s;
821 TPinv(3,3) = one_over_s;
824 multiply(a_inverted, preMult, TPinv);
840 -(tx*a_inverted(0,0) + ty*a_inverted(0,1) + tz*a_inverted(0,2));
842 -(tx*a_inverted(1,0) + ty*a_inverted(1,1) + tz*a_inverted(1,2));
844 -(tx*a_inverted(2,0) + ty*a_inverted(2,1) + tz*a_inverted(2,2));
854 template <
typename T>
855 inline T determinant3x3( T a1,T a2,T a3,
859 return a1*(b2*c3-b3*c2)
864 template <
typename T>
868 m[0]*determinant3x3(m[5],m[6],m[7],m[9],m[10],m[11],m[13],m[14],m[15])
869 -m[4]*determinant3x3(m[1],m[2],m[3],m[9],m[10],m[11],m[13],m[14],m[15])
870 +m[8]*determinant3x3(m[1],m[2],m[3],m[5],m[6],m[7],m[13],m[14],m[15])
871 -m[12]*determinant3x3(m[1],m[2],m[3],m[5],m[6],m[7],m[9],m[10],m[11]);
874 template <
typename T>
880 const F32 det=determinant(m);
885 feX(
"inversion failure");
889 const F32 inv=1.0f/det;
891 a_inverted[0]= inv*determinant3x3(
892 m[5],m[6],m[7],m[9],m[10],m[11],m[13],m[14],m[15]);
893 a_inverted[4]= -inv*determinant3x3(
894 m[1],m[2],m[3],m[9],m[10],m[11],m[13],m[14],m[15]);
895 a_inverted[8]= inv*determinant3x3(
896 m[1],m[2],m[3],m[5],m[6],m[7],m[13],m[14],m[15]);
897 a_inverted[12]= -inv*determinant3x3(
898 m[1],m[2],m[3],m[5],m[6],m[7],m[9],m[10],m[11]);
900 a_inverted[1]= -inv*determinant3x3(
901 m[4],m[6],m[7],m[8],m[10],m[11],m[12],m[14],m[15]);
902 a_inverted[5]= inv*determinant3x3(
903 m[0],m[2],m[3],m[8],m[10],m[11],m[12],m[14],m[15]);
904 a_inverted[9]= -inv*determinant3x3(
905 m[0],m[2],m[3],m[4],m[6],m[7],m[12],m[14],m[15]);
906 a_inverted[13]= inv*determinant3x3(
907 m[0],m[2],m[3],m[4],m[6],m[7],m[8],m[10],m[11]);
909 a_inverted[2]= inv*determinant3x3(
910 m[4],m[5],m[7],m[8],m[9],m[11],m[12],m[13],m[15]);
911 a_inverted[6]= -inv*determinant3x3(
912 m[0],m[1],m[3],m[8],m[9],m[11],m[12],m[13],m[15]);
913 a_inverted[10]= inv*determinant3x3(
914 m[0],m[1],m[3],m[4],m[5],m[7],m[12],m[13],m[15]);
915 a_inverted[14]= -inv*determinant3x3(
916 m[0],m[1],m[3],m[4],m[5],m[7],m[8],m[9],m[11]);
918 a_inverted[3]= -inv*determinant3x3(
919 m[4],m[5],m[6],m[8],m[9],m[10],m[12],m[13],m[14]);
920 a_inverted[7]= inv*determinant3x3(
921 m[0],m[1],m[2],m[8],m[9],m[10],m[12],m[13],m[14]);
922 a_inverted[11]= -inv*determinant3x3(
923 m[0],m[1],m[2],m[4],m[5],m[6],m[12],m[13],m[14]);
924 a_inverted[15]= inv*determinant3x3(
925 m[0],m[1],m[2],m[4],m[5],m[6],m[8],m[9],m[10]);
931 template <
typename T>
940 for(IWORD a = 0; a < 16; a++)
942 src[a] = a_matrix[a];
946 tmp[0] = src[10] * src[15];
947 tmp[1] = src[11] * src[14];
948 tmp[2] = src[9] * src[15];
949 tmp[3] = src[11] * src[13];
950 tmp[4] = src[9] * src[14];
951 tmp[5] = src[10] * src[13];
952 tmp[6] = src[8] * src[15];
953 tmp[7] = src[11] * src[12];
954 tmp[8] = src[8] * src[14];
955 tmp[9] = src[10] * src[12];
956 tmp[10] = src[8] * src[13];
957 tmp[11] = src[9] * src[12];
960 dst[0] = tmp[0]* src[5] + tmp[3]*src[6] + tmp[4]*src[7];
961 dst[0] -= tmp[1]*src[5] + tmp[2]*src[6] + tmp[5]*src[7];
962 dst[1] = tmp[1]* src[4] + tmp[6]*src[6] + tmp[9]*src[7];
963 dst[1] -= tmp[0]*src[4] + tmp[7]*src[6] + tmp[8]*src[7];
964 dst[2] = tmp[2]* src[4] + tmp[7]*src[5] + tmp[10]*src[7];
965 dst[2] -= tmp[3]*src[4] + tmp[6]*src[5] + tmp[11]*src[7];
966 dst[3] = tmp[5]* src[4] + tmp[8]*src[5] + tmp[11]*src[6];
967 dst[3] -= tmp[4]*src[4] + tmp[9]*src[5] + tmp[10]*src[6];
968 dst[4] = tmp[1]* src[1] + tmp[2]*src[2] + tmp[5]*src[3];
969 dst[4] -= tmp[0]*src[1] + tmp[3]*src[2] + tmp[4]*src[3];
970 dst[5] = tmp[0]* src[0] + tmp[7]*src[2] + tmp[8]*src[3];
971 dst[5] -= tmp[1]*src[0] + tmp[6]*src[2] + tmp[9]*src[3];
972 dst[6] = tmp[3]* src[0] + tmp[6]*src[1] + tmp[11]*src[3];
973 dst[6] -= tmp[2]*src[0] + tmp[7]*src[1] + tmp[10]*src[3];
974 dst[7] = tmp[4]* src[0] + tmp[9]*src[1] + tmp[10]*src[2];
975 dst[7] -= tmp[5]*src[0] + tmp[8]*src[1] + tmp[11]*src[2];
978 tmp[0] = src[2] * src[7];
979 tmp[1] = src[3] * src[6];
980 tmp[2] = src[1] * src[7];
981 tmp[3] = src[3] * src[5];
982 tmp[4] = src[1] * src[6];
983 tmp[5] = src[2] * src[5];
984 tmp[6] = src[0] * src[7];
985 tmp[7] = src[3] * src[4];
986 tmp[8] = src[0] * src[6];
987 tmp[9] = src[2] * src[4];
988 tmp[10] = src[0] * src[5];
989 tmp[11] = src[1] * src[4];
992 dst[8] = tmp[0]* src[13] + tmp[3]*src[14] + tmp[4]*src[15];
993 dst[8] -= tmp[1]*src[13] + tmp[2]*src[14] + tmp[5]*src[15];
994 dst[9] = tmp[1]* src[12] + tmp[6]*src[14] + tmp[9]*src[15];
995 dst[9] -= tmp[0]*src[12] + tmp[7]*src[14] + tmp[8]*src[15];
996 dst[10] = tmp[2]* src[12] + tmp[7]*src[13] + tmp[10]*src[15];
997 dst[10] -= tmp[3]*src[12] + tmp[6]*src[13] + tmp[11]*src[15];
998 dst[11] = tmp[5]* src[12] + tmp[8]*src[13] + tmp[11]*src[14];
999 dst[11] -= tmp[4]*src[12] + tmp[9]*src[13] + tmp[10]*src[14];
1000 dst[12] = tmp[2]* src[10] + tmp[5]*src[11] + tmp[1]*src[9];
1001 dst[12] -= tmp[4]*src[11] + tmp[0]*src[9] + tmp[3]*src[10];
1002 dst[13] = tmp[8]* src[11] + tmp[0]*src[8] + tmp[7]*src[10];
1003 dst[13] -= tmp[6]*src[10] + tmp[9]*src[11] + tmp[1]*src[8];
1004 dst[14] = tmp[6]* src[9] + tmp[11]*src[11] + tmp[3]*src[8];
1005 dst[14] -= tmp[10]*src[11] + tmp[2]*src[8] + tmp[7]*src[9];
1006 dst[15] = tmp[10]* src[10] + tmp[4]*src[8] + tmp[9]*src[9];
1007 dst[15] -= tmp[8]*src[9] + tmp[11]*src[10] + tmp[5]*src[8];
1010 det = determinant(a_matrix);
1014 for(IWORD j = 0; j < 16; j++)
1019 for(IWORD i = 0; i < 4; i++)
1021 a_inverted[i] = dst[i + 4];
1022 a_inverted[i + 4] = dst[i * 4 + 1];
1023 a_inverted[i + 8] = dst[i * 4 + 2];
1024 a_inverted[i + 12] = dst[i * 4 + 3];
1032 template <
typename T>
1042 template <
typename T>
1046 a_inverted(0,0)= a_matrix(1,1)*a_matrix(2,2) - a_matrix(2,1)*a_matrix(1,2);
1047 a_inverted(0,1)= -a_matrix(0,1)*a_matrix(2,2) + a_matrix(2,1)*a_matrix(0,2);
1048 a_inverted(0,2)= a_matrix(0,1)*a_matrix(1,2) - a_matrix(1,1)*a_matrix(0,2);
1049 a_inverted(1,0)= -a_matrix(1,0)*a_matrix(2,2) + a_matrix(2,0)*a_matrix(1,2);
1050 a_inverted(1,1)= a_matrix(0,0)*a_matrix(2,2) - a_matrix(2,0)*a_matrix(0,2);
1051 a_inverted(1,2)= -a_matrix(0,0)*a_matrix(1,2) + a_matrix(1,0)*a_matrix(0,2);
1052 a_inverted(2,0)= a_matrix(1,0)*a_matrix(2,1) - a_matrix(2,0)*a_matrix(1,1);
1053 a_inverted(2,1)= -a_matrix(0,0)*a_matrix(2,1) + a_matrix(2,0)*a_matrix(0,1);
1054 a_inverted(2,2)= a_matrix(0,0)*a_matrix(1,1) - a_matrix(1,0)*a_matrix(0,1);
1056 Real det = a_inverted(0,0) * a_matrix(0,0) + a_inverted(1,0) * a_matrix(0,1)
1057 + a_inverted(2,0) * a_matrix(0,2);
1059 if(fabs(det) < fe::tol)
1061 feX(
"attempt to invert singular 3x3 matrix");
1064 a_inverted *= 1.0 / det;
1069 template <
typename T>
1073 a_inverted(0,0)= a_matrix(1,1)*a_matrix(2,2) - a_matrix(2,1)*a_matrix(1,2);
1074 a_inverted(0,1)= -a_matrix(0,1)*a_matrix(2,2) + a_matrix(2,1)*a_matrix(0,2);
1075 a_inverted(0,2)= a_matrix(0,1)*a_matrix(1,2) - a_matrix(1,1)*a_matrix(0,2);
1076 a_inverted(1,0)= -a_matrix(1,0)*a_matrix(2,2) + a_matrix(2,0)*a_matrix(1,2);
1077 a_inverted(1,1)= a_matrix(0,0)*a_matrix(2,2) - a_matrix(2,0)*a_matrix(0,2);
1078 a_inverted(1,2)= -a_matrix(0,0)*a_matrix(1,2) + a_matrix(1,0)*a_matrix(0,2);
1079 a_inverted(2,0)= a_matrix(1,0)*a_matrix(2,1) - a_matrix(2,0)*a_matrix(1,1);
1080 a_inverted(2,1)= -a_matrix(0,0)*a_matrix(2,1) + a_matrix(2,0)*a_matrix(0,1);
1081 a_inverted(2,2)= a_matrix(0,0)*a_matrix(1,1) - a_matrix(1,0)*a_matrix(0,1);
1083 Real det = a_inverted(0,0) * a_matrix(0,0) + a_inverted(1,0) * a_matrix(0,1)
1084 + a_inverted(2,0) * a_matrix(0,2);
1086 if(fabs(det) < fe::tol)
1091 a_inverted *= 1.0 / det;
1097 template <
typename T>
1100 FEASSERT(fovy>0.0f);
1101 FEASSERT(aspect>0.0f);
1102 FEASSERT(nearplane>0.0f);
1103 FEASSERT(farplane>nearplane);
1108 T f=1.0f/tan(0.5f*fovy*degToRad);
1109 T d=nearplane-farplane;
1113 matrix[10]=(nearplane+farplane)/d;
1115 matrix[14]=2.0f*nearplane*farplane/d;
1121 template <
typename T>
1123 T &a_rFovy,T &a_rAspect,T &a_rNearplane,T &a_rFarplane)
1125 const Real a=a_rProjection[10];
1126 const Real b=a_rProjection[14];
1128 a_rAspect=a_rProjection[5]/a_rProjection[0];
1129 a_rFovy=2.0/degToRad*atan(1.0/a_rProjection[5]);
1130 a_rNearplane=0.5*(b*(a+1.0)/(a-1.0)-b);
1131 a_rFarplane=a_rNearplane*(a-1.0)/(a+1.0);
1158 template <
typename T>
1166 T dz = far_val-near_val;
1170 matrix[10] = -2.0/dz;
1172 matrix[12] = -(right+left)/dx;
1173 matrix[13] = -(top+bottom)/dy;
1174 matrix[14] = -(far_val+near_val)/dz;
1181 template <
typename T>
1185 const T w=1.0f/(a_v[0]*a_m[3]+a_v[1]*a_m[7]+a_v[2]*a_m[11]+a_m[15] );
1186 a_r[0]=a_v[0]*a_m[0]+a_v[1]*a_m[4]+a_v[2]*a_m[8]+a_m[12];
1187 a_r[1]=a_v[0]*a_m[1]+a_v[1]*a_m[5]+a_v[2]*a_m[9]+a_m[13];
1188 a_r[2]=a_v[0]*a_m[2]+a_v[1]*a_m[6]+a_v[2]*a_m[10]+a_m[14];
1196 template <
typename T>
1200 const Vector<4,T> inverted=inverseTransformVector(a_m,a_v);
1201 if(inverted[3]==T(0))
1207 a_r[3]=T(1)/inverted[3];
1208 a_r[0]=inverted[0]*a_r[3];
1209 a_r[1]=inverted[1]*a_r[3];
1210 a_r[2]=inverted[2]*a_r[3];
1213 template <
typename T>
1218 a_v[0]*a_m[0] +a_v[1]*a_m[4] +a_v[2]*a_m[8] +a_v[3]*a_m[12],
1219 a_v[0]*a_m[1] +a_v[1]*a_m[5] +a_v[2]*a_m[9] +a_v[3]*a_m[13],
1220 a_v[0]*a_m[2] +a_v[1]*a_m[6] +a_v[2]*a_m[10] +a_v[3]*a_m[14],
1221 a_v[0]*a_m[3] +a_v[1]*a_m[7] +a_v[2]*a_m[11] +a_v[3]*a_m[15]);
1224 template <
int N,
typename T>
1230 transformVector(lhs,in,out);
1235 template <
int N,
typename T>
1242 return transformVector(inverse,in);
1245 template <
typename T>
1246 inline void transposeTransformVector(
const Matrix<4,4,T> &a_m,
1251 a_v[0]*a_m[0] +a_v[1]*a_m[1] +a_v[2]*a_m[2] +a_v[3]*a_m[3],
1252 a_v[0]*a_m[4] +a_v[1]*a_m[5] +a_v[2]*a_m[6] +a_v[3]*a_m[7],
1253 a_v[0]*a_m[8] +a_v[1]*a_m[9] +a_v[2]*a_m[10] +a_v[3]*a_m[11],
1254 a_v[0]*a_m[12] +a_v[1]*a_m[13] +a_v[2]*a_m[14] +a_v[3]*a_m[15]);
1265 template<
int N,
typename T>
1273 for(U32 m=0;m<N;m++)
1275 result[m]=vector[m]/diagonal(m,m);
1288 template<
int N,
class T>
1293 for(U32 i=0;i<N;i++)
1296 for(U32 j=0;j<N;j++)
1298 result(i,j)=rhs(i,j)*d;
1313 template<
int N,
class T>
1318 for(U32 j=0;j<N;j++)
1321 for(U32 i=0;i<N;i++)
1323 result(i,j)=lhs(i,j)*d;
1329 template<
int N,
class T>
1333 for(
unsigned int i = 0; i < N; i++)
1335 for(
unsigned int j = 0; j < N; j++)
1337 result(i,j) = a[i] * b[j];
1348 template <
typename T,
typename U>
1351 const T sina=sin(radians);
1352 const T cosa=cos(radians);
1354 static const U32 index[3][2]={{1,2},{2,0},{0,1}};
1355 U32 x1=index[axis][0];
1356 U32 x2=index[axis][1];
1360 lhs(0,x1)=c*sina+b*cosa;
1361 lhs(0,x2)=c*cosa-b*sina;
1364 lhs(1,x1)=c*sina+b*cosa;
1365 lhs(1,x2)=c*cosa-b*sina;
1368 lhs(2,x1)=c*sina+b*cosa;
1369 lhs(2,x2)=c*cosa-b*sina;
Vector< M, T > transposeMultiply(const Matrix< M, N, T > &A, const Vector< N, T > &x)
Matrix Vector multiply with the matrix transposed.
Definition: Matrix.h:348
Matrix< M, N, T > & subtract(Matrix< M, N, T > &R, const Matrix< M, N, T > &A, const Matrix< M, N, U > &B)
Matrix Matrix subtract.
Definition: Matrix.h:270
Matrix< N, N, T > & postmultiplyInverseDiagonal(Matrix< N, N, T > &result, const Matrix< N, N, T > &lhs, const Matrix< N, N, T > &rhs)
Matrix-Matrix multiply where first matrix is presumed diagonal.
Definition: Matrix.h:1314
Matrix< 3, 3, T > & rotateMatrix(Matrix< 3, 3, T > &lhs, U radians, Axis axis)
3D Matrix rotation
Definition: Matrix.h:1349
void unproject(Vector< 4, T > &a_r, const Matrix< 4, 4, T > &a_m, const Vector< 4, T > &a_v)
reverse project vector through matrix. reverses w division
Definition: Matrix.h:1197
Matrix< M, N, T > operator*(const U lhs, const Matrix< M, N, T > &rhs)
Matrix Scale.
Definition: Matrix.h:549
Vector< M, T > & multiply(Vector< M, T > &b, const Matrix< M, N, T > &A, const Vector< N, U > &x)
Matrix Vector multiply.
Definition: Matrix.h:309
Matrix< N, N, T > & premultiplyInverseDiagonal(Matrix< N, N, T > &result, const Matrix< N, N, T > &lhs, const Matrix< N, N, T > &rhs)
Matrix-Matrix multiply where first matrix is presumed diagonal.
Definition: Matrix.h:1289
String fprint(FILE *a_fp, const Matrix< M, N, T > &a_m)
Matrix print.
Definition: Matrix.h:389
Vector< M, T > multiply(const Matrix< M, N, T > &A, const Vector< N, U > &x)
Matrix Vector multiply.
Definition: Matrix.h:328
Matrix< N, M, T > transpose(const Matrix< M, N, T > &matrix)
Return transpose of matrix.
Definition: Matrix.h:212
kernel
Definition: namespace.dox:3
String print(const Matrix< M, N, T > &a_m)
Matrix print.
Definition: Matrix.h:368
Matrix< 4, 4, T > & invert(Matrix< 4, 4, T > &a_inverted, const Matrix< 4, 4, T > &a_matrix)
4x4 full matrix inversion
Definition: Matrix.h:1033
General template for fixed size numeric matrices.
Definition: Matrix.h:42
Matrix< 4, 4, T > ortho(T left, T right, T bottom, T top, T near_val, T far_val)
Create orthogonal projection transform just like glOrtho.
Definition: Matrix.h:1159
void decomposePerspective(const Matrix< 4, 4, T > &a_rProjection, T &a_rFovy, T &a_rAspect, T &a_rNearplane, T &a_rFarplane)
Try to extract settings of a perspective matrix.
Definition: Matrix.h:1122
Matrix< M, N, T > operator*(const Matrix< M, N, T > &lhs, const Real rhs)
Matrix Scale.
Definition: Matrix.h:529
Vector< M, U > operator*(const Matrix< M, N, T > &lhs, const Vector< N, U > &rhs)
Matrix Vector multiply.
Definition: Matrix.h:538
Dense vector - size fixed by template.
Definition: Vector.h:19
Matrix< M, L, T > operator*(const Matrix< M, N, T > &lhs, const Matrix< N, L, U > &rhs)
Matrix Matrix multiply.
Definition: Matrix.h:517
void overlay(Matrix< M, N, T > &lhs, const Matrix< I, J, T > &rhs)
Matrix overlay.
Definition: Matrix.h:443
T operator()(unsigned int i, unsigned int j) const
Column Major addressing.
Definition: Matrix.h:108
Matrix< 4, 4, T > & osg_invert(Matrix< 4, 4, T > &a_inverted, const Matrix< 4, 4, T > &a_matrix)
4x4 invert
Definition: Matrix.h:725
String & cat(const char *operand)
Append the current String with the given text.
Definition: String.cc:545
U32 height(const Matrix< M, N, T > &matrix)
Return the vertical dimension.
Definition: Matrix.h:158
Matrix< M, N, T > operator+(const Matrix< M, N, T > &lhs, const Matrix< M, N, U > &rhs)
Matrix Matrix add.
Definition: Matrix.h:493
Automatically reference-counted string container.
Definition: String.h:128
Matrix< M, N, T > multiply(const Matrix< M, N, T > &A, const U &scale)
Matrix scale.
Definition: Matrix.h:479
void project(Vector< 4, T > &a_r, const Matrix< 4, 4, T > &a_m, const Vector< 4, T > &a_v)
project vector through matrix. divides by transformed w
Definition: Matrix.h:1182
Matrix< 4, 4, T > perspective(T fovy, T aspect, T nearplane, T farplane)
Create perspective projection transform just like gluPerspective.
Definition: Matrix.h:1098
U32 width(const Matrix< M, N, T > &matrix)
Return the horizonatal dimension.
Definition: Matrix.h:149
Matrix< M, N, T > & setTranspose(Matrix< M, N, T > &matrix)
Transpose matrix in place.
Definition: Matrix.h:229
Matrix< M, N, T > operator-(const Matrix< M, N, T > &lhs, const Matrix< M, N, U > &rhs)
Matrix Matrix subtract.
Definition: Matrix.h:505
String & catf(const char *fmt,...)
Populate the string as with sPrintf(), but by concatenating the results to the existing string...
Definition: String.cc:554
Matrix< M, N, T > & add(Matrix< M, N, T > &R, const Matrix< M, N, T > &A, const Matrix< M, N, U > &B)
Matrix Matrix add.
Definition: Matrix.h:253
Matrix< M, N, T > & setIdentity(Matrix< M, N, T > &matrix)
Set matrix to identity matrix.
Definition: Matrix.h:176
void premultiplyInverseDiagonal(Vector< N, T > &result, const Matrix< N, N, T > &diagonal, const Vector< N, T > &vector)
Compute the per-element product of the vector and the inverse diagonal entries.
Definition: Matrix.h:1266
void copy(Matrix< M, N, T > &lhs, const Matrix< I, J, U > &rhs)
Matrix copy.
Definition: Matrix.h:410
bool isSquare(const Matrix< M, N, T > &matrix)
Return true is matrix is square, otherwise return false.
Definition: Matrix.h:167
Matrix< M, N, T > & operator*=(Matrix< M, N, T > &lhs, const U rhs)
Matrix Scale.
Definition: Matrix.h:558
Partially specialized 4-component vector intended for spatial use.
Definition: Vector4.h:21
Matrix< M, N, T > & multiply(Matrix< M, N, T > &R, const Matrix< M, L, T > &A, const Matrix< L, N, U > &B)
Matrix Matrix multiply.
Definition: Matrix.h:287
Matrix< M, N, T > & multiply(Matrix< M, N, T > &A, const U &scale)
Matrix scale in place.
Definition: Matrix.h:466
void squareroot(Matrix< M, N, T > &a_U, const Matrix< M, N, T > &a_A)
Square root of a matrix.
Definition: Matrix.h:567