K3dMatrix.h

Go to the documentation of this file.
00001 
00012 /***************************************************************************
00013  *   Copyright (C) 2007 by Jan Koci   *
00014  *   honza.koci@email.cz   *
00015  *   http://kengine.sourceforge.net/tutorial/
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  *   This program is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00025  *   GNU General Public License for more details.                          *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU General Public License     *
00028  *   along with this program; if not, write to the                         *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00031  ***************************************************************************/
00032 
00033 #pragma once
00034 
00035 #include "K3dVector3.h"
00036 #include "K3dVector4.h"
00037 
00038 
00039 class K3dMatrix: public K3dString
00040 {
00041                 // 4x4 matrix array
00042 
00043                 // Standard matrix:
00044                 // |0,   1,  2  ,3|
00045                 // |4,   5,  6  ,7|
00046                 // |8,   9, 10 ,11|
00047                 // |12, 13, 14 ,15|
00048 
00049                 // OpenGL matrix:
00050                 // |0, 4,  8  ,12|
00051                 // |1, 5,  9  ,13|
00052                 // |2, 6, 10  ,14|
00053                 // |3, 7, 11  ,15|
00054 
00055                 float m_afMatrix[16];           
00056                 int m_iId;                              
00057         public:
00058                 K3dMatrix();
00059                 K3dMatrix ( const float afMatrix[16] ); // Constructor
00060                 ~K3dMatrix();
00061 
00063                 int &GetId()
00064                 {
00065                         return m_iId;
00066                 }
00067                 // Reset matrix
00068                 void LoadIdentity();
00069                 // Reset roation matrix
00070                 void ResetRotation();
00071                 // Reset translation matrix
00072                 void ResetTranslation();
00073                 // Set matrix from array
00074                 // Get or set current matrix array
00075                 float *Matrix();
00076                 const float *Matrix() const;
00077 
00078                 // Get current matrix array
00079                 float *GetMatrix()
00080                 {
00081                         return m_afMatrix;
00082                 }
00083 
00084                 void SetMatrix ( const float *_pfMatrix, const int _iSize=16 );
00085                 void SetMatrix ( const K3dMatrix &_rkMatrix, const int _iSize=16 );
00086                 void SetRow ( const K3dVector4 &_rkRow, const int _iRow );
00087                 void SetColumn ( const K3dVector4 &_rkColumn, const int _iRow );
00088                 void GetRow ( K3dVector4 &_rkRow, const int _iRow );
00089                 void GetColumn ( K3dVector4 &_rkColumn, const int _iColumn );
00090                 // Overloaded operator[] allows set matrix arrays
00091                 float &operator[] ( int index ) ;
00092                 // Overloaded operator() allow set ant get row and col value
00093                 float operator() ( int iRow, int iCol ) const;
00094                 float& operator() ( int iRow, int iCol );
00095 
00096                 // Assignment
00097                 K3dMatrix& operator= ( const K3dMatrix &_rkM );
00098 
00100                 // Comparison
00102                 bool operator== ( K3dMatrix& rkM );
00103                 bool operator!= ( K3dMatrix& rkM ) ;
00104                 bool operator< ( K3dMatrix& rkM );
00105                 bool operator<= ( K3dMatrix& rkM );
00106                 bool operator> ( K3dMatrix& rkM );
00107                 bool operator>= ( K3dMatrix& rkM );
00108                 // Compare arrays for comparison operators
00109                 int CompareArrays ( K3dMatrix& rkV );
00110 
00112                 // Arithmetic operations
00114                 K3dMatrix operator+ ( K3dMatrix& rkM );
00115                 K3dMatrix operator- ( K3dMatrix& rkM );
00116                 K3dMatrix operator* ( K3dMatrix &rkMatrix ) ;
00117                 K3dMatrix operator* ( float fScalar );
00118                 K3dMatrix operator* ( const float afMatrix[16] );
00119                 K3dVector3 operator* ( K3dVector3& rkV );
00120                 K3dMatrix operator- ();
00121 
00123                 // Arithmetic updates
00125                 K3dMatrix& operator+= ( K3dMatrix& rkM );
00126                 K3dMatrix& operator-= ( K3dMatrix& rkM );
00127                 K3dMatrix& operator*= ( float fScalar );
00128                 K3dMatrix& operator/= ( float fScalar );
00129 
00130 
00132                 // Functions
00134 
00135                 void Multiply ( K3dMatrix& _rkMat );
00136                 // Multiply transpse (OpenGL matrix)
00137                 void MultiplyTranspose ( K3dMatrix& _rkMat );
00138                 // Multiply row by scalar
00139                 void MultiplyRow ( const float fScalar, const int iRow );
00140                 // Multiply column by scalar
00141                 void MultiplyColumn ( const float fScalar, const int iColumn );
00142                 // Add row to another iRow1 = iRow1 + iRow2
00143                 void AddRow ( const int iRow1, const int iRow2 );
00144                 // Set translation matrix
00145                 void Translation ( const float *translation );
00146                 // Set translation matrix from vector
00147                 void Translation ( const K3dVector3& _rkVector );
00148                 // Set inverse translation matrix from vector
00149                 void InverseTranslation ( const K3dVector3 &_rkVector );
00150 
00151                 // Calculate rotation matrix
00152                 void Rotation ( K3dVector3 &_rkAngle );
00153                 // Calculate rotation matrix
00154                 void Rotation ( const float *pfAngle );
00155                 // Set inverse rotation matrix
00156                 void InverseRotation ( K3dVector3 &_rkAngle );
00157                 // Set inverse rotation matrix
00158                 void InverseRotation ( const float *pfAngle );
00159                 // Calculate X rotation matrix
00160                 void RotationX ( const float fAngle );
00161                 void RotationXGL ( const float _fAngle );
00162                 // Calculate Y rotation matrix
00163                 void RotationY ( const float fAngle );
00164                 void RotationYGL ( const float _fAngle );
00165                 // Calculate Z rotation matrix
00166                 void RotationZ ( const float fAngle );
00167                 void RotationZGL ( const float _fAngle );
00168                 // Set scale matrix
00169                 void Scale ( K3dVector3 &_rkVector );
00170                 // Get vector from matrix
00171                 void GetVector ( K3dVector3 &_rkVector );
00172                 // Get vector from matrix
00173                 //K3dVector3 *GetVector();
00174                 // Get scalar index by row and column
00175                 int GetScalarIndex ( const int iRow, const int iCol );
00176                 //      Change vector by matrix only rotation
00177                 void ChangeVector ( K3dVector3& _rkVec );
00178                 //      Change vector by matrix with tranform
00179                 void ChangeVectorTran ( K3dVector3& _rkVec );
00180                 //      Translate vector by matrix
00181                 void TranslateVector ( K3dVector3& _rkVec );
00182                 //      Change GL vector by matrix
00183                 void ChangeVectorGL ( K3dVector3& _rkVec );
00184                 //      Change X vector coordination by matrix
00185                 void ChangeVectorX ( K3dVector3& _rkVec );
00186                 void ChangeVectorXGL ( K3dVector3& _rkVec );
00187                 //      Change Y vector coordination by matrix
00188                 void ChangeVectorY ( K3dVector3& _rkVec );
00189                 void ChangeVectorYGL ( K3dVector3& _rkVec );
00190                 //      Change Z vector coordination by matrix
00191                 void ChangeVectorZ ( K3dVector3& _rkVec );
00192                 void ChangeVectorZGL ( K3dVector3& _rkVec );
00193                 // Calculate determinant
00194                 float Determinant();
00195                 // Inverse matrix
00196                 void Inverse();
00197                 // Inverse opengl matrix
00198                 void InverseGL();
00199                 // Flip rows to column (normal matrix to OpenGL or again)
00200                 void FlipRowToColumn ( const K3dMatrix &_rkMatrix );
00201                 // Rotation through an angle about an arbitrary axis
00202                 void Rotation ( const K3dVector3 &_rkAxis  ,const float fAngle );
00203                 // GL rotation through an angle about an arbitrary axis
00204                 void RotationGL ( const K3dVector3 &_rkAxis  ,const float fAngle );
00205                 // Calculate linear system of three equations
00206                 K3dVector3 LinearSystem ( const K3dVector4 &_rkEq1,const K3dVector4 &_rkEq2, const K3dVector4 &_rkEq3 );
00207                 // Change standrard matrix to the OpenGL matrix
00208                 void ToOrFromGL();
00209                 // Multiply matrix and vector
00210                 // dst = M * src
00211                 void MultMatrixVec ( const K3dVector3 &_rkSrc, K3dVector3 &rkDst );
00212                 void MultMatrixVec ( K3dVector3 & rkSrcAndDst );
00213                 // Multiply vector and matrix
00214                 // dst = src * M
00215                 void MultVecMatrix ( const K3dVector3 &rkSrc, K3dVector3 &rkDst );
00216                 void MultVecMatrix ( K3dVector3 & rkSrcAndDst );
00217                 // Multiply directional matrix and vector
00218                 // dst = M * src
00219                 void MultMatrixDir ( const K3dVector3 &rkSrc, K3dVector3 &rkDst );
00220                 void MultMatrixDir ( K3dVector3 & rkSrcAndDst );
00221                 // Multiply vector and directional matrix
00222                 // dst = src * M
00223                 void MultDirMatrix ( const K3dVector3 &rkSrc, K3dVector3 &rkDst );
00224                 void MultDirMatrix ( K3dVector3 & rkSrcAndDst );
00227                 void GetTranslation ( K3dVector3 &_rkTranslation )
00228                 {
00229                         _rkTranslation[0] = m_afMatrix[12];
00230                         _rkTranslation[1] = m_afMatrix[13];
00231                         _rkTranslation[2] = m_afMatrix[14];
00232                 }
00233 };
00234 
00235 
00236 
00237 // Get or set current matrix array
00238 inline float *K3dMatrix::Matrix()
00239 {
00240         return m_afMatrix;
00241 }
00242 inline const float *K3dMatrix::Matrix() const
00243 {
00244         return m_afMatrix;
00245 }
00246 
00247 
00248 
00249 // Overloaded operator[] allows set matrix arrays
00250 inline float &K3dMatrix::operator[] ( int i )
00251 {
00252         if ( ! ( 0 <= i ) && ( i < 16 ) )
00253         {
00254                 cerr  << "Error :: K3dMatrix::operator[] -- wrong index " << i << endl;
00255         }
00256         return m_afMatrix[i];
00257 }
00258 
00259 
00260 
00261 // Overloaded operator() allow set ant get row and col value
00262 inline float K3dMatrix::operator() ( int iRow, int iCol ) const
00263 {
00264         if ( ( iRow==0 ) && ( iCol==0 ) ) return m_afMatrix[0];
00265         if ( ( iRow==0 ) && ( iCol==1 ) ) return m_afMatrix[1];
00266         if ( ( iRow==0 ) && ( iCol==2 ) ) return m_afMatrix[2];
00267         if ( ( iRow==0 ) && ( iCol==3 ) ) return m_afMatrix[3];
00268         if ( ( iRow==1 ) && ( iCol==0 ) ) return m_afMatrix[4];
00269         if ( ( iRow==1 ) && ( iCol==1 ) ) return m_afMatrix[5];
00270         if ( ( iRow==1 ) && ( iCol==2 ) ) return m_afMatrix[6];
00271         if ( ( iRow==1 ) && ( iCol==3 ) ) return m_afMatrix[7];
00272         if ( ( iRow==2 ) && ( iCol==0 ) ) return m_afMatrix[8];
00273         if ( ( iRow==2 ) && ( iCol==1 ) ) return m_afMatrix[9];
00274         if ( ( iRow==2 ) && ( iCol==2 ) ) return m_afMatrix[10];
00275         if ( ( iRow==2 ) && ( iCol==3 ) ) return m_afMatrix[11];
00276         if ( ( iRow==3 ) && ( iCol==0 ) ) return m_afMatrix[12];
00277         if ( ( iRow==3 ) && ( iCol==1 ) ) return m_afMatrix[13];
00278         if ( ( iRow==3 ) && ( iCol==2 ) ) return m_afMatrix[14];
00279         if ( ( iRow==3 ) && ( iCol==3 ) ) return m_afMatrix[15];
00280 
00281         return m_afMatrix[0];
00282 }
00283 
00284 
00285 
00286 inline float &K3dMatrix::operator() ( int iRow, int iCol )
00287 {
00288         int iIndex = GetScalarIndex ( iRow, iCol );
00289         return m_afMatrix[iIndex];
00290 }
00291 
00292 
00293 
00294 // Reset matrix
00295 inline void K3dMatrix::LoadIdentity()
00296 {
00297         m_afMatrix[0] = 1;      m_afMatrix[4] = 0;      m_afMatrix[8]  = 0;     m_afMatrix[12] = 0;
00298         m_afMatrix[1] = 0;      m_afMatrix[5] = 1;      m_afMatrix[9]  = 0;     m_afMatrix[13] = 0;
00299         m_afMatrix[2] = 0;      m_afMatrix[6] = 0;      m_afMatrix[10] = 1;     m_afMatrix[14] = 0;
00300         m_afMatrix[3] = 0;      m_afMatrix[7] = 0;      m_afMatrix[11] = 0;     m_afMatrix[15] = 1;
00301 }
00302 
00303 
00304 
00305 // Reset roation matrix
00306 inline void K3dMatrix::ResetRotation()
00307 {
00308         m_afMatrix[0] = 1;      m_afMatrix[4] = 0;      m_afMatrix[8]  = 0;
00309         m_afMatrix[1] = 0;      m_afMatrix[5] = 1;      m_afMatrix[9]  = 0;
00310         m_afMatrix[2] = 0;      m_afMatrix[6] = 0;      m_afMatrix[10] = 1;
00311         m_afMatrix[3] = 0;      m_afMatrix[7] = 0;      m_afMatrix[11] = 0;
00312 }
00313 
00314 
00315 
00316 // Reset translation matrix
00317 inline void K3dMatrix::ResetTranslation()
00318 {
00319         m_afMatrix[12] = 0;
00320         m_afMatrix[13] = 0;
00321         m_afMatrix[14] = 0;
00322         m_afMatrix[15] = 1;
00323 }
00324 
00325 
00326 
00327 inline bool K3dMatrix::operator== ( K3dMatrix& rkM )
00328 {
00329         return memcmp ( m_afMatrix, rkM.m_afMatrix, 16*sizeof ( float ) ) == 0;
00330 }
00331 
00332 
00333 
00334 inline bool K3dMatrix::operator!= ( K3dMatrix& rkM )
00335 {
00336         return memcmp ( m_afMatrix, rkM.m_afMatrix, 16*sizeof ( float ) ) != 0;
00337 }
00338 
00339 
00340 
00341 inline bool K3dMatrix::operator< ( K3dMatrix& rkM )
00342 {
00343         return CompareArrays ( rkM ) < 0;
00344 }
00345 
00346 
00347 
00348 inline bool K3dMatrix::operator<= ( K3dMatrix& rkM )
00349 {
00350         return CompareArrays ( rkM ) <= 0;
00351 }
00352 
00353 
00354 
00355 inline bool K3dMatrix::operator> ( K3dMatrix& rkM )
00356 {
00357         return CompareArrays ( rkM ) > 0;
00358 }
00359 
00360 
00361 
00362 inline bool K3dMatrix::operator>= ( K3dMatrix& rkM )
00363 {
00364         return CompareArrays ( rkM ) >= 0;
00365 }
00366 
00367 
00368 
00369 inline K3dMatrix K3dMatrix::operator* ( K3dMatrix &rkMatrix )
00370 {
00371 
00372         float afMatrix[16];
00373         const float *m1 = m_afMatrix, *m2 = rkMatrix.m_afMatrix;
00374 
00375         afMatrix[0] = ( float ) ( m1[0] * m2[0] )  + ( m1[4] * m2[1] )  + ( m1[8]  * m2[2] );
00376         afMatrix[1] = ( float ) ( m1[1] * m2[0] )  + ( m1[5] * m2[1] )  + ( m1[9]  * m2[2] );
00377         afMatrix[2] = ( float ) ( m1[2] * m2[0] )  + ( m1[6] * m2[1] )  + ( m1[10] * m2[2] );
00378         afMatrix[3] = 0;
00379 
00380         afMatrix[4] = ( float ) ( m1[0] * m2[4] )  + ( m1[4] * m2[5] )  + ( m1[8]  * m2[6] );
00381         afMatrix[5] = ( float ) ( m1[1] * m2[4] )  + ( m1[5] * m2[5] )  + ( m1[9]  * m2[6] );
00382         afMatrix[6] = ( float ) ( m1[2] * m2[4] )  + ( m1[6] * m2[5] )  + ( m1[10] * m2[6] );
00383         afMatrix[7] = 0;
00384 
00385         afMatrix[8] = ( float ) ( m1[0] * m2[8] )  + ( m1[4] * m2[9] )  + ( m1[8]  * m2[10] );
00386         afMatrix[9] = ( float ) ( m1[1] * m2[8] )  + ( m1[5] * m2[9] )  + ( m1[9]  * m2[10] );
00387         afMatrix[10] = ( float ) ( m1[2] * m2[8] )  + ( m1[6] * m2[9] )  + ( m1[10] * m2[10] );
00388         afMatrix[11] = 0;
00389 
00390         afMatrix[12] = ( float ) ( m1[0] * m2[12] ) + ( m1[4] * m2[13] ) + ( m1[8]  * m2[14] ) + m1[12];
00391         afMatrix[13] = ( float ) ( m1[1] * m2[12] ) + ( m1[5] * m2[13] ) + ( m1[9]  * m2[14] ) + m1[13];
00392         afMatrix[14] = ( float ) ( m1[2] * m2[12] ) + ( m1[6] * m2[13] ) + ( m1[10] * m2[14] ) + m1[14];
00393         afMatrix[15] = 1;
00394 
00395         SetMatrix ( afMatrix );
00396         return *this;
00397 }
00398 
00399 
00400 
00401 inline K3dMatrix K3dMatrix::operator* ( const float afMatrix[16] )
00402 {
00403         float afNewMatrix[16];
00404         const float *m1 = m_afMatrix, *m2 = afMatrix;
00405 
00406         afNewMatrix[0] = ( float ) ( m1[0] * m2[0] )  + ( m1[4] * m2[1] )  + ( m1[8]  * m2[2] );
00407         afNewMatrix[1] = ( float ) ( m1[1] * m2[0] )  + ( m1[5] * m2[1] )  + ( m1[9]  * m2[2] );
00408         afNewMatrix[2] = ( float ) ( m1[2] * m2[0] )  + ( m1[6] * m2[1] )  + ( m1[10] * m2[2] );
00409         afNewMatrix[3] = 0;
00410 
00411         afNewMatrix[4] = ( float ) ( m1[0] * m2[4] )  + ( m1[4] * m2[5] )  + ( m1[8]  * m2[6] );
00412         afNewMatrix[5] = ( float ) ( m1[1] * m2[4] )  + ( m1[5] * m2[5] )  + ( m1[9]  * m2[6] );
00413         afNewMatrix[6] = ( float ) ( m1[2] * m2[4] )  + ( m1[6] * m2[5] )  + ( m1[10] * m2[6] );
00414         afNewMatrix[7] = 0;
00415 
00416         afNewMatrix[8] = ( float ) ( m1[0] * m2[8] )  + ( m1[4] * m2[9] )  + ( m1[8]  * m2[10] );
00417         afNewMatrix[9] = ( float ) ( m1[1] * m2[8] )  + ( m1[5] * m2[9] )  + ( m1[9]  * m2[10] );
00418         afNewMatrix[10] = ( float ) ( m1[2] * m2[8] )  + ( m1[6] * m2[9] )  + ( m1[10] * m2[10] );
00419         afNewMatrix[11] = 0;
00420 
00421         afNewMatrix[12] = ( float ) ( m1[0] * m2[12] ) + ( m1[4] * m2[13] ) + ( m1[8]  * m2[14] ) + m1[12];
00422         afNewMatrix[13] = ( float ) ( m1[1] * m2[12] ) + ( m1[5] * m2[13] ) + ( m1[9]  * m2[14] ) + m1[13];
00423         afNewMatrix[14] = ( float ) ( m1[2] * m2[12] ) + ( m1[6] * m2[13] ) + ( m1[10] * m2[14] ) + m1[14];
00424         afNewMatrix[15] = 1;
00425 
00426 
00427 
00428         SetMatrix ( afNewMatrix );
00429 
00430         return *this;
00431 }
00432 
00433 
00434 
00435 inline K3dVector3 K3dMatrix::operator* ( K3dVector3& rkV )
00436 {
00437         K3dVector3 kVec = rkV;
00438         this->ChangeVector ( kVec );
00439         return kVec;
00440 }
00441 
00442 
00443 
00445 inline void K3dMatrix::Multiply ( K3dMatrix& _rkMat )
00446 {
00447         float afMatrix[16];
00448         const float *m1 = m_afMatrix, *m2 = _rkMat.m_afMatrix;
00449 
00450         afMatrix[0] = ( float ) ( m1[0] * m2[0] )  + ( m1[4] * m2[1] )  + ( m1[8]  * m2[2] );
00451         afMatrix[1] = ( float ) ( m1[1] * m2[0] )  + ( m1[5] * m2[1] )  + ( m1[9]  * m2[2] );
00452         afMatrix[2] = ( float ) ( m1[2] * m2[0] )  + ( m1[6] * m2[1] )  + ( m1[10] * m2[2] );
00453         afMatrix[3] = 0;
00454 
00455         afMatrix[4] = ( float ) ( m1[0] * m2[4] )  + ( m1[4] * m2[5] )  + ( m1[8]  * m2[6] );
00456         afMatrix[5] = ( float ) ( m1[1] * m2[4] )  + ( m1[5] * m2[5] )  + ( m1[9]  * m2[6] );
00457         afMatrix[6] = ( float ) ( m1[2] * m2[4] )  + ( m1[6] * m2[5] )  + ( m1[10] * m2[6] );
00458         afMatrix[7] = 0;
00459 
00460         afMatrix[8] = ( float ) ( m1[0] * m2[8] )  + ( m1[4] * m2[9] )  + ( m1[8]  * m2[10] );
00461         afMatrix[9] = ( float ) ( m1[1] * m2[8] )  + ( m1[5] * m2[9] )  + ( m1[9]  * m2[10] );
00462         afMatrix[10] = ( float ) ( m1[2] * m2[8] )  + ( m1[6] * m2[9] )  + ( m1[10] * m2[10] );
00463         afMatrix[11] = 0;
00464 
00465         afMatrix[12] = ( float ) ( m1[0] * m2[12] ) + ( m1[4] * m2[13] ) + ( m1[8]  * m2[14] ) + m1[12];
00466         afMatrix[13] = ( float ) ( m1[1] * m2[12] ) + ( m1[5] * m2[13] ) + ( m1[9]  * m2[14] ) + m1[13];
00467         afMatrix[14] = ( float ) ( m1[2] * m2[12] ) + ( m1[6] * m2[13] ) + ( m1[10] * m2[14] ) + m1[14];
00468         afMatrix[15] = 1;
00469 
00470         SetMatrix ( afMatrix );
00471 }
00472 
00473 
00474 
00476 inline void K3dMatrix::MultiplyTranspose ( K3dMatrix& _rkMat )
00477 {
00478         float afMatrix[16];
00479         const float *m1 = m_afMatrix, *m2 = _rkMat.m_afMatrix;
00480 
00481         afMatrix[0]  = ( float ) ( m1[0] * m2[0] ) + ( m1[1] * m2[4] ) + ( m1[2] * m2[8] );
00482         afMatrix[1]  = ( float ) ( m1[0] * m2[1] ) + ( m1[1] * m2[5] ) + ( m1[2] * m2[9] );
00483         afMatrix[2]  = ( float ) ( m1[0] * m2[2] ) + ( m1[1] * m2[6] ) + ( m1[2] * m2[10] );
00484         afMatrix[3]  = 0;
00485 
00486         afMatrix[4]  = ( float ) ( m1[4] * m2[0] ) + ( m1[5] * m2[4] ) + ( m1[6] * m2[8] );
00487         afMatrix[5]  = ( float ) ( m1[4] * m2[1] ) + ( m1[5] * m2[5] ) + ( m1[6] * m2[9] );
00488         afMatrix[6]  = ( float ) ( m1[4] * m2[2] ) + ( m1[5] * m2[6] ) + ( m1[6] * m2[10] );
00489         afMatrix[7]  = 0;
00490 
00491         afMatrix[8]  = ( float ) ( m1[8] * m2[0] ) + ( m1[9] * m2[4] ) + ( m1[10] * m2[8] );
00492         afMatrix[9]  = ( float ) ( m1[8] * m2[1] ) + ( m1[9] * m2[5] ) + ( m1[10] * m2[9] );
00493         afMatrix[10] = ( float ) ( m1[8] * m2[2] ) + ( m1[9] * m2[6] ) + ( m1[10] * m2[10] );
00494         afMatrix[11] = 0;
00495 
00496         afMatrix[12] = ( float ) ( m1[12] * m2[0] ) + ( m1[13] * m2[4] ) + ( m1[14] * m2[8] )  + m1[12];
00497         afMatrix[13] = ( float ) ( m1[12] * m2[1] ) + ( m1[13] * m2[5] ) + ( m1[14] * m2[9] )  + m1[13];
00498         afMatrix[14] = ( float ) ( m1[12] * m2[2] ) + ( m1[13] * m2[6] ) + ( m1[14] * m2[10] ) + m1[14];
00499         afMatrix[15] = 1;
00500 
00501         SetMatrix ( afMatrix );
00502 }
00503 
00504 
00505 
00506 // Add row to another iRow1 = iRow1 + iRow2
00507 inline void K3dMatrix::AddRow ( const int iRow1, const int iRow2 )
00508 {
00509         K3dVector4 kRow1;
00510         K3dVector4 kRow2;
00511 
00512         if ( ! ( 0 <= iRow1 ) && ( iRow1 < 4 ) )
00513         {
00514                 cerr  << "Error :: K3dMatrix::AddRow() -- wrong index " << iRow1 << endl;
00515         }
00516         if ( ! ( 0 <= iRow2 ) && ( iRow2 < 4 ) )
00517         {
00518                 cerr  << "Error :: K3dMatrix::AddRow() -- wrong index " << iRow2 << endl;
00519         }
00520 
00521         // Get row 1
00522         this->GetRow ( kRow1, iRow1 );
00523         // Get row 2
00524         this->GetRow ( kRow2, iRow2 );
00525 
00526         // Add row2 to row1
00527         kRow1 += kRow2;
00528 
00529         // Set row 1
00530         this->SetRow ( kRow1, iRow1 );
00531 
00532 }
00533 
00534 
00535 
00536 // Set translation matrix from array
00537 inline void K3dMatrix::Translation ( const float *translation )
00538 {
00539         m_afMatrix[12] = translation[0];
00540         m_afMatrix[13] = translation[1];
00541         m_afMatrix[14] = translation[2];
00542 }
00543 
00544 
00545 
00546 // Set translation matrix from vector
00547 inline void K3dMatrix::Translation ( const K3dVector3 &_rkVector )
00548 {
00549         m_afMatrix[12] = _rkVector[0];
00550         m_afMatrix[13] = _rkVector[1];
00551         m_afMatrix[14] = _rkVector[2];
00552 }
00553 
00554 
00555 
00557 inline void K3dMatrix::InverseTranslation ( const K3dVector3 &_rkVector )
00558 {
00559         m_afMatrix[12] = -_rkVector[0];
00560         m_afMatrix[13] = -_rkVector[1];
00561         m_afMatrix[14] = -_rkVector[2];
00562 }
00563 
00564 
00565 
00566 // Set scale matrix
00567 inline void K3dMatrix::Scale ( K3dVector3 &_rkVector )
00568 {
00569         m_afMatrix[0] = _rkVector[0];
00570         m_afMatrix[1] = 0;
00571         m_afMatrix[2] = 0;
00572         m_afMatrix[3] = 0;
00573 
00574         m_afMatrix[4] = 0;
00575         m_afMatrix[5] = _rkVector[1];
00576         m_afMatrix[6] = 0;
00577         m_afMatrix[7] = 0;
00578 
00579         m_afMatrix[8] = 0;
00580         m_afMatrix[9] = 0;
00581         m_afMatrix[10] = _rkVector[2];
00582         m_afMatrix[11] = 0;
00583 
00584         m_afMatrix[12] = 0;
00585         m_afMatrix[13] = 0;
00586         m_afMatrix[14] = 0;
00587         m_afMatrix[15] = 1;
00588 }
00589 
00590 
00591 
00592 
00593 
00594 // Calculate rotation matrix
00595 inline void K3dMatrix::Rotation ( K3dVector3 &_rkAngle )
00596 {
00597         double cr = cos ( _rkAngle[0] );
00598         double sr = sin ( _rkAngle[0] );
00599         double cp = cos ( _rkAngle[1] );
00600         double sp = sin ( _rkAngle[1] );
00601         double cy = cos ( _rkAngle[2] );
00602         double sy = sin ( _rkAngle[2] );
00603 
00604         m_afMatrix[0] = ( float ) ( cp * cy );
00605         m_afMatrix[1] = ( float ) ( cp * sy );
00606         m_afMatrix[2] = ( float ) ( -sp );
00607 
00608         double srsp = sr * sp;
00609         double crsp = cr * sp;
00610 
00611         m_afMatrix[4] = ( float ) ( srsp * cy - cr  *sy );
00612         m_afMatrix[5] = ( float ) ( srsp * sy + cr * cy );
00613         m_afMatrix[6] = ( float ) ( sr * cp );
00614 
00615         m_afMatrix[8] = ( float ) ( crsp * cy + sr * sy );
00616         m_afMatrix[9] = ( float ) ( crsp * sy - sr * cy );
00617         m_afMatrix[10] = ( float ) ( cr * cp );
00618 }
00619 
00620 
00621 
00622 // Calculate rotation matrix
00623 inline void K3dMatrix::Rotation ( const float *pfAngle )
00624 {
00625 
00626         double cr = cos ( pfAngle[0] );
00627         double sr = sin ( pfAngle[0] );
00628         double cp = cos ( pfAngle[1] );
00629         double sp = sin ( pfAngle[1] );
00630         double cy = cos ( pfAngle[2] );
00631         double sy = sin ( pfAngle[2] );
00632 
00633         m_afMatrix[0] = ( float ) ( cp * cy );
00634         m_afMatrix[1] = ( float ) ( cp * sy );
00635         m_afMatrix[2] = ( float ) ( -sp );
00636 
00637         double srsp = sr * sp;
00638         double crsp = cr * sp;
00639 
00640         m_afMatrix[4] = ( float ) ( srsp * cy - cr  *sy );
00641         m_afMatrix[5] = ( float ) ( srsp * sy + cr * cy );
00642         m_afMatrix[6] = ( float ) ( sr * cp );
00643 
00644         m_afMatrix[8] = ( float ) ( crsp * cy + sr * sy );
00645         m_afMatrix[9] = ( float ) ( crsp * sy - sr * cy );
00646         m_afMatrix[10] = ( float ) ( cr * cp );
00647 }
00648 
00649 
00650 
00651 
00652 // Set inverse rotation matrix
00653 inline void K3dMatrix::InverseRotation ( K3dVector3 &_rkAngle )
00654 {
00655         double cr = cos ( _rkAngle[0] );
00656         double sr = sin ( _rkAngle[0] );
00657         double cp = cos ( _rkAngle[1] );
00658         double sp = sin ( _rkAngle[1] );
00659         double cy = cos ( _rkAngle[2] );
00660         double sy = sin ( _rkAngle[2] );
00661 
00662         m_afMatrix[0] = ( float ) ( cp * cy );
00663         m_afMatrix[4] = ( float ) ( cp * sy );
00664         m_afMatrix[8] = ( float ) ( -sp );
00665 
00666         double srsp = sr * sp;
00667         double crsp = cr * sp;
00668 
00669         m_afMatrix[1] = ( float ) ( srsp * cy - cr * sy );
00670         m_afMatrix[5] = ( float ) ( srsp * sy + cr * cy );
00671         m_afMatrix[9] = ( float ) ( sr * cp );
00672 
00673         m_afMatrix[2] = ( float ) ( crsp * cy + sr * sy );
00674         m_afMatrix[6] = ( float ) ( crsp * sy - sr * cy );
00675         m_afMatrix[10] = ( float ) ( cr * cp );
00676 }
00677 
00678 
00679 
00680 // Set inverse rotation matrix
00681 inline void K3dMatrix::InverseRotation ( const float *pfAngle )
00682 {
00683         double cr = cos ( pfAngle[0] );
00684         double sr = sin ( pfAngle[0] );
00685         double cp = cos ( pfAngle[1] );
00686         double sp = sin ( pfAngle[1] );
00687         double cy = cos ( pfAngle[2] );
00688         double sy = sin ( pfAngle[2] );
00689 
00690 
00691         m_afMatrix[0] = ( float ) ( cp * cy );
00692         m_afMatrix[4] = ( float ) ( cp * sy );
00693         m_afMatrix[8] = ( float ) ( -sp );
00694 
00695         double srsp = sr * sp;
00696         double crsp = cr * sp;
00697 
00698         m_afMatrix[1] = ( float ) ( srsp * cy - cr * sy );
00699         m_afMatrix[5] = ( float ) ( srsp * sy + cr * cy );
00700         m_afMatrix[9] = ( float ) ( sr * cp );
00701 
00702         m_afMatrix[2] = ( float ) ( crsp * cy + sr * sy );
00703         m_afMatrix[6] = ( float ) ( crsp * sy - sr * cy );
00704         m_afMatrix[10] = ( float ) ( cr * cp );
00705 }
00706 
00707 
00708 
00709 // Calculate X rotation matrix
00710 inline void K3dMatrix::RotationX ( const float fAngle )
00711 {
00712         const float fS = sin ( fAngle );
00713         const float fC = cos ( fAngle );
00714 
00715         m_afMatrix[5] = ( float ) fC;
00716         m_afMatrix[6] = ( float )-fS;
00717         m_afMatrix[9] = ( float ) fS;
00718         m_afMatrix[10] = ( float ) fC;
00719 }
00720 
00721 
00722 
00725 inline void K3dMatrix::RotationXGL ( const float _fAngle )
00726 {
00727         const float fS = sin ( _fAngle );
00728         const float fC = cos ( _fAngle );
00729 
00730         m_afMatrix[5] = ( float ) fC;
00731         m_afMatrix[9] = ( float )-fS;
00732         m_afMatrix[6] = ( float ) fS;
00733         m_afMatrix[10] = ( float ) fC;
00734 }
00735 
00736 
00737 
00738 // Calculate Y rotation matrix
00739 inline void K3dMatrix::RotationY ( const float fAngle )
00740 {
00741         const float fS = sin ( fAngle );
00742         const float fC = cos ( fAngle );
00743 
00744         m_afMatrix[0] = ( float ) fC;
00745         m_afMatrix[2] = ( float ) fS;
00746         m_afMatrix[8] = ( float )-fS;
00747         m_afMatrix[10] = ( float ) fC;
00748 }
00749 
00750 
00751 
00754 inline void K3dMatrix::RotationYGL ( const float _fAngle )
00755 {
00756         const float fS = sin ( _fAngle );
00757         const float fC = cos ( _fAngle );
00758 
00759         m_afMatrix[0] = ( float ) fC;
00760         m_afMatrix[8] = ( float ) fS;
00761         m_afMatrix[2] = ( float )-fS;
00762         m_afMatrix[10] = ( float ) fC;
00763 }
00764 
00765 
00766 
00767 // Calculate Z rotation matrix
00768 inline void K3dMatrix::RotationZ ( const float fAngle )
00769 {
00770         const float fS = sin ( fAngle );
00771         const float fC = cos ( fAngle );
00772 
00773         m_afMatrix[0] = ( float ) fC;
00774         m_afMatrix[1] = ( float )-fS;
00775         m_afMatrix[4] = ( float ) fS;
00776         m_afMatrix[5] = ( float ) fC;
00777 }
00778 
00779 
00780 
00783 inline void K3dMatrix::RotationZGL ( const float _fAngle )
00784 {
00785         const float fS = sin ( _fAngle );
00786         const float fC = cos ( _fAngle );
00787 
00788         m_afMatrix[0] = ( float ) fC;
00789         m_afMatrix[4] = ( float )-fS;
00790         m_afMatrix[1] = ( float ) fS;
00791         m_afMatrix[5] = ( float ) fC;
00792 }
00793 
00794 
00795 
00796 // Get translate vector from matrix
00797 inline void K3dMatrix::GetVector ( K3dVector3 &rkVector )
00798 {
00799         K3dVector3 kVector;
00800         kVector[0] = m_afMatrix[12];
00801         kVector[1] = m_afMatrix[13];
00802         kVector[2] = m_afMatrix[14];
00803 
00804         rkVector.Set ( kVector );
00805 }
00806 
00807 
00808 /*
00809         // Get vector from matrix
00810         inline K3dVector3 *K3dMatrix::GetVector()
00811         {
00812                 K3dVector3 kVector;
00813                 kVector[0] = m_afMatrix[12];
00814                 kVector[1] = m_afMatrix[13];
00815                 kVector[2] = m_afMatrix[14];
00816 
00817                 return &kVector;
00818         }
00819 
00820 
00821 */
00822 // Get scalar index by row and column
00823 inline int K3dMatrix::GetScalarIndex ( const int iRow, const int iCol )
00824 {
00825         if ( ! ( 0 <= iRow && iRow <= 3 && 0 <= iCol && iCol <= 3 ) )
00826         {
00827                 cerr  << "Error :: K3dMatrix::GetScalarIndex() -- iRow and iCol indexes is must be from 0 to 3 " << " iRow " << iRow << " iCol " << iCol << endl;
00828         }
00829         if ( ( iRow==0 ) && ( iCol==0 ) ) return 0;
00830         if ( ( iRow==0 ) && ( iCol==1 ) ) return 1;
00831         if ( ( iRow==0 ) && ( iCol==2 ) ) return 2;
00832         if ( ( iRow==0 ) && ( iCol==3 ) ) return 3;
00833         if ( ( iRow==1 ) && ( iCol==0 ) ) return 4;
00834         if ( ( iRow==1 ) && ( iCol==1 ) ) return 5;
00835         if ( ( iRow==1 ) && ( iCol==2 ) ) return 6;
00836         if ( ( iRow==1 ) && ( iCol==3 ) ) return 7;
00837         if ( ( iRow==2 ) && ( iCol==0 ) ) return 8;
00838         if ( ( iRow==2 ) && ( iCol==1 ) ) return 9;
00839         if ( ( iRow==2 ) && ( iCol==2 ) ) return 10;
00840         if ( ( iRow==2 ) && ( iCol==3 ) ) return 11;
00841         if ( ( iRow==3 ) && ( iCol==0 ) ) return 12;
00842         if ( ( iRow==3 ) && ( iCol==1 ) ) return 13;
00843         if ( ( iRow==3 ) && ( iCol==2 ) ) return 14;
00844         if ( ( iRow==3 ) && ( iCol==3 ) ) return 15;
00845         return 0;
00846 }
00847 
00848 
00849 
00850 //      Change vector by matrix only rotation
00851 inline void K3dMatrix::ChangeVector ( K3dVector3& rkVec )
00852 {
00853         K3dVector3 kResult;
00854 
00855 
00856         // Rotate
00857         kResult[0] = ( rkVec[0] * m_afMatrix[0] ) + ( rkVec[1] * m_afMatrix[1] ) + ( rkVec[2] * m_afMatrix[2] ) /* + m_afMatrix[12]*/;
00858         kResult[1] = ( rkVec[0] * m_afMatrix[4] ) + ( rkVec[1] * m_afMatrix[5] ) + ( rkVec[2] * m_afMatrix[6] ) /* + m_afMatrix[13]*/;
00859         kResult[2] = ( rkVec[0] * m_afMatrix[8] ) + ( rkVec[1] * m_afMatrix[9] ) + ( rkVec[2] * m_afMatrix[10] ) /* + m_afMatrix[14]*/;
00860 
00861 
00862         rkVec = kResult;
00863 }
00864 
00865 
00866 
00867 //      Change vector by matrix with tranform
00868 inline void K3dMatrix::ChangeVectorTran ( K3dVector3& rkVec )
00869 {
00870         K3dVector3 kResult;
00871 
00872 
00873         // Rotate
00874         kResult[0] = ( rkVec[0] * m_afMatrix[0] ) + ( rkVec[1] * m_afMatrix[1] ) + ( rkVec[2] * m_afMatrix[2] ) + m_afMatrix[12];
00875         kResult[1] = ( rkVec[0] * m_afMatrix[4] ) + ( rkVec[1] * m_afMatrix[5] ) + ( rkVec[2] * m_afMatrix[6] ) + m_afMatrix[13];
00876         kResult[2] = ( rkVec[0] * m_afMatrix[8] ) + ( rkVec[1] * m_afMatrix[9] ) + ( rkVec[2] * m_afMatrix[10] ) + m_afMatrix[14];
00877 
00878 
00879         rkVec = kResult;
00880 }
00881 
00882 
00883 
00884 //      Translate vector by matrix
00885 inline void K3dMatrix::TranslateVector ( K3dVector3& rkVec )
00886 {
00887         K3dVector3 kResult;
00888 
00889 
00890         // Rotate
00891         kResult[0] = rkVec[0] +  m_afMatrix[12];
00892         kResult[1] = rkVec[1] +  m_afMatrix[13];
00893         kResult[2] = rkVec[2] +  m_afMatrix[14];
00894 
00895 
00896         rkVec = kResult;
00897 }
00898 
00899 
00900 
00902 inline void K3dMatrix::ChangeVectorGL ( K3dVector3& _rkVec )
00903 {
00904         K3dVector3 kResult;
00905 
00906         kResult[0] = ( _rkVec[0] * m_afMatrix[0] ) + ( _rkVec[1] * m_afMatrix[4] ) + ( _rkVec[2] * m_afMatrix[8] );
00907         kResult[1] = ( _rkVec[0] * m_afMatrix[1] ) + ( _rkVec[1] * m_afMatrix[5] ) + ( _rkVec[2] * m_afMatrix[9] );
00908         kResult[2] = ( _rkVec[0] * m_afMatrix[2] ) + ( _rkVec[1] * m_afMatrix[6] ) + ( _rkVec[2] * m_afMatrix[10] );
00909 
00910         _rkVec = kResult;
00911 }
00912 
00913 
00914 
00915 //      Change X vector coordination by matrix
00916 inline void K3dMatrix::ChangeVectorX ( K3dVector3& rkVec )
00917 {
00918         float fVec;
00919 
00920         fVec = ( rkVec[0] * m_afMatrix[0] ) + ( rkVec[1] * m_afMatrix[1] ) + ( rkVec[2] * m_afMatrix[2] );
00921         rkVec[0] = fVec;
00922 
00923 }
00924 
00925 
00926 
00929 inline void K3dMatrix::ChangeVectorXGL ( K3dVector3& _rkVec )
00930 {
00931         float fVec = ( _rkVec[0] * m_afMatrix[0] ) + ( _rkVec[1] * m_afMatrix[4] ) + ( _rkVec[2] * m_afMatrix[8] );
00932         _rkVec[0] = fVec;
00933 }
00934 
00935 
00936 
00937 //      Change Y vector coordination by matrix
00938 inline void K3dMatrix::ChangeVectorY ( K3dVector3& _rkVec )
00939 {
00940         float fVec;
00941 
00942         fVec = _rkVec[0] * m_afMatrix[4] + _rkVec[1] * m_afMatrix[5] + _rkVec[2] * m_afMatrix[6];
00943         _rkVec[1] = fVec;
00944 }
00945 
00946 
00947 
00950 inline void K3dMatrix::ChangeVectorYGL ( K3dVector3& _rkVec )
00951 {
00952         float fVec = _rkVec[0] * m_afMatrix[1] + _rkVec[1] * m_afMatrix[5] + _rkVec[2] * m_afMatrix[9];
00953         _rkVec[1] = fVec;
00954 }
00955 
00956 
00957 
00958 //      Change Z vector coordination by matrix
00959 inline void K3dMatrix::ChangeVectorZ ( K3dVector3& rkVec )
00960 {
00961         float fVec;
00962 
00963         fVec = rkVec[0] * m_afMatrix[8] + rkVec[1] * m_afMatrix[9] + rkVec[2] * m_afMatrix[10];
00964         rkVec[2] = fVec;
00965 }
00966 
00967 
00968 
00971 inline void K3dMatrix::ChangeVectorZGL ( K3dVector3& _rkVec )
00972 {
00973         float fVec = _rkVec[0] * m_afMatrix[2] + _rkVec[1] * m_afMatrix[6] + _rkVec[2] * m_afMatrix[10];
00974         _rkVec[2] = fVec;
00975 }
00976 
00977 
00978 
00979 
00980 // Calculate determinant
00981 inline float K3dMatrix::Determinant ()
00982 {
00983         float fA0 = m_afMatrix[ 0]*m_afMatrix[ 5] - m_afMatrix[ 1]*m_afMatrix[ 4];
00984         float fA1 = m_afMatrix[ 0]*m_afMatrix[ 6] - m_afMatrix[ 2]*m_afMatrix[ 4];
00985         float fA2 = m_afMatrix[ 0]*m_afMatrix[ 7] - m_afMatrix[ 3]*m_afMatrix[ 4];
00986         float fA3 = m_afMatrix[ 1]*m_afMatrix[ 6] - m_afMatrix[ 2]*m_afMatrix[ 5];
00987         float fA4 = m_afMatrix[ 1]*m_afMatrix[ 7] - m_afMatrix[ 3]*m_afMatrix[ 5];
00988         float fA5 = m_afMatrix[ 2]*m_afMatrix[ 7] - m_afMatrix[ 3]*m_afMatrix[ 6];
00989         float fB0 = m_afMatrix[ 8]*m_afMatrix[13] - m_afMatrix[ 9]*m_afMatrix[12];
00990         float fB1 = m_afMatrix[ 8]*m_afMatrix[14] - m_afMatrix[10]*m_afMatrix[12];
00991         float fB2 = m_afMatrix[ 8]*m_afMatrix[15] - m_afMatrix[11]*m_afMatrix[12];
00992         float fB3 = m_afMatrix[ 9]*m_afMatrix[14] - m_afMatrix[10]*m_afMatrix[13];
00993         float fB4 = m_afMatrix[ 9]*m_afMatrix[15] - m_afMatrix[11]*m_afMatrix[13];
00994         float fB5 = m_afMatrix[10]*m_afMatrix[15] - m_afMatrix[11]*m_afMatrix[14];
00995         float fDet = fA0*fB5-fA1*fB4+fA2*fB3+fA3*fB2-fA4*fB1+fA5*fB0;
00996         return fDet;
00997 }
00998 
00999 
01000 
01002 inline void K3dMatrix::Inverse()
01003 {
01004         float fA0 = m_afMatrix[ 0]*m_afMatrix[ 5] - m_afMatrix[ 1]*m_afMatrix[ 4];
01005         float fA1 = m_afMatrix[ 0]*m_afMatrix[ 6] - m_afMatrix[ 2]*m_afMatrix[ 4];
01006         float fA2 = m_afMatrix[ 0]*m_afMatrix[ 7] - m_afMatrix[ 3]*m_afMatrix[ 4];
01007         float fA3 = m_afMatrix[ 1]*m_afMatrix[ 6] - m_afMatrix[ 2]*m_afMatrix[ 5];
01008         float fA4 = m_afMatrix[ 1]*m_afMatrix[ 7] - m_afMatrix[ 3]*m_afMatrix[ 5];
01009         float fA5 = m_afMatrix[ 2]*m_afMatrix[ 7] - m_afMatrix[ 3]*m_afMatrix[ 6];
01010         float fB0 = m_afMatrix[ 8]*m_afMatrix[13] - m_afMatrix[ 9]*m_afMatrix[12];
01011         float fB1 = m_afMatrix[ 8]*m_afMatrix[14] - m_afMatrix[10]*m_afMatrix[12];
01012         float fB2 = m_afMatrix[ 8]*m_afMatrix[15] - m_afMatrix[11]*m_afMatrix[12];
01013         float fB3 = m_afMatrix[ 9]*m_afMatrix[14] - m_afMatrix[10]*m_afMatrix[13];
01014         float fB4 = m_afMatrix[ 9]*m_afMatrix[15] - m_afMatrix[11]*m_afMatrix[13];
01015         float fB5 = m_afMatrix[10]*m_afMatrix[15] - m_afMatrix[11]*m_afMatrix[14];
01016 
01017         float fDet = fA0*fB5-fA1*fB4+fA2*fB3+fA3*fB2-fA4*fB1+fA5*fB0;
01018 
01019         float kInv[16];
01020         kInv[0] = + m_afMatrix[ 5]*fB5 - m_afMatrix[ 6]*fB4 + m_afMatrix[ 7]*fB3;
01021         kInv[1] = - m_afMatrix[ 1]*fB5 + m_afMatrix[ 2]*fB4 - m_afMatrix[ 3]*fB3;
01022         kInv[2] = + m_afMatrix[13]*fA5 - m_afMatrix[14]*fA4 + m_afMatrix[15]*fA3;
01023         kInv[3] = - m_afMatrix[ 9]*fA5 + m_afMatrix[10]*fA4 - m_afMatrix[11]*fA3;
01024         kInv[4] = - m_afMatrix[ 4]*fB5 + m_afMatrix[ 6]*fB2 - m_afMatrix[ 7]*fB1;
01025         kInv[5] = + m_afMatrix[ 0]*fB5 - m_afMatrix[ 2]*fB2 + m_afMatrix[ 3]*fB1;
01026         kInv[6] = - m_afMatrix[12]*fA5 + m_afMatrix[14]*fA2 - m_afMatrix[15]*fA1;
01027         kInv[7] = + m_afMatrix[ 8]*fA5 - m_afMatrix[10]*fA2 + m_afMatrix[11]*fA1;
01028         kInv[8] = + m_afMatrix[ 4]*fB4 - m_afMatrix[ 5]*fB2 + m_afMatrix[ 7]*fB0;
01029         kInv[9] = - m_afMatrix[ 0]*fB4 + m_afMatrix[ 1]*fB2 - m_afMatrix[ 3]*fB0;
01030         kInv[10] = + m_afMatrix[12]*fA4 - m_afMatrix[13]*fA2 + m_afMatrix[15]*fA0;
01031         kInv[11] = - m_afMatrix[ 8]*fA4 + m_afMatrix[ 9]*fA2 - m_afMatrix[11]*fA0;
01032         kInv[12] = - m_afMatrix[ 4]*fB3 + m_afMatrix[ 5]*fB1 - m_afMatrix[ 6]*fB0;
01033         kInv[13] = + m_afMatrix[ 0]*fB3 - m_afMatrix[ 1]*fB1 + m_afMatrix[ 2]*fB0;
01034         kInv[14] = - m_afMatrix[12]*fA3 + m_afMatrix[13]*fA1 - m_afMatrix[14]*fA0;
01035         kInv[15] = + m_afMatrix[ 8]*fA3 - m_afMatrix[ 9]*fA1 + m_afMatrix[10]*fA0;
01036 
01037         float fInvDet = ( ( float ) 1.0 ) /fDet;
01038 
01039         for ( int i=0 ; i<16; i++ )
01040         {
01041                 kInv[i] *= fInvDet;
01042                 m_afMatrix[i] = kInv[i];
01043         }
01044 }
01045 
01046 
01047 
01048 // Inverse opengl matrix
01049 inline void K3dMatrix::InverseGL()
01050 {
01051         ToOrFromGL();
01052 
01053         float fA0 = m_afMatrix[ 0]*m_afMatrix[ 5] - m_afMatrix[ 1]*m_afMatrix[ 4];
01054         float fA1 = m_afMatrix[ 0]*m_afMatrix[ 6] - m_afMatrix[ 2]*m_afMatrix[ 4];
01055         float fA2 = m_afMatrix[ 0]*m_afMatrix[ 7] - m_afMatrix[ 3]*m_afMatrix[ 4];
01056         float fA3 = m_afMatrix[ 1]*m_afMatrix[ 6] - m_afMatrix[ 2]*m_afMatrix[ 5];
01057         float fA4 = m_afMatrix[ 1]*m_afMatrix[ 7] - m_afMatrix[ 3]*m_afMatrix[ 5];
01058         float fA5 = m_afMatrix[ 2]*m_afMatrix[ 7] - m_afMatrix[ 3]*m_afMatrix[ 6];
01059         float fB0 = m_afMatrix[ 8]*m_afMatrix[13] - m_afMatrix[ 9]*m_afMatrix[12];
01060         float fB1 = m_afMatrix[ 8]*m_afMatrix[14] - m_afMatrix[10]*m_afMatrix[12];
01061         float fB2 = m_afMatrix[ 8]*m_afMatrix[15] - m_afMatrix[11]*m_afMatrix[12];
01062         float fB3 = m_afMatrix[ 9]*m_afMatrix[14] - m_afMatrix[10]*m_afMatrix[13];
01063         float fB4 = m_afMatrix[ 9]*m_afMatrix[15] - m_afMatrix[11]*m_afMatrix[13];
01064         float fB5 = m_afMatrix[10]*m_afMatrix[15] - m_afMatrix[11]*m_afMatrix[14];
01065 
01066         float fDet = fA0*fB5-fA1*fB4+fA2*fB3+fA3*fB2-fA4*fB1+fA5*fB0;
01067 
01068         float kInv[16];
01069         kInv[0] = + m_afMatrix[ 5]*fB5 - m_afMatrix[ 6]*fB4 + m_afMatrix[ 7]*fB3;
01070         kInv[1] = - m_afMatrix[ 1]*fB5 + m_afMatrix[ 2]*fB4 - m_afMatrix[ 3]*fB3;
01071         kInv[2] = + m_afMatrix[13]*fA5 - m_afMatrix[14]*fA4 + m_afMatrix[15]*fA3;
01072         kInv[3] = - m_afMatrix[ 9]*fA5 + m_afMatrix[10]*fA4 - m_afMatrix[11]*fA3;
01073         kInv[4] = - m_afMatrix[ 4]*fB5 + m_afMatrix[ 6]*fB2 - m_afMatrix[ 7]*fB1;
01074         kInv[5] = + m_afMatrix[ 0]*fB5 - m_afMatrix[ 2]*fB2 + m_afMatrix[ 3]*fB1;
01075         kInv[6] = - m_afMatrix[12]*fA5 + m_afMatrix[14]*fA2 - m_afMatrix[15]*fA1;
01076         kInv[7] = + m_afMatrix[ 8]*fA5 - m_afMatrix[10]*fA2 + m_afMatrix[11]*fA1;
01077         kInv[8] = + m_afMatrix[ 4]*fB4 - m_afMatrix[ 5]*fB2 + m_afMatrix[ 7]*fB0;
01078         kInv[9] = - m_afMatrix[ 0]*fB4 + m_afMatrix[ 1]*fB2 - m_afMatrix[ 3]*fB0;
01079         kInv[10] = + m_afMatrix[12]*fA4 - m_afMatrix[13]*fA2 + m_afMatrix[15]*fA0;
01080         kInv[11] = - m_afMatrix[ 8]*fA4 + m_afMatrix[ 9]*fA2 - m_afMatrix[11]*fA0;
01081         kInv[12] = - m_afMatrix[ 4]*fB3 + m_afMatrix[ 5]*fB1 - m_afMatrix[ 6]*fB0;
01082         kInv[13] = + m_afMatrix[ 0]*fB3 - m_afMatrix[ 1]*fB1 + m_afMatrix[ 2]*fB0;
01083         kInv[14] = - m_afMatrix[12]*fA3 + m_afMatrix[13]*fA1 - m_afMatrix[14]*fA0;
01084         kInv[15] = + m_afMatrix[ 8]*fA3 - m_afMatrix[ 9]*fA1 + m_afMatrix[10]*fA0;
01085 
01086         float fInvDet = ( ( float ) 1.0 ) /fDet;
01087 
01088         for ( int i=0 ; i<16; i++ )
01089         {
01090                 kInv[i] *= fInvDet;
01091                 m_afMatrix[i] = kInv[i];
01092         }
01093 }
01094 
01095 
01096 
01097 // Flip rows to column (normal matrix to OpenGL or again)
01098 inline void K3dMatrix::FlipRowToColumn ( const K3dMatrix &_rkMatrix )
01099 {
01100         m_afMatrix[ 0] = _rkMatrix.m_afMatrix[ 0];
01101         m_afMatrix[ 1] = _rkMatrix.m_afMatrix[ 4];
01102         m_afMatrix[ 2] = _rkMatrix.m_afMatrix[ 8];
01103         m_afMatrix[ 3] = _rkMatrix.m_afMatrix[12];
01104         m_afMatrix[ 4] = _rkMatrix.m_afMatrix[ 1];
01105         m_afMatrix[ 5] = _rkMatrix.m_afMatrix[ 5];
01106         m_afMatrix[ 6] = _rkMatrix.m_afMatrix[ 9];
01107         m_afMatrix[ 7] = _rkMatrix.m_afMatrix[13];
01108         m_afMatrix[ 8] = _rkMatrix.m_afMatrix[ 2];
01109         m_afMatrix[ 9] = _rkMatrix.m_afMatrix[ 6];
01110         m_afMatrix[10] = _rkMatrix.m_afMatrix[10];
01111         m_afMatrix[11] = _rkMatrix.m_afMatrix[14];
01112         m_afMatrix[12] = _rkMatrix.m_afMatrix[ 3];
01113         m_afMatrix[13] = _rkMatrix.m_afMatrix[ 7];
01114         m_afMatrix[14] = _rkMatrix.m_afMatrix[11];
01115         m_afMatrix[15] = _rkMatrix.m_afMatrix[15];
01116 }
01117 
01118 
01119 
01120 // Rotation through an angle about an arbitrary axis
01121 inline void K3dMatrix::Rotation ( const K3dVector3 &_rkAxis  ,const float fAngle )
01122 {
01123         //                        | C+Ax^2(1-C)   , AxAy(1-C)-AzS , AxAz(1-C)+AyS |
01124         //RA(angle) = | AxAy(1-C)+AzS , C+Ay^2(1-C)   , AyAz(1-C)-AxS |
01125         //                        | AxAz(1-C)-AyS , AyAz(1-C)+AxS , C+Az^2(1-C)   |
01126 
01127         // S = sin, C = cos
01128         K3dVector3 kA = _rkAxis;
01129         float fS = ( float ) sin ( fAngle );
01130         float fC = ( float ) cos ( fAngle );
01131         float f1C = 1.0f - fC;
01132         float fAxAy = _rkAxis.GetX() *_rkAxis.GetY();
01133         float fAxAz = _rkAxis.GetX() *_rkAxis.GetZ();
01134         float fAyAz = _rkAxis.GetY() *_rkAxis.GetZ();
01135         float fAxS = _rkAxis.GetX() *fS;
01136         float fAyS = _rkAxis.GetY() *fS;
01137         float fAzS = _rkAxis.GetZ() *fS;
01138         float fAx2 = _rkAxis.GetX() *_rkAxis.GetX();
01139         float fAy2 = _rkAxis.GetY() *_rkAxis.GetY();
01140         float fAz2 = _rkAxis.GetZ() *_rkAxis.GetZ();
01141         // Set matrix
01142         m_afMatrix[0]=fC+ ( fAx2*f1C );     m_afMatrix[1]= ( fAxAy*f1C )-fAzS;  m_afMatrix[2]= ( fAxAz*f1C ) +fAyS;
01143         m_afMatrix[4]= ( fAxAy*f1C ) +fAzS;     m_afMatrix[5]=fC+ ( fAy2*f1C );         m_afMatrix[6]= ( fAyAz*f1C )-fAxS;
01144         m_afMatrix[8]= ( fAxAz*f1C )-fAyS;      m_afMatrix[9]= ( fAyAz*f1C ) +fAxS;     m_afMatrix[10]=fC+ ( fAz2*f1C );
01145 }
01146 
01147 
01148 
01149 
01150 
01151 // GL rotation through an angle about an arbitrary axis
01152 inline void K3dMatrix::RotationGL ( const K3dVector3 &_rkAxis  ,const float fAngle )
01153 {
01154         //                        | C+Ax^2(1-C)   , AxAy(1-C)-AzS , AxAz(1-C)+AyS |
01155         //RA(angle) = | AxAy(1-C)+AzS , C+Ay^2(1-C)   , AyAz(1-C)-AxS |
01156         //                        | AxAz(1-C)-AyS , AyAz(1-C)+AxS , C+Az^2(1-C)   |
01157 
01158         // S = sin, C = cos
01159         K3dVector3 kA = _rkAxis;
01160         float fS = ( float ) sin ( fAngle );
01161         float fC = ( float ) cos ( fAngle );
01162         float f1C = 1.0f - fC;
01163         float fAxAy = _rkAxis.GetX() *_rkAxis.GetY();
01164         float fAxAz = _rkAxis.GetX() *_rkAxis.GetZ();
01165         float fAyAz = _rkAxis.GetY() *_rkAxis.GetZ();
01166         float fAxS = _rkAxis.GetX() *fS;
01167         float fAyS = _rkAxis.GetY() *fS;
01168         float fAzS = _rkAxis.GetZ() *fS;
01169         float fAx2 = _rkAxis.GetX() *_rkAxis.GetX();
01170         float fAy2 = _rkAxis.GetY() *_rkAxis.GetY();
01171         float fAz2 = _rkAxis.GetZ() *_rkAxis.GetZ();
01172         // Set matrix
01173         m_afMatrix[0]=fC+ ( fAx2*f1C );     m_afMatrix[4]= ( fAxAy*f1C )-fAzS;  m_afMatrix[8]= ( fAxAz*f1C ) +fAyS;
01174         m_afMatrix[1]= ( fAxAy*f1C ) +fAzS;     m_afMatrix[5]=fC+ ( fAy2*f1C );         m_afMatrix[9]= ( fAyAz*f1C )-fAxS;
01175         m_afMatrix[2]= ( fAxAz*f1C )-fAyS;      m_afMatrix[6]= ( fAyAz*f1C ) +fAxS;     m_afMatrix[10]=fC+ ( fAz2*f1C );
01176 }
01177 
01178 // Calculate linear system of three equations
01179 inline K3dVector3 K3dMatrix::LinearSystem ( const K3dVector4 &_rkEq1,const K3dVector4 &_rkEq2,const K3dVector4 &_rkEq3 )
01180 {
01181         K3dVector3 kV;
01182         K3dVector4 kV4;
01183         K3dMatrix kM;
01184         float fScalar;
01185         //float *pM;
01186 
01187         // Set equations to the matrix
01188         kM.SetRow ( _rkEq1, 0 );
01189         kM.SetRow ( _rkEq2, 1 );
01190         kM.SetRow ( _rkEq3, 2 );
01191 
01193         // Set scalar for multiplication row 1
01194         // Column 1 of row 1 must equal to 1
01196 
01197         fScalar = kM[0];
01198         if ( fScalar == 0 ) return kV;
01199         fScalar = 1/fScalar;
01200         // Multiply row 1 by scalar
01201         kM.MultiplyRow ( fScalar, 0 );
01202 
01203         // Set scalar for add a multiple row 1 to row 2
01204         // Column 1 of row 2 must equal to 0
01205         fScalar = -kM[4];
01206         // Get row 1 to 4D vector
01207         kM.GetRow ( kV4, 0 );
01208         // Multiply row 1 by scalar
01209         kM.MultiplyRow ( fScalar, 0 );
01210         // Add row 1 to row 2
01211         kM.AddRow ( 1, 0 );
01212         // Set previous row 1
01213         kM.SetRow ( kV4, 0 );
01214 
01215         // Set scalar for add a multiple row 1 to row 3
01216         // Column 1 of row 3 must equal to 0
01217         fScalar = -kM[8];
01218         // Multiply row 1 by scalar
01219         kM.MultiplyRow ( fScalar, 0 );
01220         // Add row 1 to row 3
01221         kM.AddRow ( 2, 0 );
01222         // Set previous row 1
01223         kM.SetRow ( kV4, 0 );
01224 
01225 
01226 
01228         // Set scalar for multiplication row 2
01229         // Column 2 of row 2 must equal to 1
01231 
01232         fScalar = kM[5];
01233         if ( fScalar == 0 ) return kV;
01234         fScalar = 1/fScalar;
01235         // Multiply row 2 by scalar
01236         kM.MultiplyRow ( fScalar, 1 );
01237 
01238         // Set scalar for add a multiple row 2 to row 1
01239         // Column 2 of row 2 must equal to 0
01240         fScalar = -kM[1];
01241         // Get row 2 to 4D vector
01242         kM.GetRow ( kV4, 1 );
01243         // Multiply row 2 by scalar
01244         kM.MultiplyRow ( fScalar, 1 );
01245         // Add row 2 to row 1
01246         kM.AddRow ( 0, 1 );
01247         // Set previous row 2
01248         kM.SetRow ( kV4, 1 );
01249 
01250         // Set scalar for add a multiple row 2 to row 3
01251         // Column 2 of row 3 must equal to 0
01252         fScalar = -kM[9];
01253         // Multiply row 2 by scalar
01254         kM.MultiplyRow ( fScalar, 1 );
01255         // Add row 2 to row 3
01256         kM.AddRow ( 2, 1 );
01257         // Set previous row 2
01258         kM.SetRow ( kV4, 1 );
01259 
01260 
01261 
01263         // Set scalar for multiplication row 3
01264         // Column 3 of row 3 must equal to 1
01266 
01267         fScalar = kM[10];
01268         //if(fScalar == 0) return kV;
01269         if ( fScalar == 0 ) return kV;
01270         fScalar = 1/fScalar;
01271         // Multiply row 3 by scalar
01272         kM.MultiplyRow ( fScalar, 2 );
01273 
01274         // Set scalar for add a multiple row 3 to row 1
01275         // Column 3 of row 1 must equal to 0
01276         fScalar = -kM[2];
01277         // Get row 3 to 4D vector
01278         kM.GetRow ( kV4, 2 );
01279         // Multiply row 3 by scalar
01280         kM.MultiplyRow ( fScalar, 2 );
01281         // Add row 3 to row 1
01282         kM.AddRow ( 0, 2 );
01283         // Set previous row 3
01284         kM.SetRow ( kV4, 2 );
01285 
01286         // Set scalar for add a multiple row 3 to row 2
01287         // Column 3 of row 2 must equal to 0
01288         fScalar = -kM[6];
01289         // Multiply row 3 by scalar
01290         kM.MultiplyRow ( fScalar, 2 );
01291         // Add row 3 to row 2
01292         kM.AddRow ( 1, 2 );
01293         // Set previous row 3
01294         kM.SetRow ( kV4, 2 );
01295 
01296 
01297         // Get results from matrix
01298         kV[0] = kM[3];
01299         kV[1] = kM[7];
01300         kV[2] = kM[11];
01301 
01302         return kV;
01303 }
01304 
01305 
01306 
01307 // Change standrard matrix to the OpenGL matrix
01308 inline void K3dMatrix::ToOrFromGL()
01309 {
01310         K3dMatrix kM = m_afMatrix;
01311 
01312         m_afMatrix[1] = kM[4];
01313         m_afMatrix[2] = kM[8];
01314         m_afMatrix[3] = kM[12];
01315         m_afMatrix[4] = kM[1];
01316         m_afMatrix[6] = kM[9];
01317         m_afMatrix[7] = kM[13];
01318         m_afMatrix[8] = kM[2];
01319         m_afMatrix[9] = kM[6];
01320         m_afMatrix[11] = kM[14];
01321         m_afMatrix[12] = kM[3];
01322         m_afMatrix[13] = kM[7];
01323         m_afMatrix[14] = kM[11];
01324 
01325 }
01326 
01327 
01328 
01329 // Multiply matrix and vector
01330 // dst = M * src
01331 inline void K3dMatrix::MultMatrixVec ( const K3dVector3 &rkSrc, K3dVector3 &rkDst )
01332 {
01333         K3dMatrix kElement = m_afMatrix;
01334 
01335         float fW = (
01336                        rkSrc[0] * kElement ( 3,0 ) +
01337                        rkSrc[1] * kElement ( 3,1 ) +
01338                        rkSrc[2] * kElement ( 3,2 ) +
01339                        kElement ( 3,3 ) );
01340 
01341         if ( fW == ( float ) 0 )
01342         {
01343                 cerr  << "Error :: K3dMatrix::MultMatrixVec() -- Divide by zero" << fW << endl;
01344         }
01345         fW = ( float ) 1;
01346 
01347 
01348         rkDst[0]  = (
01349                         rkSrc[0] * kElement ( 0,0 ) +
01350                         rkSrc[1] * kElement ( 0,1 ) +
01351                         rkSrc[2] * kElement ( 0,2 ) +
01352                         kElement ( 0,3 ) ) / fW;
01353         rkDst[1]  = (
01354                         rkSrc[0] * kElement ( 1,0 ) +
01355                         rkSrc[1] * kElement ( 1,1 ) +
01356                         rkSrc[2] * kElement ( 1,2 ) +
01357                         kElement ( 1,3 ) ) / fW;
01358         rkDst[2]  = (
01359                         rkSrc[0] * kElement ( 2,0 ) +
01360                         rkSrc[1] * kElement ( 2,1 ) +
01361                         rkSrc[2] * kElement ( 2,2 ) +
01362                         kElement ( 2,3 ) ) / fW;
01363 }
01364 
01365 
01366 
01367 // Multiply matrix and vector
01368 // dst = M * src
01369 inline void K3dMatrix::MultMatrixVec ( K3dVector3 & rkSrcAndDst )
01370 {
01371         //MultMatrixVec(K3dVector3(rkSrcAndDst), rkSrcAndDst);
01372         MultMatrixVec ( rkSrcAndDst, rkSrcAndDst );
01373 }
01374 
01375 
01376 
01377 
01378 // Multiply vector and matrix
01379 // dst = src * M
01380 inline void K3dMatrix::MultVecMatrix ( const K3dVector3 &rkSrc, K3dVector3 &rkDst )
01381 {
01382         K3dMatrix kElement = m_afMatrix;
01383 
01384         float fW = (
01385                        rkSrc[0] * kElement ( 0,3 ) +
01386                        rkSrc[1] * kElement ( 1,3 ) +
01387                        rkSrc[2] * kElement ( 2,3 ) +
01388                        kElement ( 3,3 ) );
01389 
01390         if ( fW == ( float ) 0 )
01391         {
01392                 cerr  << "Error :: K3dMatrix::MultVecMatrix()  -- Divide by zero" << fW << endl;
01393         }
01394 
01395         rkDst[0]  = (
01396                         rkSrc[0] * kElement ( 0,0 ) +
01397                         rkSrc[1] * kElement ( 1,0 ) +
01398                         rkSrc[2] * kElement ( 2,0 ) +
01399                         kElement ( 3,0 ) ) / fW;
01400         rkDst[1]  = (
01401                         rkSrc[0] * kElement ( 0,1 ) +
01402                         rkSrc[1] * kElement ( 1,1 ) +
01403                         rkSrc[2] * kElement ( 2,1 ) +
01404                         kElement ( 3,1 ) ) / fW;
01405         rkDst[2]  = (
01406                         rkSrc[0] * kElement ( 0,2 ) +
01407                         rkSrc[1] * kElement ( 1,2 ) +
01408                         rkSrc[2] * kElement ( 2,2 ) +
01409                         kElement ( 3,2 ) ) / fW;
01410 }
01411 
01412 
01413 
01414 
01415 // Multiply vector and matrix
01416 // dst = src * M
01417 inline void K3dMatrix::MultVecMatrix ( K3dVector3 & rkSrcAndDst )
01418 {
01419         //MultVecMatrix(K3dVector3(rkSrcAndDst), rkSrcAndDst);
01420         MultVecMatrix ( rkSrcAndDst, rkSrcAndDst );
01421 }
01422 
01423 
01424 
01425 // Multiply directional matrix and vector
01426 // dst = M * src
01427 inline void K3dMatrix::MultMatrixDir ( const  K3dVector3 &rkSrc, K3dVector3 &rkDst )
01428 {
01429         K3dMatrix kElement = m_afMatrix;
01430 
01431         rkDst[0]  = (
01432                         rkSrc[0] * kElement ( 0,0 ) +
01433                         rkSrc[1] * kElement ( 0,1 ) +
01434                         rkSrc[2] * kElement ( 0,2 ) ) ;
01435         rkDst[1]  = (
01436                         rkSrc[0] * kElement ( 1,0 ) +
01437                         rkSrc[1] * kElement ( 1,1 ) +
01438                         rkSrc[2] * kElement ( 1,2 ) ) ;
01439         rkDst[2]  = (
01440                         rkSrc[0] * kElement ( 2,0 ) +
01441                         rkSrc[1] * kElement ( 2,1 ) +
01442                         rkSrc[2] * kElement ( 2,2 ) ) ;
01443 }
01444 
01445 
01446 
01447 // Multiply directional matrix and vector
01448 // dst = src * M
01449 inline void K3dMatrix::MultMatrixDir ( K3dVector3 & rkSrcAndDst )
01450 {
01451         //MultMatrixDir(K3dVector3(rkSrcAndDst), rkSrcAndDst);
01452         MultMatrixDir ( rkSrcAndDst, rkSrcAndDst );
01453 }
01454 
01455 
01456 
01457 // Multiply vector and directional matrix
01458 // dst = src * M
01459 inline void K3dMatrix::MultDirMatrix ( const  K3dVector3 &rkSrc, K3dVector3 &rkDst )
01460 {
01461         K3dMatrix kElement = m_afMatrix;
01462 
01463         rkDst[0]  = (
01464                         rkSrc[0] * kElement ( 0,0 ) +
01465                         rkSrc[1] * kElement ( 1,0 ) +
01466                         rkSrc[2] * kElement ( 2,0 ) ) ;
01467         rkDst[1]  = (
01468                         rkSrc[0] * kElement ( 0,1 ) +
01469                         rkSrc[1] * kElement ( 1,1 ) +
01470                         rkSrc[2] * kElement ( 2,1 ) ) ;
01471         rkDst[2]  = (
01472                         rkSrc[0] * kElement ( 0,2 ) +
01473                         rkSrc[1] * kElement ( 1,2 ) +
01474                         rkSrc[2] * kElement ( 2,2 ) ) ;
01475 }
01476 
01477 
01478 
01479 // Multiply vector and directional matrix
01480 // dst = src * M
01481 inline void K3dMatrix::MultDirMatrix ( K3dVector3 & rkSrcAndDst )
01482 {
01483         //MultDirMatrix(K3dVector3(rkSrcAndDst), rkSrcAndDst);
01484         MultDirMatrix ( rkSrcAndDst, rkSrcAndDst );
01485 }
01486 
01487 

Generated on Thu Aug 16 23:53:27 2007 for K3dEngine by  doxygen 1.5.0