Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

CMatrix.h

Go to the documentation of this file.
00001 /*
00002         
00003         ZMACHINE 2.0 (SIGFRID)
00004 
00005         CMATRIX.H
00006 
00007         author:                 Trombetta Roberto
00008         filename:               CMatrix.h       
00009         description:    header file for matrix class 
00010         date:                   04/04/2003
00011 
00012 */
00013 
00014 #ifndef __CMATRIX_H_
00015 #define __CMATRIX_H_
00016 
00017 #include "CVector3.h"
00018 #include "Zdef.h"
00019 #include "Zmacro.h"
00020 
00022 
00026 class CMatrix {
00027 
00028 public:
00029 
00031         zfloat fm[16];
00032         
00034         CMatrix () {}
00035         
00037         inline CMatrix (zfloat v11, zfloat v12, zfloat v13,
00038                                 zfloat v21, zfloat v22, zfloat v23,
00039                                     zfloat v31, zfloat v32, zfloat v33) {
00040         
00041                 fm[ 0] = v11; 
00042                 fm[ 1] = v12; 
00043                 fm[ 2] = v13; 
00044                 fm[ 3] = 0;
00045                 fm[ 4] = v21; 
00046                 fm[ 5] = v22; 
00047                 fm[ 6] = v23; 
00048                 fm[ 7] = 0;
00049                 fm[ 8] = v31; 
00050                 fm[ 9] = v32; 
00051                 fm[10] = v33; 
00052                 fm[11] = 0;
00053                 fm[12] = 0; 
00054                 fm[13] = 0; 
00055                 fm[14] = 0; 
00056                 fm[15] = 0;  
00057         }
00058 
00060         inline CMatrix (zfloat v11, zfloat v12, zfloat v13, zfloat v14,
00061                                 zfloat v21, zfloat v22, zfloat v23, zfloat v24,
00062                                     zfloat v31, zfloat v32, zfloat v33, zfloat v34,
00063                                         zfloat v41, zfloat v42, zfloat v43, zfloat v44) {
00064         
00065                 fm[ 0] = v11; 
00066                 fm[ 1] = v12; 
00067                 fm[ 2] = v13; 
00068                 fm[ 3] = v14;
00069                 fm[ 4] = v21; 
00070                 fm[ 5] = v22; 
00071                 fm[ 6] = v23; 
00072                 fm[ 7] = v24;
00073                 fm[ 8] = v31; 
00074                 fm[ 9] = v32; 
00075                 fm[10] = v33; 
00076                 fm[11] = v34;
00077                 fm[12] = v41; 
00078                 fm[13] = v42; 
00079                 fm[14] = v43; 
00080                 fm[15] = v44;  
00081         }
00082 
00084         inline CMatrix (zfloat v[16]) {
00085         
00086                 fm[ 0] = v[ 0];
00087                 fm[ 1] = v[ 1];
00088                 fm[ 2] = v[ 2];
00089                 fm[ 3] = v[ 3];
00090                 fm[ 4] = v[ 4];
00091                 fm[ 5] = v[ 5];
00092                 fm[ 6] = v[ 6];
00093                 fm[ 7] = v[ 7];
00094                 fm[ 8] = v[ 8];
00095                 fm[ 9] = v[ 9];
00096                 fm[10] = v[10];
00097                 fm[11] = v[11];
00098                 fm[12] = v[12];
00099                 fm[13] = v[13];
00100                 fm[14] = v[14];
00101                 fm[15] = v[15];
00102 
00103         }
00104 
00106         inline CMatrix operator+ (const CMatrix &v) {
00107         
00108                 fm[ 0] += v.fm[ 0];
00109                 fm[ 1] += v.fm[ 1];
00110                 fm[ 2] += v.fm[ 2];
00111                 fm[ 3] += v.fm[ 3];
00112                 fm[ 4] += v.fm[ 4];
00113                 fm[ 5] += v.fm[ 5];
00114                 fm[ 6] += v.fm[ 6];
00115                 fm[ 7] += v.fm[ 7];
00116                 fm[ 8] += v.fm[ 8];
00117                 fm[ 9] += v.fm[ 9];
00118                 fm[10] += v.fm[10];
00119                 fm[11] += v.fm[11];
00120                 fm[12] += v.fm[12];
00121                 fm[13] += v.fm[13];
00122                 fm[14] += v.fm[14];
00123                 fm[15] += v.fm[15];
00124 
00125                 return *this;
00126         }
00127         
00129         inline CMatrix operator- (const CMatrix &v) {
00130         
00131                 fm[ 0] -= v.fm[ 0];
00132                 fm[ 1] -= v.fm[ 1];
00133                 fm[ 2] -= v.fm[ 2];
00134                 fm[ 3] -= v.fm[ 3];
00135                 fm[ 4] -= v.fm[ 4];
00136                 fm[ 5] -= v.fm[ 5];
00137                 fm[ 6] -= v.fm[ 6];
00138                 fm[ 7] -= v.fm[ 7];
00139                 fm[ 8] -= v.fm[ 8];
00140                 fm[ 9] -= v.fm[ 9];
00141                 fm[10] -= v.fm[10];
00142                 fm[11] -= v.fm[11];
00143                 fm[12] -= v.fm[12];
00144                 fm[13] -= v.fm[13];
00145                 fm[14] -= v.fm[14];
00146                 fm[15] -= v.fm[15];
00147 
00148                 return *this;
00149         
00150         }
00151 
00153         inline CMatrix operator= (const CMatrix &v) {
00154 
00155                 fm[ 0] = v.fm[ 0];
00156                 fm[ 1] = v.fm[ 1];
00157                 fm[ 2] = v.fm[ 2];
00158                 fm[ 3] = v.fm[ 3];
00159                 fm[ 4] = v.fm[ 4];
00160                 fm[ 5] = v.fm[ 5];
00161                 fm[ 6] = v.fm[ 6];
00162                 fm[ 7] = v.fm[ 7];
00163                 fm[ 8] = v.fm[ 8];
00164                 fm[ 9] = v.fm[ 9];
00165                 fm[10] = v.fm[10];
00166                 fm[11] = v.fm[11];
00167                 fm[12] = v.fm[12];
00168                 fm[13] = v.fm[13];
00169                 fm[14] = v.fm[14];
00170                 fm[15] = v.fm[15];
00171         
00172                 return *this;
00173         }
00174 
00176         inline CVector3 operator* (const CVector3 &v) {
00177 
00178                 return (CVector3(fm[0]*v.fCoord[0] + fm[1]*v.fCoord[1] + fm[ 2]*v.fCoord[2],
00179                                                  fm[4]*v.fCoord[0] + fm[5]*v.fCoord[1] + fm[ 6]*v.fCoord[2],
00180                                                  fm[8]*v.fCoord[0] + fm[9]*v.fCoord[1] + fm[10]*v.fCoord[2]));
00181         }
00182 
00184         inline void wProduct (const CVector3 &v, zfloat w, zfloat* res) {
00185 
00186                 res[0] = fm[ 0]*v.fCoord[0] + fm[ 1]*v.fCoord[1] + fm[ 2]*v.fCoord[2] + fm[ 3]*w;
00187                 res[1] = fm[ 4]*v.fCoord[0] + fm[ 5]*v.fCoord[1] + fm[ 6]*v.fCoord[2] + fm[ 7]*w;
00188                 res[2] = fm[ 8]*v.fCoord[0] + fm[ 9]*v.fCoord[1] + fm[10]*v.fCoord[2] + fm[11]*w;
00189                 res[3] = fm[12]*v.fCoord[0] + fm[13]*v.fCoord[1] + fm[14]*v.fCoord[2] + fm[15]*w; 
00190 
00191         }
00192 
00193 
00195         inline CMatrix operator* (const CMatrix &v) {           
00196 
00197                 return (CMatrix(fm[ 0]*v.fm[ 0] + fm[ 1]*v.fm[ 4] + fm[ 2]*v.fm[ 8] + fm[ 3]*v.fm[12],
00198                                     fm[ 0]*v.fm[ 1] + fm[ 1]*v.fm[ 5] + fm[ 2]*v.fm[ 9] + fm[ 3]*v.fm[13],
00199                                                 fm[ 0]*v.fm[ 2] + fm[ 1]*v.fm[ 6] + fm[ 2]*v.fm[10] + fm[ 3]*v.fm[14],
00200                                                 fm[ 0]*v.fm[ 3] + fm[ 1]*v.fm[ 7] + fm[ 2]*v.fm[11] + fm[ 3]*v.fm[15],
00201                                                 fm[ 4]*v.fm[ 0] + fm[ 5]*v.fm[ 4] + fm[ 6]*v.fm[ 8] + fm[ 7]*v.fm[12],
00202                                                 fm[ 4]*v.fm[ 1] + fm[ 5]*v.fm[ 5] + fm[ 6]*v.fm[ 9] + fm[ 7]*v.fm[13],
00203                                                 fm[ 4]*v.fm[ 2] + fm[ 5]*v.fm[ 6] + fm[ 6]*v.fm[10] + fm[ 7]*v.fm[14],
00204                                                 fm[ 4]*v.fm[ 3] + fm[ 5]*v.fm[ 7] + fm[ 6]*v.fm[11] + fm[ 7]*v.fm[15],
00205                                                 fm[ 8]*v.fm[ 0] + fm[ 9]*v.fm[ 4] + fm[10]*v.fm[ 8] + fm[11]*v.fm[12],
00206                                                 fm[ 8]*v.fm[ 1] + fm[ 9]*v.fm[ 5] + fm[10]*v.fm[ 9] + fm[11]*v.fm[13],
00207                                                 fm[ 8]*v.fm[ 2] + fm[ 9]*v.fm[ 6] + fm[10]*v.fm[10] + fm[11]*v.fm[14],
00208                                                 fm[ 8]*v.fm[ 3] + fm[ 9]*v.fm[ 7] + fm[10]*v.fm[11] + fm[11]*v.fm[15],
00209                                                 fm[12]*v.fm[ 0] + fm[13]*v.fm[ 4] + fm[14]*v.fm[ 8] + fm[15]*v.fm[12],
00210                                                 fm[12]*v.fm[ 1] + fm[13]*v.fm[ 5] + fm[14]*v.fm[ 9] + fm[15]*v.fm[13],
00211                                                 fm[12]*v.fm[ 2] + fm[13]*v.fm[ 6] + fm[14]*v.fm[10] + fm[15]*v.fm[14],
00212                                                 fm[12]*v.fm[ 3] + fm[13]*v.fm[ 7] + fm[14]*v.fm[11] + fm[15]*v.fm[15]));        
00213         }
00214 
00215 
00217         inline zfloat determinant3 () const {
00218 
00219         return  fm[0] * (fm[5]*fm[10] - fm[6]*fm[9])
00220                    -fm[1] * (fm[4]*fm[10] - fm[6]*fm[8])
00221                    +fm[2] * (fm[4]*fm[ 9] - fm[5]*fm[8]);
00222 
00223         }
00224 
00225 
00226 };
00227 
00228 #endif



SourceForge.net Logo