GEL
2
GEL is a library for Geometry and Linear Algebra
|
00001 #ifndef __CGLA_ARITHSQMAT4X4FLOAT_H 00002 #define __CGLA_ARITHSQMAT4X4FLOAT_H 00003 00004 #include "ExceptionStandard.h" 00005 #include "CGLA.h" 00006 #include "Vec3f.h" 00007 #include "Vec3Hf.h" 00008 #include "Vec4f.h" 00009 #include "ArithSqMatFloat.h" 00010 00011 00012 namespace CGLA 00013 { 00014 CGLA_DERIVEEXCEPTION(Mat4x4fException) 00015 CGLA_DERIVEEXCEPTION(Mat4x4fNotAffine) 00016 CGLA_DERIVEEXCEPTION(Mat4x4fSingular) 00017 00022 template<class VT, class M> 00023 class ArithSqMat4x4Float: public ArithSqMatFloat<VT, M, 4> 00024 { 00025 public: 00026 00028 typedef VT VectorType; 00029 00031 typedef typename VT::ScalarType ScalarType; 00032 00033 public: 00034 00036 ArithSqMat4x4Float(VT a, VT b, VT c, VT d): 00037 ArithSqMatFloat<VT, M, 4> (a,b,c,d) {} 00038 00040 ArithSqMat4x4Float() {} 00041 00043 explicit ArithSqMat4x4Float(ScalarType _a): 00044 ArithSqMatFloat<VT,M,4>(_a) {} 00045 00052 template<class T, class VecT> 00053 const VecT mul_3D_vector(const ArithVec3Float<T,VecT>& v_in) const 00054 { 00055 VT v_out = (*this) * VT(v_in[0],v_in[1],v_in[2],0); 00056 return VecT(v_out[0],v_out[1],v_out[2]); 00057 } 00058 00065 template<class T, class VecT> 00066 const VecT mul_3D_point(const ArithVec3Float<T,VecT> & v_in) const 00067 { 00068 VT v_out = (*this) * VT(v_in[0],v_in[1],v_in[2],1); 00069 return VecT(v_out[0],v_out[1],v_out[2]); 00070 } 00071 00074 template<class T, class VecT> 00075 const VecT project_3D_point(const ArithVec3Float<T,VecT>& v_in) const 00076 { 00077 VT v_out = (*this) * VT(v_in[0],v_in[1],v_in[2],1); 00078 v_out.de_homogenize(); 00079 return VecT(v_out[0],v_out[1],v_out[2]); 00080 } 00081 00082 }; 00083 00087 template<class VT, class M> 00088 M adjoint(const ArithSqMat4x4Float<VT,M>&); 00089 00095 template<class V, class M> 00096 inline double determinant(const ArithSqMat4x4Float<V,M>& m) 00097 { 00098 /* return m[0][0] * (m[1][1]*(m[2][2]*m[3][3]-m[3][2]*m[2][3])- */ 00099 /* m[2][1]*(m[1][2]*m[3][3]-m[3][2]*m[1][3])+ */ 00100 /* m[3][1]*(m[1][2]*m[2][3]-m[2][2]*m[1][3])) */ 00101 /* - m[1][0] * (m[0][1]*(m[2][2]*m[3][3]-m[3][2]*m[2][3])- */ 00102 /* m[2][1]*(m[0][2]*m[3][3]-m[3][2]*m[0][3])+ */ 00103 /* m[3][1]*(m[0][2]*m[2][3]-m[2][2]*m[0][3])) */ 00104 /* + m[2][0] * (m[0][1]*(m[1][2]*m[3][3]-m[3][2]*m[1][3])- */ 00105 /* m[1][1]*(m[0][2]*m[3][3]-m[3][2]*m[0][3])+ */ 00106 /* m[3][1]*(m[0][2]*m[1][3]-m[1][2]*m[0][3])) */ 00107 /* - m[3][0] * (m[0][1]*(m[1][2]*m[2][3]-m[2][2]*m[1][3])- */ 00108 /* m[1][1]*(m[0][2]*m[2][3]-m[2][2]*m[0][3])+ */ 00109 /* m[2][1]*(m[0][2]*m[1][3]-m[1][2]*m[0][3])); */ 00110 typedef typename M::ScalarType ScalarType; 00111 ScalarType a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4; 00112 00113 /* assign to individual variable names to aid selecting */ 00114 /* correct elements */ 00115 00116 a1 = m[0][0]; b1 = m[1][0]; c1 = m[2][0]; d1 = m[3][0]; 00117 a2 = m[0][1]; b2 = m[1][1]; c2 = m[2][1]; d2 = m[3][1]; 00118 a3 = m[0][2]; b3 = m[1][2]; c3 = m[2][2]; d3 = m[3][2]; 00119 a4 = m[0][3]; b4 = m[1][3]; c4 = m[2][3]; d4 = m[3][3]; 00120 00121 return 00122 a1 * (b2*(c3*d4-d3*c4)-c2*(b3*d4-d3*b4)+d2*(b3*c4-c3*b4)) 00123 - b1 * (a2*(c3*d4-d3*c4)-c2*(a3*d4-d3*a4)+d2*(a3*c4-c3*a4)) 00124 + c1 * (a2*(b3*d4-d3*b4)-b2*(a3*d4-d3*a4)+d2*(a3*b4-b3*a4)) 00125 - d1 * (a2*(b3*c4-c3*b4)-b2*(a3*c4-c3*a4)+c2*(a3*b4-b3*a4)); 00126 00127 } 00128 00130 template<class VT, class M> 00131 M invert(const ArithSqMat4x4Float<VT,M>&); 00132 00134 template<class VT, class M> 00135 M invert_affine(const ArithSqMat4x4Float<VT,M>&); 00136 00137 } 00138 #endif 00139 00140 00141 00142 00143 00144 00145