_Matrix3.cc

Go to the documentation of this file.
00001 #include <vecmath/GMatrix.h>
00002 #include <vecmath/Matrix3SVD.h>
00003 
00004 template<> const double _Matrix3<double>::EPS = 1e-16;
00005 template<> const double _Matrix3<double>::ERR_EPS = 1e-08;
00006 template<> const float _Matrix3<float>::EPS = 1e-16;
00007 template<> const float _Matrix3<float>::ERR_EPS = 1e-08;
00008 
00009 template <class Type>
00010 void _Matrix3<Type>::add(Type d)
00011 {
00012     m00 += d;
00013     m01 += d;
00014     m02 += d;
00015     m10 += d;
00016     m11 += d;
00017     m12 += d;
00018     m20 += d;
00019     m21 += d;
00020     m22 += d;
00021 }
00022 
00023 template <class Type>
00024 void _Matrix3<Type>::add(Type d, const _Matrix3<Type>& m)
00025 {
00026     set(m.m00 + d, m.m01 + d, m.m02 + d,
00027         m.m10 + d, m.m11 + d, m.m12 + d,
00028         m.m20 + d, m.m21 + d, m.m22 + d);
00029 }
00030 
00031 template <class Type>
00032 void _Matrix3<Type>::add(const _Matrix3<Type>& m)
00033 {
00034     m00 += m.m00;
00035     m01 += m.m01;
00036     m02 += m.m02;
00037     m10 += m.m10;
00038     m11 += m.m11;
00039     m12 += m.m12;
00040     m20 += m.m20;
00041     m21 += m.m21;
00042     m22 += m.m22;
00043 }
00044 
00045 template <class Type>
00046 void _Matrix3<Type>::add(const _Matrix3<Type>& m, const _Matrix3<Type>& m1)
00047 {
00048     set(m.m00 + m1.m00, m.m01 + m1.m01, m.m02 + m1.m02,
00049         m.m10 + m1.m10, m.m11 + m1.m11, m.m12 + m1.m12,
00050         m.m20 + m1.m20, m.m21 + m1.m21, m.m22 + m1.m22);
00051 }
00052 
00053 template <class Type>
00054 void _Matrix3<Type>::compute_svd(double m[9], double scale[3], double rot[9], bool flag)
00055 {
00056 #if 0
00057     GMatrix gad(3, 3, ad, true);
00058     GMatrix gad1(3, 3, ad1, true);
00059     GMatrix gad2(3, 3, ad2, true);
00060     
00061     gad.computeSVD(gad, gad, gad1, gad2, flag);
00062 #endif
00063     
00064     double scale_a[9];
00065     Matrix3SVD::compute_svd(m, scale_a, rot, false);
00066     scale[0] = scale_a[0];
00067     scale[1] = scale_a[1];
00068     scale[2] = scale_a[2];
00069 //  cerr << "Matrix3x3 compute_svd not properly implemented - check!" << endl;
00070 }
00071 
00072 template <class Type>
00073 bool _Matrix3<Type>::epsilonEquals(const _Matrix3<Type>& m, Type epsilon) const
00074 {
00075     return (Math::epsilonEquals(m00, m.m00, epsilon) &&
00076             Math::epsilonEquals(m01, m.m01, epsilon) &&
00077             Math::epsilonEquals(m02, m.m02, epsilon) &&
00078             Math::epsilonEquals(m10, m.m10, epsilon) &&
00079             Math::epsilonEquals(m11, m.m11, epsilon) &&
00080             Math::epsilonEquals(m12, m.m12, epsilon) &&
00081             Math::epsilonEquals(m20, m.m20, epsilon) &&
00082             Math::epsilonEquals(m21, m.m21, epsilon) &&
00083             Math::epsilonEquals(m22, m.m22, epsilon));
00084 }
00085 
00086 template <class Type>
00087 bool _Matrix3<Type>::equals(const _Matrix3<Type>& m) const
00088 {
00089     return (m00 == m.m00 && m01 == m.m01 && m02 == m.m02
00090             && m10 == m.m10 && m11 == m.m11 && m12 == m.m12
00091             && m20 == m.m20 && m21 == m.m21 && m22 == m.m22);
00092 }
00093 
00094 template <class Type>
00095 void _Matrix3<Type>::getColumn(int column, _Vector3<Type>& v) const
00096 {
00097     switch (column) {
00098     case 0:
00099         v.set(m00, m10, m20);
00100         break;
00101     case 1:
00102         v.set(m01, m11, m21);
00103         break;
00104     case 2:
00105         v.set(m02, m12, m22);
00106         break;
00107     default:
00108         break;
00109     }
00110 }
00111 
00112 template <class Type>
00113 void _Matrix3<Type>::getColumn(int column, Type ad[]) const
00114 {
00115     switch (column) {
00116     case 0:
00117         ad[0] = m00;
00118         ad[1] = m10;
00119         ad[2] = m20;
00120         break;
00121     case 1:
00122         ad[0] = m01;
00123         ad[1] = m11;
00124         ad[2] = m21;
00125         break;
00126     case 2:
00127         ad[0] = m02;
00128         ad[1] = m12;
00129         ad[2] = m22;
00130         break;
00131     default:
00132         break;
00133     }
00134 }
00135 
00136 template <class Type>
00137 Type _Matrix3<Type>::getElement(int row, int column) const
00138 {
00139     switch (row) {
00140     case 0:
00141         switch (column) {
00142         case 0: return m00;
00143         case 1: return m01;
00144         case 2: return m02;
00145         }
00146         break;
00147     case 1:
00148         switch (column) {
00149         case 0: return m10;
00150         case 1: return m11;
00151         case 2: return m12;
00152         }
00153         break;
00154     case 2:
00155         switch (column) {
00156         case 0: return m20;
00157         case 1: return m21;
00158         case 2: return m22;
00159         }
00160         break;
00161     }
00162     return 0;
00163 }
00164 
00165 template <class Type>
00166 void _Matrix3<Type>::getRow(int row, _Vector3<Type>& v) const
00167 {
00168     switch (row) {
00169     case 0:
00170         v.set(m00, m01, m02);
00171         break;
00172     case 1:
00173         v.set(m10, m11, m12);
00174         break;
00175     case 2:
00176         v.set(m20, m21, m22);
00177         break;
00178     default:
00179         break;
00180     }
00181 }
00182 
00183 template <class Type>
00184 void _Matrix3<Type>::getRow(int row, Type ad[3]) const
00185 {
00186     switch (row) {
00187     case 0:
00188         ad[0] = m00;
00189         ad[1] = m01;
00190         ad[2] = m02;
00191         break;
00192     case 1:
00193         ad[0] = m10;
00194         ad[1] = m11;
00195         ad[2] = m12;
00196         break;
00197     case 2:
00198         ad[0] = m20;
00199         ad[1] = m21;
00200         ad[2] = m22;
00201         break;
00202     default:
00203         break;
00204     }
00205 }
00206 
00207 template <class Type>
00208 void _Matrix3<Type>::invert(const _Matrix3<Type>& m)
00209 {
00210     Type d = m.determinant();
00211 
00212     if (this != &m) {
00213         m00 = (m.m11 * m.m22 - m.m21 * m.m12) / d;
00214         m01 = (m.m02 * m.m21 - m.m22 * m.m01) / d;
00215         m02 = (m.m01 * m.m12 - m.m11 * m.m02) / d;
00216 
00217         m10 = (m.m12 * m.m20 - m.m22 * m.m10) / d;
00218         m11 = (m.m00 * m.m22 - m.m20 * m.m02) / d;
00219         m12 = (m.m02 * m.m10 - m.m12 * m.m00) / d;
00220 
00221         m20 = (m.m10 * m.m21 - m.m20 * m.m11) / d;
00222         m21 = (m.m01 * m.m20 - m.m21 * m.m00) / d;
00223         m22 = (m.m00 * m.m11 - m.m10 * m.m01) / d;
00224     } else {
00225         Type ad[9];
00226 
00227         ad[0] = (m.m11 * m.m22 - m.m21 * m.m12) / d;
00228         ad[1] = (m.m02 * m.m21 - m.m22 * m.m01) / d;
00229         ad[2] = (m.m01 * m.m12 - m.m11 * m.m02) / d;
00230 
00231         ad[3] = (m.m12 * m.m20 - m.m22 * m.m10) / d;
00232         ad[4] = (m.m00 * m.m22 - m.m20 * m.m02) / d;
00233         ad[5] = (m.m02 * m.m10 - m.m12 * m.m00) / d;
00234 
00235         ad[6] = (m.m10 * m.m21 - m.m20 * m.m11) / d;
00236         ad[7] = (m.m01 * m.m20 - m.m21 * m.m00) / d;
00237         ad[8] = (m.m00 * m.m11 - m.m10 * m.m01) / d;
00238         set(ad);
00239     }
00240 }
00241 
00242 template <class Type>
00243 void _Matrix3<Type>::mul(Type d)
00244 {
00245     m00 *= d;
00246     m01 *= d;
00247     m02 *= d;
00248     m10 *= d;
00249     m11 *= d;
00250     m12 *= d;
00251     m20 *= d;
00252     m21 *= d;
00253     m22 *= d;
00254 }
00255 
00256 template <class Type>
00257 void _Matrix3<Type>::mul(Type d, const _Matrix3<Type>& m)
00258 {
00259     set(m.m00 * d, m.m01 * d, m.m02 * d,
00260         m.m10 * d, m.m11 * d, m.m12 * d,
00261         m.m20 * d, m.m21 * d, m.m22 * d);
00262 }
00263 
00264 
00265 template <class Type>
00266 void _Matrix3<Type>::mul(const _Matrix3<Type>& m, const _Matrix3<Type>& m1)
00267 {
00268     if(this != &m && this != &m1) {
00269         m00 = m.m00 * m1.m00 + m.m01 * m1.m10 + m.m02 * m1.m20;
00270         m01 = m.m00 * m1.m01 + m.m01 * m1.m11 + m.m02 * m1.m21;
00271         m02 = m.m00 * m1.m02 + m.m01 * m1.m12 + m.m02 * m1.m22;
00272         m10 = m.m10 * m1.m00 + m.m11 * m1.m10 + m.m12 * m1.m20;
00273         m11 = m.m10 * m1.m01 + m.m11 * m1.m11 + m.m12 * m1.m21;
00274         m12 = m.m10 * m1.m02 + m.m11 * m1.m12 + m.m12 * m1.m22;
00275         m20 = m.m20 * m1.m00 + m.m21 * m1.m10 + m.m22 * m1.m20;
00276         m21 = m.m20 * m1.m01 + m.m21 * m1.m11 + m.m22 * m1.m21;
00277         m22 = m.m20 * m1.m02 + m.m21 * m1.m12 + m.m22 * m1.m22;
00278     } else {
00279         Type d0 = m.m00 * m1.m00 + m.m01 * m1.m10 + m.m02 * m1.m20;
00280         Type d1 = m.m00 * m1.m01 + m.m01 * m1.m11 + m.m02 * m1.m21;
00281         Type d2 = m.m00 * m1.m02 + m.m01 * m1.m12 + m.m02 * m1.m22;
00282         Type d3 = m.m10 * m1.m00 + m.m11 * m1.m10 + m.m12 * m1.m20;
00283         Type d4 = m.m10 * m1.m01 + m.m11 * m1.m11 + m.m12 * m1.m21;
00284         Type d5 = m.m10 * m1.m02 + m.m11 * m1.m12 + m.m12 * m1.m22;
00285         Type d6 = m.m20 * m1.m00 + m.m21 * m1.m10 + m.m22 * m1.m20;
00286         Type d7 = m.m20 * m1.m01 + m.m21 * m1.m11 + m.m22 * m1.m21;
00287         Type d8 = m.m20 * m1.m02 + m.m21 * m1.m12 + m.m22 * m1.m22;
00288         set(d0, d1, d2,
00289             d3, d4, d5,
00290             d6, d7, d8);
00291     }
00292 }
00293 
00294 template <class Type>
00295 void _Matrix3<Type>::mulNormalize(const _Matrix3<Type>& m, const _Matrix3<Type>& m1)
00296 {
00297     double tmp[9];
00298     double tmp_scale[9];
00299     double tmp_rot[9];
00300     tmp[0] = m.m00 * m1.m00 + m.m01 * m1.m10 + m.m02 * m1.m20;
00301     tmp[1] = m.m00 * m1.m01 + m.m01 * m1.m11 + m.m02 * m1.m21;
00302     tmp[2] = m.m00 * m1.m02 + m.m01 * m1.m12 + m.m02 * m1.m22;
00303     tmp[3] = m.m10 * m1.m00 + m.m11 * m1.m10 + m.m12 * m1.m20;
00304     tmp[4] = m.m10 * m1.m01 + m.m11 * m1.m11 + m.m12 * m1.m21;
00305     tmp[5] = m.m10 * m1.m02 + m.m11 * m1.m12 + m.m12 * m1.m22;
00306     tmp[6] = m.m20 * m1.m00 + m.m21 * m1.m10 + m.m22 * m1.m20;
00307     tmp[7] = m.m20 * m1.m01 + m.m21 * m1.m11 + m.m22 * m1.m21;
00308     tmp[8] = m.m20 * m1.m02 + m.m21 * m1.m12 + m.m22 * m1.m22;
00309     compute_svd(tmp, tmp_scale, tmp_rot, false);
00310     set(tmp_rot);
00311 }
00312 
00313 template <class Type>
00314 void _Matrix3<Type>::mulTransposeBoth(const _Matrix3<Type> m, const _Matrix3<Type>& m1)
00315 {
00316     if(this != &m && this != &m1) {
00317         m00 = m.m00 * m1.m00 + m.m10 * m1.m01 + m.m20 * m1.m02;
00318         m01 = m.m00 * m1.m10 + m.m10 * m1.m11 + m.m20 * m1.m12;
00319         m02 = m.m00 * m1.m20 + m.m10 * m1.m21 + m.m20 * m1.m22;
00320         m10 = m.m01 * m1.m00 + m.m11 * m1.m01 + m.m21 * m1.m02;
00321         m11 = m.m01 * m1.m10 + m.m11 * m1.m11 + m.m21 * m1.m12;
00322         m12 = m.m01 * m1.m20 + m.m11 * m1.m21 + m.m21 * m1.m22;
00323         m20 = m.m02 * m1.m00 + m.m12 * m1.m01 + m.m22 * m1.m02;
00324         m21 = m.m02 * m1.m10 + m.m12 * m1.m11 + m.m22 * m1.m12;
00325         m22 = m.m02 * m1.m20 + m.m12 * m1.m21 + m.m22 * m1.m22;
00326     } else {
00327         Type d0 = m.m00 * m1.m00 + m.m10 * m1.m01 + m.m20 * m1.m02;
00328         Type d1 = m.m00 * m1.m10 + m.m10 * m1.m11 + m.m20 * m1.m12;
00329         Type d2 = m.m00 * m1.m20 + m.m10 * m1.m21 + m.m20 * m1.m22;
00330         Type d3 = m.m01 * m1.m00 + m.m11 * m1.m01 + m.m21 * m1.m02;
00331         Type d4 = m.m01 * m1.m10 + m.m11 * m1.m11 + m.m21 * m1.m12;
00332         Type d5 = m.m01 * m1.m20 + m.m11 * m1.m21 + m.m21 * m1.m22;
00333         Type d6 = m.m02 * m1.m00 + m.m12 * m1.m01 + m.m22 * m1.m02;
00334         Type d7 = m.m02 * m1.m10 + m.m12 * m1.m11 + m.m22 * m1.m12;
00335         Type d8 = m.m02 * m1.m20 + m.m12 * m1.m21 + m.m22 * m1.m22;
00336         set(d0, d1, d2,
00337             d3, d4, d5,
00338             d6, d7, d8);
00339     }
00340 }
00341 
00342 template <class Type>
00343 void _Matrix3<Type>::mulTransposeLeft(const _Matrix3<Type>& m, const _Matrix3<Type>& m1)
00344 {
00345     if(this != &m && this != &m1) {
00346         m00 = m.m00 * m1.m00 + m.m10 * m1.m10 + m.m20 * m1.m20;
00347         m01 = m.m00 * m1.m01 + m.m10 * m1.m11 + m.m20 * m1.m21;
00348         m02 = m.m00 * m1.m02 + m.m10 * m1.m12 + m.m20 * m1.m22;
00349         m10 = m.m01 * m1.m00 + m.m11 * m1.m10 + m.m21 * m1.m20;
00350         m11 = m.m01 * m1.m01 + m.m11 * m1.m11 + m.m21 * m1.m21;
00351         m12 = m.m01 * m1.m02 + m.m11 * m1.m12 + m.m21 * m1.m22;
00352         m20 = m.m02 * m1.m00 + m.m12 * m1.m10 + m.m22 * m1.m20;
00353         m21 = m.m02 * m1.m01 + m.m12 * m1.m11 + m.m22 * m1.m21;
00354         m22 = m.m02 * m1.m02 + m.m12 * m1.m12 + m.m22 * m1.m22;
00355     } else {
00356         Type d0 = m.m00 * m1.m00 + m.m10 * m1.m10 + m.m20 * m1.m20;
00357         Type d1 = m.m00 * m1.m01 + m.m10 * m1.m11 + m.m20 * m1.m21;
00358         Type d2 = m.m00 * m1.m02 + m.m10 * m1.m12 + m.m20 * m1.m22;
00359         Type d3 = m.m01 * m1.m00 + m.m11 * m1.m10 + m.m21 * m1.m20;
00360         Type d4 = m.m01 * m1.m01 + m.m11 * m1.m11 + m.m21 * m1.m21;
00361         Type d5 = m.m01 * m1.m02 + m.m11 * m1.m12 + m.m21 * m1.m22;
00362         Type d6 = m.m02 * m1.m00 + m.m12 * m1.m10 + m.m22 * m1.m20;
00363         Type d7 = m.m02 * m1.m01 + m.m12 * m1.m11 + m.m22 * m1.m21;
00364         Type d8 = m.m02 * m1.m02 + m.m12 * m1.m12 + m.m22 * m1.m22;
00365         set(d0, d1, d2,
00366             d3, d4, d5,
00367             d6, d7, d8);
00368     }
00369 }
00370 
00371 template <class Type>
00372 void _Matrix3<Type>::mulTransposeRight(const _Matrix3<Type>& m, const _Matrix3<Type>& m1)
00373 {
00374     if(this != &m && this != &m1) {
00375         m00 = m.m00 * m1.m00 + m.m01 * m1.m01 + m.m02 * m1.m02;
00376         m01 = m.m00 * m1.m10 + m.m01 * m1.m11 + m.m02 * m1.m12;
00377         m02 = m.m00 * m1.m20 + m.m01 * m1.m21 + m.m02 * m1.m22;
00378         m10 = m.m10 * m1.m00 + m.m11 * m1.m01 + m.m12 * m1.m02;
00379         m11 = m.m10 * m1.m10 + m.m11 * m1.m11 + m.m12 * m1.m12;
00380         m12 = m.m10 * m1.m20 + m.m11 * m1.m21 + m.m12 * m1.m22;
00381         m20 = m.m20 * m1.m00 + m.m21 * m1.m01 + m.m22 * m1.m02;
00382         m21 = m.m20 * m1.m10 + m.m21 * m1.m11 + m.m22 * m1.m12;
00383         m22 = m.m20 * m1.m20 + m.m21 * m1.m21 + m.m22 * m1.m22;
00384     } else {
00385         Type d0 = m.m00 * m1.m00 + m.m01 * m1.m01 + m.m02 * m1.m02;
00386         Type d1 = m.m00 * m1.m10 + m.m01 * m1.m11 + m.m02 * m1.m12;
00387         Type d2 = m.m00 * m1.m20 + m.m01 * m1.m21 + m.m02 * m1.m22;
00388         Type d3 = m.m10 * m1.m00 + m.m11 * m1.m01 + m.m12 * m1.m02;
00389         Type d4 = m.m10 * m1.m10 + m.m11 * m1.m11 + m.m12 * m1.m12;
00390         Type d5 = m.m10 * m1.m20 + m.m11 * m1.m21 + m.m12 * m1.m22;
00391         Type d6 = m.m20 * m1.m00 + m.m21 * m1.m01 + m.m22 * m1.m02;
00392         Type d7 = m.m20 * m1.m10 + m.m21 * m1.m11 + m.m22 * m1.m12;
00393         Type d8 = m.m20 * m1.m20 + m.m21 * m1.m21 + m.m22 * m1.m22;
00394         set(d0, d1, d2,
00395             d3, d4, d5,
00396             d6, d7, d8);
00397     }
00398 }
00399 
00400 template <class Type>
00401 void _Matrix3<Type>::negate(const _Matrix3<Type>& m)
00402 {
00403     set(-m.m00, -m.m01, -m.m02,
00404         -m.m10, -m.m11, -m.m12,
00405         -m.m20, -m.m21, -m.m22);
00406 }
00407 
00408 template <class Type>
00409 void _Matrix3<Type>::normalize()
00410 {
00411     double tmp_scale[9];
00412     double tmp_rot[9];
00413     getScaleRotate(tmp_scale, tmp_rot);
00414     set(tmp_rot);
00415 }
00416 
00417 template <class Type>
00418 void _Matrix3<Type>::normalize(const _Matrix3<Type>& m)
00419 {
00420     double tmp[9];
00421     double tmp_scale[9];
00422     double tmp_rot[9];
00423     m.get(tmp);
00424     compute_svd(tmp, tmp_scale, tmp_rot, false);
00425     set(tmp_rot);
00426 }
00427 
00428 template <class Type>
00429 void _Matrix3<Type>::normalizeCP(const _Matrix3<Type>& m)
00430 {
00431     Type d = sqrt(m.m00 * m.m00 + m.m10 * m.m10 + m.m20 * m.m20);
00432     m00 = m.m00 / d;
00433     m10 = m.m10 / d;
00434     m20 = m.m20 / d;
00435     d = sqrt(m.m01 * m.m01 + m.m11 * m.m11 + m.m21 * m.m21);
00436     m01 = m.m01 / d;
00437     m11 = m.m11 / d;
00438     m21 = m.m21 / d;
00439     m02 = m10 * m21 - m11 * m20;
00440     m12 = m01 * m20 - m00 * m21;
00441     m22 = m00 * m11 - m01 * m10;
00442 }
00443 
00444 template <class Type>
00445 void _Matrix3<Type>::rotX(Type angle)
00446 {
00447     Type s = sin(angle);
00448     Type c = cos(angle);
00449 
00450     set(1.0, 0.0, 0.0,
00451         0.0,   c,  -s,
00452         0.0,   s,   c);
00453 }
00454 
00455 template <class Type>
00456 void _Matrix3<Type>::rotY(Type angle)
00457 {
00458     Type s = sin(angle);
00459     Type c = cos(angle);
00460 
00461     set(c  , 0.0,   s,
00462         0.0, 1.0, 0.0,
00463         -s , 0.0,   c);
00464 }
00465 
00466 template <class Type>
00467 void _Matrix3<Type>::rotZ(Type angle)
00468 {
00469     Type s = sin(angle);
00470     Type c = cos(angle);
00471 
00472     set(c  ,  -s, 0.0,
00473         s  ,   c, 0.0,
00474         0.0, 0.0, 1.0);
00475 }
00476 
00477 template <class Type>
00478 void _Matrix3<Type>::setAxisAngle(Type x, Type y, Type z, Type angle)
00479 {
00480     Type d = sqrt(x * x + y * y + z * z);
00481 
00482     if (Math::epsilonEquals(d)) {
00483         setIdentity();
00484     } else {
00485         Type d1 = x / d;
00486         Type d2 = y / d;
00487         Type d3 = z / d;
00488         Type d4 = sin(angle);
00489         Type d5 = cos(angle);
00490         Type d6 = 1.0 - d5;
00491         Type d7 = x * z;
00492         Type d8 = x * y;
00493         Type d9 = y * z;
00494         set(d6 * d1 * d1 + d5, d6 * d8 - d4 * d3, d6 * d7 + d4 * d2,
00495             d6 * d8 + d4 * d3, d6 * d2 * d2 + d5, d6 * d9 - d4 * d1,
00496             d6 * d7 - d4 * d2, d6 * d9 + d4 * d1, d6 * d3 * d3 + d5);
00497     }
00498 }
00499 
00500 template <class Type>
00501 void _Matrix3<Type>::setQuat(Type x, Type y, Type z, Type w)
00502 {
00503     set(1.0 - 2.0 * y * y - 2.0 * z * z,
00504         2.0 * (x * y + w * z),
00505         2.0 * (x * z - w * y),
00506         2.0 * (x * y - w * z),
00507         1.0 - 2.0 * x * x - 2.0 * z * z,
00508         2.0 * (y * z + w * x),
00509         2.0 * (x * z + w * y),
00510         2.0 * (y * z - w * x),
00511         1.0 - 2.0 * x * x - 2.0 * y * y);
00512 }
00513 
00514 template <class Type>
00515 void _Matrix3<Type>::setRow(int row, Type x, Type y, Type z)
00516 {
00517     switch(row) {
00518     case 0:
00519         m00 = x;
00520         m01 = y;
00521         m02 = z;
00522         break;
00523     case 1:
00524         m10 = x;
00525         m11 = y;
00526         m12 = z;
00527         break;
00528     case 2:
00529         m20 = x;
00530         m21 = y;
00531         m22 = z;
00532         break;
00533     default:
00534         break;
00535     }
00536 }
00537 
00538 template <class Type>
00539 void _Matrix3<Type>::setRow(int row, const Type v[3])
00540 {
00541     switch(row) {
00542     case 0:
00543         m00 = v[0];
00544         m01 = v[1];
00545         m02 = v[2];
00546         break;
00547     case 1:
00548         m10 = v[0];
00549         m11 = v[1];
00550         m12 = v[2];
00551         break;
00552     case 2:
00553         m20 = v[0];
00554         m21 = v[1];
00555         m22 = v[2];
00556         break;
00557     default:
00558         break;
00559     }
00560 }
00561 
00562 template <class Type>
00563 void _Matrix3<Type>::setRow(int row, const _Vector3<Type>& v)
00564 {
00565     switch(row) {
00566     case 0:
00567         m00 = v.x;
00568         m01 = v.y;
00569         m02 = v.z;
00570         break;
00571     case 1:
00572         m10 = v.x;
00573         m11 = v.y;
00574         m12 = v.z;
00575         break;
00576     case 2:
00577         m20 = v.x;
00578         m21 = v.y;
00579         m22 = v.z;
00580         break;
00581     default:
00582         break;
00583     }
00584 }
00585 
00586 template <class Type>
00587 void _Matrix3<Type>::sub(const _Matrix3<Type>& m)
00588 {
00589     m00 -= m.m00;
00590     m01 -= m.m01;
00591     m02 -= m.m02;
00592     m10 -= m.m10;
00593     m11 -= m.m11;
00594     m12 -= m.m12;
00595     m20 -= m.m20;
00596     m21 -= m.m21;
00597     m22 -= m.m22;
00598 }
00599 
00600 template <class Type>
00601 void _Matrix3<Type>::sub(const _Matrix3<Type>& m, const _Matrix3<Type>& m1)
00602 {
00603     set(m.m00 - m1.m00, m.m01 - m1.m01, m.m02 - m1.m02,
00604         m.m10 - m1.m10, m.m11 - m1.m11, m.m12 - m1.m12,
00605         m.m20 - m1.m20, m.m21 - m1.m21, m.m22 - m1.m22);
00606 }
00607 
00608 template <class Type>
00609 void _Matrix3<Type>::transform(const _Tuple3<Type>& t, _Tuple3<Type>& t1) const
00610 {
00611     Type x = t.x, y = t.y;
00612     t1.x = m00 * x + m01 * y + m02 * t.z;
00613     t1.y = m10 * x + m11 * y + m12 * t.z;
00614     t1.z = m20 * x + m21 * y + m22 * t.z;
00615 }
00616 
00617 template <class Type>
00618 void _Matrix3<Type>::transpose(const _Matrix3<Type>& m)
00619 {
00620     if (this != &m) {
00621         set(m.m00, m.m10, m.m20,
00622             m.m01, m.m11, m.m21,
00623             m.m02, m.m12, m.m22);
00624     } else
00625         transpose();
00626 }
00627 
00628 template <class Type>
00629 std::ostream& operator <<(std::ostream& os, const _Matrix3<Type>& m)
00630 {
00631     os << "{ ";
00632     for (int i = 0; i < 9;) {
00633         double d = m.getElement(i/3, i%3);
00634         if (Math::abs(d) < m.EPS)
00635             d = 0.0;
00636         os << d;
00637         i++;
00638         if (i % 3)
00639             os << ", ";
00640         else {
00641             if (i < 9)
00642                 os << std::endl << "  ";
00643             else
00644                 os << " }" << std::endl;
00645         }
00646     }
00647     return os;
00648 }
00649 
00650 template <class Type>
00651 std::ostream& operator <<(std::ostream& os, const _Matrix3<Type>* m)
00652 {
00653     return os << *m;
00654 }
00655 
00656 template class _Matrix3<double>;
00657 template class _Matrix3<float>;
00658 template std::ostream& operator <<(std::ostream&, const _Matrix3<double>&);
00659 template std::ostream& operator <<(std::ostream&, const _Matrix3<float>&);
00660 template std::ostream& operator <<(std::ostream&, const _Matrix3<double>*);
00661 template std::ostream& operator <<(std::ostream&, const _Matrix3<float>*);
00662 

Generated on Thu Sep 29 13:39:44 2005 for vecmath by  doxygen 1.4.4