glc_matrix4x4.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 *****************************************************************************/
00022 
00024 
00025 #ifndef GLC_MATRIX4X4_H_
00026 #define GLC_MATRIX4X4_H_
00027 
00028 #include <QVector>
00029 #include "glc_vector3d.h"
00030 
00031 #include "../glc_config.h"
00032 
00035 
00040 
00041 class GLC_LIB_EXPORT GLC_Matrix4x4
00042 {
00043         friend class GLC_Vector3d;
00044 public:
00046         enum
00047         {
00048                 General= 0x0000,
00049                 Direct= 0x0001,
00050                 Indirect= 0x0002,
00051                 Identity= 0x0003
00052         };
00053 
00055 // Constructor
00057 public:
00059 
00060 
00061         inline GLC_Matrix4x4();
00062 
00064         inline GLC_Matrix4x4(const GLC_Matrix4x4 &matrix)
00065         :m_Type(matrix.m_Type)
00066         {
00067                 memcpy(m_Matrix, matrix.m_Matrix, sizeof(double) * 16);
00068         }
00069 
00071         inline GLC_Matrix4x4(const double *pArray)
00072         : m_Type(General)
00073         {
00074                 memcpy(m_Matrix, pArray, sizeof(double) * 16);
00075         }
00076 
00078         inline GLC_Matrix4x4(const float *);
00079 
00081         inline GLC_Matrix4x4(const GLC_Vector3d &Vect, const double &dAngleRad);
00082 
00084         inline GLC_Matrix4x4(const GLC_Vector3d &Vect1, const GLC_Vector3d &Vect2);
00085 
00087         inline GLC_Matrix4x4(const GLC_Vector3d &Vect)
00088         {setMatTranslate(Vect);}
00089 
00091         inline GLC_Matrix4x4(const double Tx, const double Ty, const double Tz)
00092         {setMatTranslate(Tx, Ty, Tz);}
00094 
00096 
00098 
00099 public:
00101         inline GLC_Matrix4x4& operator = (const GLC_Matrix4x4 &matrix);
00102 
00104         inline GLC_Matrix4x4 operator * (const GLC_Matrix4x4 &Mat) const;
00105 
00107         inline GLC_Vector3d operator * (const GLC_Vector3d &Vect) const;
00108 
00110         inline bool operator==(const GLC_Matrix4x4& mat) const;
00111 
00113         inline bool operator!=(const GLC_Matrix4x4& mat) const
00114         {return !operator==(mat);}
00115 
00117 
00119 
00121 
00122 public:
00124         inline double determinant(void) const;
00125 
00127 
00128         inline const double* getData(void)
00129         {return m_Matrix;}
00130 
00132         inline const double* getData(void) const
00133         {return m_Matrix;}
00134 
00136         inline double* setData(void)
00137         {
00138                 m_Type= General;
00139                 return m_Matrix;
00140         }
00141 
00143         QVector<double> toEuler(void) const;
00144 
00146         QString toString() const;
00147 
00149         inline GLC_Matrix4x4 rotationMatrix() const;
00150 
00152         inline GLC_Matrix4x4 isometricMatrix() const;
00153 
00155         inline double scalingX() const
00156         {return GLC_Vector3d(m_Matrix[0], m_Matrix[1], m_Matrix[2]).length();}
00157 
00159         inline double scalingY() const
00160         {return GLC_Vector3d(m_Matrix[4], m_Matrix[5], m_Matrix[6]).length();}
00161 
00163         inline double scalingZ() const
00164         {return GLC_Vector3d(m_Matrix[8], m_Matrix[9], m_Matrix[10]).length();}
00165 
00167         inline GLC_Matrix4x4 inverted() const
00168         {return GLC_Matrix4x4(*this).invert();}
00169 
00171         inline int type() const
00172         {
00173                 return m_Type;
00174         }
00175 
00177         inline bool isDirect() const
00178         {return (m_Type & Direct);}
00179 
00181 
00183 
00185 
00186 public:
00188         inline GLC_Matrix4x4& setMatRot(const GLC_Vector3d &, const double &);
00189 
00191         inline GLC_Matrix4x4& setMatRot(const GLC_Vector3d &, const GLC_Vector3d &);
00192 
00194         inline GLC_Matrix4x4& setMatTranslate(const GLC_Vector3d &);
00195 
00197         inline GLC_Matrix4x4& setMatTranslate(const double, const double, const double);
00198 
00200         inline GLC_Matrix4x4& setMatScaling(const double, const double, const double);
00201 
00203         inline GLC_Matrix4x4& invert(void);
00204 
00206         inline GLC_Matrix4x4& setToIdentity();
00207 
00209         inline GLC_Matrix4x4& transpose(void);
00210 
00212         GLC_Matrix4x4& fromEuler(const double, const double, const double);
00213 
00215         GLC_Matrix4x4& setColumn(int index, const GLC_Vector3d& vector);
00216 
00218         inline GLC_Matrix4x4& optimise(bool force= false);
00219 
00221 
00225 private:
00226 
00228         inline bool isInDiagonal(const int index) const
00229         {
00230                 if ((index == 0) || (index == 5) || (index == 10) || (index == 15))
00231                         return true;
00232                 else
00233                         return false;
00234         }
00235 
00237         inline double getDeterminantLC(const int, const int) const;
00238 
00240         inline void getSubMat(const int, const int, double *) const;
00241 
00243         inline GLC_Matrix4x4 getTranspose(void) const;
00244 
00246         inline GLC_Matrix4x4 getCoMat4x4(void) const;
00247 
00248 
00249 
00251 // Private members
00253 private:
00254 
00256         enum {TAILLEMAT4X4 = 16};
00257 
00259         enum {DIMMAT4X4 = 4};
00260 
00262         double m_Matrix[TAILLEMAT4X4];
00263 
00265         int m_Type;
00266 
00267 /*
00268 the matrix :
00269                                         a[00] a[04] a[08] a[12]
00270 
00271                                         a[01] a[05] a[09] a[13]
00272 
00273                                         a[02] a[06] a[10] a[14]
00274 
00275                                         a[03] a[07] a[11] a[15]
00276  */
00277 //                                      Tx = 12,        Ty = 13,        Tz = 14
00278 
00279 };
00280 
00281 
00283 // Constructor/Destructor
00285 
00286 GLC_Matrix4x4::GLC_Matrix4x4()
00287 : m_Type(Identity)
00288 {
00289         setToIdentity();
00290 }
00291 
00292 GLC_Matrix4x4::GLC_Matrix4x4(const float *Tableau)
00293 : m_Type(General)
00294 {
00295 
00296         for (int i=0; i < TAILLEMAT4X4; i++)
00297         {
00298                 m_Matrix[i]= static_cast<double>(Tableau[i]);
00299         }
00300 }
00301 GLC_Matrix4x4::GLC_Matrix4x4(const GLC_Vector3d &Vect, const double &dAngleRad)
00302 : m_Type(Direct)
00303 {
00304         setToIdentity();
00305         setMatRot(Vect, dAngleRad);
00306 }
00307 
00308 GLC_Matrix4x4::GLC_Matrix4x4(const GLC_Vector3d &Vect1, const GLC_Vector3d &Vect2)
00309 : m_Type(Direct)
00310 {
00311         setToIdentity();
00312         setMatRot(Vect1, Vect2);
00313 }
00314 
00315 GLC_Matrix4x4 GLC_Matrix4x4::operator * (const GLC_Matrix4x4 &Mat) const
00316 {
00317         if (m_Type == Identity)
00318         {
00319                 return Mat;
00320         }
00321         else if (Mat.m_Type == Identity)
00322         {
00323                 return *this;
00324         }
00325 
00326         int Colonne;
00327         int Ligne;
00328         int i;
00329         double ValInt;
00330 
00331         int IndexInt;
00332 
00333         GLC_Matrix4x4 MatResult;
00334         for (Ligne= 0; Ligne < DIMMAT4X4; Ligne++)
00335         {
00336                 for (Colonne=0; Colonne < DIMMAT4X4; Colonne++)
00337                 {
00338                         ValInt= 0.0;
00339                         IndexInt= Colonne * DIMMAT4X4;
00340 
00341                         for (i= 0; i < DIMMAT4X4; i++)
00342                         {
00343                                 ValInt+= m_Matrix[ (i * DIMMAT4X4) + Ligne] * Mat.m_Matrix[ IndexInt + i];
00344                         }
00345                         MatResult.m_Matrix[ IndexInt + Ligne]= ValInt;
00346                 }
00347         }
00348         if ((m_Type == Indirect) || (Mat.m_Type == Indirect))
00349         {
00350                 MatResult.m_Type= Indirect;
00351         }
00352         else
00353         {
00354                 MatResult.m_Type= m_Type & Mat.m_Type;
00355         }
00356 
00357         return MatResult;
00358 }
00359 
00360 GLC_Matrix4x4& GLC_Matrix4x4::operator = (const GLC_Matrix4x4 &matrix)
00361 {
00362         m_Type= matrix.m_Type;
00363         memcpy(m_Matrix, matrix.m_Matrix, sizeof(double) * 16);
00364 
00365         return *this;
00366 }
00367 
00368 GLC_Vector3d GLC_Matrix4x4::operator * (const GLC_Vector3d &Vect) const
00369 {
00370         double ValInt;
00371         int i;
00372         GLC_Vector3d VectResult;
00373         double mat[4];
00374 
00375         for (int Index= 0; Index < DIMMAT4X4; Index++)
00376         {
00377                 ValInt= 0.0;
00378                 for (i= 0; i < DIMMAT4X4 - 1; i++)
00379                 {
00380                         ValInt+= m_Matrix[(i * DIMMAT4X4) + Index] * Vect.m_Vector[i];
00381                 }
00382                 ValInt+= m_Matrix[(3 * DIMMAT4X4) + Index];
00383                 mat[Index]= ValInt;
00384         }
00385 
00386         double invW= 1.0;
00387         if (fabs(mat[3]) > 0.00001)
00388         {
00389                 invW/= mat[3];
00390         }
00391         VectResult.m_Vector[0]= mat[0] * invW;
00392         VectResult.m_Vector[1]= mat[1] * invW;
00393         VectResult.m_Vector[2]= mat[2] * invW;
00394 
00395 
00396         return VectResult;
00397 }
00398 
00399 bool GLC_Matrix4x4::operator==(const GLC_Matrix4x4& mat) const
00400 {
00401         bool result= true;
00402         int i= 0;
00403         while (result && (i < TAILLEMAT4X4))
00404         {
00405                 result= (qFuzzyCompare(m_Matrix[i], mat.m_Matrix[i]));
00406                 ++i;
00407         }
00408         return result;
00409 }
00410 
00411 GLC_Matrix4x4 GLC_Matrix4x4::rotationMatrix() const
00412 {
00413         GLC_Matrix4x4 result(*this);
00414         const double invScaleX= 1.0 / scalingX();
00415         const double invScaleY= 1.0 / scalingY();
00416         const double invScaleZ= 1.0 / scalingZ();
00417         result.m_Matrix[0]= result.m_Matrix[0] * invScaleX;
00418         result.m_Matrix[1]= result.m_Matrix[1] * invScaleX;
00419         result.m_Matrix[2]= result.m_Matrix[2] * invScaleX;
00420 
00421         result.m_Matrix[4]= result.m_Matrix[4] * invScaleY;
00422         result.m_Matrix[5]= result.m_Matrix[5] * invScaleY;
00423         result.m_Matrix[6]= result.m_Matrix[6] * invScaleY;
00424 
00425         result.m_Matrix[8]= result.m_Matrix[8] * invScaleZ;
00426         result.m_Matrix[9]= result.m_Matrix[9] * invScaleZ;
00427         result.m_Matrix[10]= result.m_Matrix[10] * invScaleZ;
00428 
00429         result.m_Matrix[12]= 0.0; result.m_Matrix[13]= 0.0; result.m_Matrix[14]= 0.0;
00430         result.m_Matrix[3]= 0.0; result.m_Matrix[7]= 0.0; result.m_Matrix[11]= 0.0;
00431         result.m_Matrix[15]= 1.0;
00432 
00433         result.m_Type= General;
00434 
00435         return result;
00436 }
00437 
00438 GLC_Matrix4x4 GLC_Matrix4x4::isometricMatrix() const
00439 {
00440         GLC_Matrix4x4 result(*this);
00441         const double invScaleX= 1.0 / scalingX();
00442         const double invScaleY= 1.0 / scalingY();
00443         const double invScaleZ= 1.0 / scalingZ();
00444         result.m_Matrix[0]= result.m_Matrix[0] * invScaleX;
00445         result.m_Matrix[1]= result.m_Matrix[1] * invScaleX;
00446         result.m_Matrix[2]= result.m_Matrix[2] * invScaleX;
00447 
00448         result.m_Matrix[4]= result.m_Matrix[4] * invScaleY;
00449         result.m_Matrix[5]= result.m_Matrix[5] * invScaleY;
00450         result.m_Matrix[6]= result.m_Matrix[6] * invScaleY;
00451 
00452         result.m_Matrix[8]= result.m_Matrix[8] * invScaleZ;
00453         result.m_Matrix[9]= result.m_Matrix[9] * invScaleZ;
00454         result.m_Matrix[10]= result.m_Matrix[10] * invScaleZ;
00455 
00456         result.m_Type= General;
00457 
00458         return result;
00459 }
00460 
00461 GLC_Matrix4x4& GLC_Matrix4x4::setMatRot(const GLC_Vector3d &Vect, const double &dAngleRad)
00462 {
00463         // Normalize the vector
00464         GLC_Vector3d VectRot(Vect);
00465         VectRot.normalize();
00466 
00467         // Code optimisation
00468         const double SinAngleSur2= sin(dAngleRad / 2.0);
00469 
00470         // Quaternion computation
00471         const double q0= cos(dAngleRad / 2);
00472         const double q1= VectRot.m_Vector[0] * SinAngleSur2;
00473         const double q2= VectRot.m_Vector[1] * SinAngleSur2;
00474         const double q3= VectRot.m_Vector[2] * SinAngleSur2;
00475 
00476         // Code optimisation
00477         const double q0Carre= (q0 * q0);
00478         const double q1Carre= (q1 * q1);
00479         const double q2Carre= (q2 * q2);
00480         const double q3Carre= (q3 * q3);
00481 
00482         m_Matrix[0]= q0Carre + q1Carre - q2Carre - q3Carre;
00483         m_Matrix[1]= 2.0 * (q1 *q2 + q0 * q3);
00484         m_Matrix[2]= 2.0 * (q1 * q3 - q0 * q2);
00485         m_Matrix[3]= 0.0;
00486         m_Matrix[4]= 2.0 * (q1 * q2 - q0 * q3);
00487         m_Matrix[5]= q0Carre + q2Carre - q3Carre - q1Carre;
00488         m_Matrix[6]= 2.0 * (q2 * q3 + q0 * q1);
00489         m_Matrix[7]= 0.0;
00490         m_Matrix[8]= 2.0 * (q1 * q3 + q0 * q2);
00491         m_Matrix[9]= 2.0 * (q2 * q3 - q0 * q1);
00492         m_Matrix[10]= q0Carre + q3Carre - q1Carre - q2Carre;
00493         m_Matrix[11]= 0.0;
00494 
00495         m_Matrix[12]= 0.0;      //TX
00496         m_Matrix[13]= 0.0;      //TY
00497         m_Matrix[14]= 0.0;      //TZ
00498         m_Matrix[15]= 1.0;
00499 
00500         m_Type= Direct;
00501 
00502         return *this;
00503 }
00504 
00505 GLC_Matrix4x4& GLC_Matrix4x4::setMatRot(const GLC_Vector3d &Vect1, const GLC_Vector3d &Vect2)
00506 {
00507 
00508         // Compute rotation matrix
00509         const GLC_Vector3d VectAxeRot(Vect1 ^ Vect2);
00510         // Check if rotation vector axis is not null
00511         if (!VectAxeRot.isNull())
00512         {  // Ok, vector not null
00513                 const double Angle= acos(Vect1 * Vect2);
00514                 setMatRot(VectAxeRot, Angle);
00515         }
00516 
00517         return *this;
00518 }
00519 
00520 GLC_Matrix4x4& GLC_Matrix4x4::setMatTranslate(const GLC_Vector3d &Vect)
00521 {
00522         m_Matrix[0]= 1.0; m_Matrix[4]= 0.0; m_Matrix[8]=  0.0; m_Matrix[12]= Vect.m_Vector[0];
00523         m_Matrix[1]= 0.0; m_Matrix[5]= 1.0; m_Matrix[9]=  0.0; m_Matrix[13]= Vect.m_Vector[1];
00524         m_Matrix[2]= 0.0; m_Matrix[6]= 0.0; m_Matrix[10]= 1.0; m_Matrix[14]= Vect.m_Vector[2];
00525         m_Matrix[3]= 0.0; m_Matrix[7]= 0.0; m_Matrix[11]= 0.0; m_Matrix[15]= 1.0;
00526 
00527         m_Type= Direct;
00528 
00529         return *this;
00530 }
00531 
00532 GLC_Matrix4x4& GLC_Matrix4x4::setMatTranslate(const double Tx, const double Ty, const double Tz)
00533 {
00534         m_Matrix[0]= 1.0; m_Matrix[4]= 0.0; m_Matrix[8]=  0.0; m_Matrix[12]= Tx;
00535         m_Matrix[1]= 0.0; m_Matrix[5]= 1.0; m_Matrix[9]=  0.0; m_Matrix[13]= Ty;
00536         m_Matrix[2]= 0.0; m_Matrix[6]= 0.0; m_Matrix[10]= 1.0; m_Matrix[14]= Tz;
00537         m_Matrix[3]= 0.0; m_Matrix[7]= 0.0; m_Matrix[11]= 0.0; m_Matrix[15]= 1.0;
00538 
00539         m_Type= Direct;
00540 
00541         return *this;
00542 }
00543 
00544 GLC_Matrix4x4& GLC_Matrix4x4::setMatScaling(const double sX, const double sY, const double sZ)
00545 {
00546         m_Matrix[0]= sX; m_Matrix[4]= 0.0; m_Matrix[8]=  0.0; m_Matrix[12]= 0.0;
00547         m_Matrix[1]= 0.0; m_Matrix[5]= sY; m_Matrix[9]=  0.0; m_Matrix[13]= 0.0;
00548         m_Matrix[2]= 0.0; m_Matrix[6]= 0.0; m_Matrix[10]= sZ; m_Matrix[14]= 0.0;
00549         m_Matrix[3]= 0.0; m_Matrix[7]= 0.0; m_Matrix[11]= 0.0; m_Matrix[15]= 1.0;
00550 
00551         m_Type= General;
00552 
00553         return *this;
00554 }
00555 
00556 
00557 GLC_Matrix4x4& GLC_Matrix4x4::invert(void)
00558 {
00559         const double det= determinant();
00560 
00561         // Test if the inverion is possible
00562         if (det == 0.0f) return *this;
00563 
00564         const double invDet = 1.0 / det;
00565         GLC_Matrix4x4 TCoMat= getCoMat4x4().getTranspose();
00566 
00567         for (int i= 0; i < TAILLEMAT4X4; i++)
00568         {
00569                 m_Matrix[i]= TCoMat.m_Matrix[i] * invDet;
00570         }
00571 
00572         return *this;
00573 }
00574 
00575 GLC_Matrix4x4& GLC_Matrix4x4::setToIdentity()
00576 {
00577         m_Matrix[0]= 1.0; m_Matrix[4]= 0.0; m_Matrix[8]=  0.0; m_Matrix[12]= 0.0;
00578         m_Matrix[1]= 0.0; m_Matrix[5]= 1.0; m_Matrix[9]=  0.0; m_Matrix[13]= 0.0;
00579         m_Matrix[2]= 0.0; m_Matrix[6]= 0.0; m_Matrix[10]= 1.0; m_Matrix[14]= 0.0;
00580         m_Matrix[3]= 0.0; m_Matrix[7]= 0.0; m_Matrix[11]= 0.0; m_Matrix[15]= 1.0;
00581 
00582         m_Type= Identity;
00583 
00584         return *this;
00585 }
00586 
00587 GLC_Matrix4x4& GLC_Matrix4x4::transpose(void)
00588 {
00589         GLC_Matrix4x4 MatT(m_Matrix);
00590         int IndexOrigine;
00591         int IndexTrans;
00592         for (int Colonne= 0; Colonne < DIMMAT4X4; Colonne++)
00593         {
00594                 for (int Ligne=0 ; Ligne < DIMMAT4X4; Ligne++)
00595                 {
00596                         IndexOrigine= (Colonne * DIMMAT4X4) + Ligne;
00597                         IndexTrans= (Ligne * DIMMAT4X4) + Colonne;
00598 
00599                         MatT.m_Matrix[IndexTrans]= m_Matrix[IndexOrigine];
00600                 }
00601         }
00602 
00603         // Load the transposed matrix in this matrix
00604         memcpy(m_Matrix, MatT.m_Matrix, sizeof(double) * 16);
00605 
00606         return *this;
00607 }
00608 
00609 GLC_Matrix4x4& GLC_Matrix4x4::optimise(bool force)
00610 {
00611         if (force || (m_Type == General))
00612         {
00613                 bool identityVal= (m_Matrix[0] == 1.0f) && (m_Matrix[4] == 0.0f) && (m_Matrix[8] ==  0.0f) && (m_Matrix[12] == 0.0f);
00614                 identityVal= identityVal && (m_Matrix[1] == 0.0f) && (m_Matrix[5] == 1.0f) && (m_Matrix[9] ==  0.0f) && (m_Matrix[13] == 0.0);
00615                 identityVal= identityVal && (m_Matrix[2] == 0.0f) && (m_Matrix[6] == 0.0f) && (m_Matrix[10] == 1.0f) && (m_Matrix[14] == 0.0);
00616                 identityVal= identityVal && (m_Matrix[3] == 0.0f) && (m_Matrix[7] == 0.0f) && (m_Matrix[11] == 0.0f) && (m_Matrix[15] == 1.0f);
00617                 if (identityVal)
00618                 {
00619                         m_Type= Identity;
00620                 }
00621                 else
00622                 {
00623                         if (determinant() > 0)
00624                         {
00625                                 m_Type= Direct;
00626                         }
00627                         else
00628                         {
00629                                 m_Type= Indirect;
00630                         }
00631                 }
00632         }
00633         return *this;
00634 }
00635 
00636 double GLC_Matrix4x4::determinant(void) const
00637 {
00638         double Determinant= 0.0;
00639         double SubMat3x3[9];
00640         int Signe= 1;
00641 
00642         for (int Colonne= 0; Colonne < DIMMAT4X4; Colonne++, Signe*= -1)
00643         {
00644                 getSubMat(0, Colonne, SubMat3x3);
00645                 Determinant+= Signe * m_Matrix[Colonne * DIMMAT4X4] * getDeterminant3x3(SubMat3x3);
00646         }
00647 
00648         return Determinant;
00649 
00650 }
00651 
00652 double GLC_Matrix4x4::getDeterminantLC(const int Ligne, const int Colonne) const
00653 {
00654         double Mat3x3[9];
00655         double Determinant;
00656 
00657         getSubMat(Ligne, Colonne, Mat3x3);
00658 
00659         if ( 0 == ((Ligne + Colonne) % 2)) // Even number
00660                 Determinant= m_Matrix[(Colonne + DIMMAT4X4) + Ligne] * getDeterminant3x3(Mat3x3);
00661         else
00662                 Determinant= - m_Matrix[(Colonne + DIMMAT4X4) + Ligne] * getDeterminant3x3(Mat3x3);
00663 
00664         return Determinant;
00665 }
00666 
00667 void GLC_Matrix4x4::getSubMat(const int Ligne, const int Colonne, double *ResultMat) const
00668 {
00669 
00670         int LigneResult;
00671         int ColonneResult;
00672         int IndexOrigine;
00673         int IndexResult;
00674 
00675         for (int ColonneOrigine= 0; ColonneOrigine < DIMMAT4X4; ColonneOrigine++)
00676         {
00677                 if (ColonneOrigine != Colonne)
00678                 {
00679                         if (ColonneOrigine < Colonne)
00680                                 ColonneResult= ColonneOrigine;
00681                         else
00682                                 ColonneResult= ColonneOrigine - 1;
00683 
00684                         for (int LigneOrigine= 0; LigneOrigine < DIMMAT4X4; LigneOrigine++)
00685                         {
00686                                 if (LigneOrigine != Ligne)
00687                                 {
00688                                         if (LigneOrigine < Ligne)
00689                                                 LigneResult= LigneOrigine;
00690                                         else
00691                                                 LigneResult= LigneOrigine - 1;
00692                                         IndexOrigine= (ColonneOrigine * DIMMAT4X4) + LigneOrigine;
00693                                         IndexResult= (ColonneResult * (DIMMAT4X4 - 1)) + LigneResult;
00694 
00695                                         ResultMat[IndexResult]= m_Matrix[IndexOrigine];
00696                                 }
00697                         }
00698                 }
00699         }
00700 }
00701 
00702 GLC_Matrix4x4 GLC_Matrix4x4::getTranspose(void) const
00703 {
00704         GLC_Matrix4x4 MatT(m_Matrix);
00705         int IndexOrigine;
00706         int IndexTrans;
00707         for (int Colonne= 0; Colonne < DIMMAT4X4; Colonne++)
00708         {
00709                 for (int Ligne=0 ; Ligne < DIMMAT4X4; Ligne++)
00710                 {
00711                         IndexOrigine= (Colonne * DIMMAT4X4) + Ligne;
00712                         IndexTrans= (Ligne * DIMMAT4X4) + Colonne;
00713 
00714                         MatT.m_Matrix[IndexTrans]= m_Matrix[IndexOrigine];
00715                 }
00716         }
00717 
00718         MatT.m_Type= m_Type;
00719         return MatT;
00720 }
00721 
00722 GLC_Matrix4x4 GLC_Matrix4x4::getCoMat4x4(void) const
00723 {
00724         GLC_Matrix4x4 CoMat(m_Matrix);
00725         double SubMat3x3[9];
00726         int Index;
00727 
00728         for (int Colonne= 0; Colonne < DIMMAT4X4; Colonne++)
00729         {
00730                 for (int Ligne=0 ; Ligne < DIMMAT4X4; Ligne++)
00731                 {
00732                         getSubMat(Ligne, Colonne, SubMat3x3);
00733                         Index= (Colonne * DIMMAT4X4) + Ligne;
00734                         if (((Colonne + Ligne + 2) % 2) == 0) // Even Number
00735                                 CoMat.m_Matrix[Index]= getDeterminant3x3(SubMat3x3);
00736                         else
00737                                 CoMat.m_Matrix[Index]= -getDeterminant3x3(SubMat3x3);
00738                 }
00739         }
00740 
00741 
00742         CoMat.m_Type= General;
00743         return CoMat;
00744 }
00745 
00746 
00747 #endif /*GLC_MATRIX4X4_H_*/

SourceForge.net Logo

©2005-2011 Laurent Ribon