00001 inline Matrix4By4::Matrix4By4() {
00002 SetToIdentity();
00003 }
00004
00005 inline BOOL Matrix4By4::operator!=( const Matrix4By4& m ) const {
00006 return !Compare( m );
00007 }
00008
00009 inline void Matrix4By4::SetToRotation( const double XDeg,
00010 const double YDeg,
00011 const double ZDeg ) {
00012 SetToIdentity();
00013 AppendRotation( XDeg, YDeg, ZDeg );
00014 }
00015
00016 inline void Matrix4By4::SetToRotation( const Vector3D& vecAngles ) {
00017 SetToIdentity();
00018 AppendRotation( vecAngles );
00019 }
00020
00021 inline void Matrix4By4::SetToScale( const double XScale,
00022 const double YScale,
00023 const double ZScale ) {
00024 SetToIdentity();
00025 AppendScale( XScale, YScale, ZScale );
00026 }
00027
00028 inline void Matrix4By4::SetToScale( const Vector3D& vecScale ) {
00029 SetToIdentity();
00030 AppendScale( vecScale );
00031 }
00032
00033 inline void Matrix4By4::SetToTranslation( const double XTrans,
00034 const double YTrans,
00035 const double ZTrans ) {
00036 SetToIdentity();
00037 AppendTranslation( XTrans, YTrans, ZTrans );
00038 }
00039
00040 inline void Matrix4By4::SetToTranslation(const Vector3D& vecTrans) {
00041 SetToIdentity();
00042 AppendTranslation( vecTrans );
00043 }
00044
00045 Matrix4By4::Matrix4By4(
00046 const double a1_1, const double a1_2, const double a1_3,
00047 const double a2_1, const double a2_2, const double a2_3,
00048 const double a3_1, const double a3_2, const double a3_3,
00049 const double Xt, const double Yt, const double Zt )
00050 {
00051 TRawMem::SetMemBuf(jMatrix, j2klib::TCard1(0), sizeof(jMatrix));
00052 jMatrix[0][0] = a1_1;
00053 jMatrix[0][1] = a1_2;
00054 jMatrix[0][2] = a1_3;
00055 jMatrix[1][0] = a2_1;
00056 jMatrix[1][1] = a2_2;
00057 jMatrix[1][2] = a2_3;
00058 jMatrix[2][0] = a3_1;
00059 jMatrix[2][1] = a3_2;
00060 jMatrix[2][2] = a3_3;
00061 jMatrix[3][0] = Xt;
00062 jMatrix[3][1] = Yt;
00063 jMatrix[3][2] = Zt;
00064 }
00065
00066 Matrix4By4::Matrix4By4( const Matrix4By4& m ) {
00067 TRawMem::CopyMemBuf(jMatrix, mtrxSrc.jMatrix, sizeof(jMatrix));
00068 }
00069
00070 double Matrix4By4::operator[]( const tJ2KMath::EMatrixElems eElem ) const {
00071 return jArray[eElem];
00072 }
00073
00074 double Matrix4By4::operator[]( const tJ2KMath::EMatrixElems eElem ) {
00075 return jArray[eElem];
00076 }
00077
00078 Matrix4By4 operator*( const Matrix4By4& m1, const Matrix4By4& m2 )
00079 {
00080 Matrix4By4 mResult;
00081
00082 mResult.Zero();
00083 for (j2klib::TCard4 c4Outer = 0; c4Outer < 4; c4Outer++)
00084 {
00085 for (j2klib::TCard4 c4Inner = 0; c4Inner < 4; c4Inner++)
00086 {
00087 for (j2klib::TCard4 c4Element = 0; c4Element < 4; c4Element++)
00088 mResult.jMatrix[c4Outer][c4Inner]
00089 += (m1.jMatrix[c4Outer][c4Element]
00090 * m2.jMatrix[c4Element][c4Inner]);
00091 }
00092 }
00093 return mResult;
00094 }
00095
00096 void Matrix4By4::operator*=( const Matrix4By4& m )
00097 {
00098
00099 Matrix4By4 mtrxTmp(*this);
00100
00101
00102 Zero();
00103 for (j2klib::TCard4 c4Outer = 0; c4Outer < 4; c4Outer++)
00104 {
00105 for (j2klib::TCard4 c4Inner = 0; c4Inner < 4; c4Inner++)
00106 {
00107 for (j2klib::TCard4 c4Element = 0; c4Element < 4; c4Element++)
00108 {
00109 jMatrix[c4Outer][c4Inner]
00110 += (mtrxTmp.jMatrix[c4Outer][c4Element]
00111 * mtrxSrc.jMatrix[c4Element][c4Inner]);
00112 }
00113 }
00114 }
00115 }
00116
00117
00118 BOOL
00119 Matrix4By4::operator==(const Matrix4By4& mtrxToTest) const
00120 {
00121
00122 if (TRawMem::eCompareMemBuf
00123 (
00124 mtrxToTest.jMatrix
00125 , jMatrix
00126 , sizeof(jMatrix)))
00127 {
00128 return FALSE;
00129 }
00130 return TRUE;
00131 }
00132
00133
00134 Matrix4By4& Matrix4By4::operator=(const Matrix4By4& mtrxToAssign)
00135 {
00136 if (this == &mtrxToAssign)
00137 return *this;
00138
00139 TRawMem::CopyMemBuf
00140 (
00141 jMatrix
00142 , mtrxToAssign.jMatrix
00143 , sizeof(jMatrix)
00144 );
00145 return *this;
00146 }
00147
00148
00149
00150
00151
00152 void
00153 Matrix4By4::AppendRotation(const Vector3D& vecAngles)
00154 {
00155
00156 T3DVector vecTmp(vecAngles);
00157 vecTmp.ToRadians();
00158
00159
00160 double SinX, SinY, SinZ;
00161 double CosX, CosY, CosZ;
00162 SinX = TMathLib::Sine(vecTmp.X());
00163 CosX = TMathLib::Cosine(vecTmp.X());
00164 SinY = TMathLib::Sine(vecTmp.Y());
00165 CosY = TMathLib::Cosine(vecTmp.Y());
00166 SinZ = TMathLib::Sine(vecTmp.Z());
00167 CosZ = TMathLib::Cosine(vecTmp.Z());
00168
00169
00170 Matrix4By4 mtrxTmp;
00171 mtrxTmp[tJ2KMath::EMatrix_22] = CosX;
00172 mtrxTmp[tJ2KMath::EMatrix_33] = CosX;
00173 mtrxTmp[tJ2KMath::EMatrix_23] = SinX;
00174 mtrxTmp[tJ2KMath::EMatrix_32] = -SinX;
00175 *this *= mtrxTmp;
00176
00177
00178 mtrxTmp.SetToIdentity();
00179 mtrxTmp[tJ2KMath::EMatrix_11] = CosY;
00180 mtrxTmp[tJ2KMath::EMatrix_33] = CosY;
00181 mtrxTmp[tJ2KMath::EMatrix_13] = -SinY;
00182 mtrxTmp[tJ2KMath::EMatrix_31] = SinY;
00183 *this *= mtrxTmp;
00184
00185
00186 mtrxTmp.SetToIdentity();
00187 mtrxTmp[tJ2KMath::EMatrix_11] = CosZ;
00188 mtrxTmp[tJ2KMath::EMatrix_22] = CosZ;
00189 mtrxTmp[tJ2KMath::EMatrix_12] = SinZ;
00190 mtrxTmp[tJ2KMath::EMatrix_21] = -SinZ;
00191 *this *= mtrxTmp;
00192 }
00193
00194 void
00195 Matrix4By4::AppendRotation(const double XAngle
00196 , const double YAngle
00197 , const double ZAngle)
00198 {
00199
00200 double XA = XAngle * kJ2KLib::PI / 180.0;
00201 double YA = YAngle * kJ2KLib::PI / 180.0;
00202 double ZA = ZAngle * kJ2KLib::PI / 180.0;
00203
00204
00205 double SinX, SinY, SinZ;
00206 double CosX, CosY, CosZ;
00207 SinX = TMathLib::Sine(XA);
00208 CosX = TMathLib::Cosine(XA);
00209 SinY = TMathLib::Sine(YA);
00210 CosY = TMathLib::Cosine(YA);
00211 SinZ = TMathLib::Sine(ZA);
00212 CosZ = TMathLib::Cosine(ZA);
00213
00214
00215 Matrix4By4 mtrxTmp;
00216 mtrxTmp[tJ2KMath::EMatrix_22] = CosX;
00217 mtrxTmp[tJ2KMath::EMatrix_33] = CosX;
00218 mtrxTmp[tJ2KMath::EMatrix_23] = SinX;
00219 mtrxTmp[tJ2KMath::EMatrix_32] = -SinX;
00220 *this *= mtrxTmp;
00221
00222
00223 mtrxTmp.SetToIdentity();
00224 mtrxTmp[tJ2KMath::EMatrix_11] = CosY;
00225 mtrxTmp[tJ2KMath::EMatrix_33] = CosY;
00226 mtrxTmp[tJ2KMath::EMatrix_13] = -SinY;
00227 mtrxTmp[tJ2KMath::EMatrix_31] = SinY;
00228 *this *= mtrxTmp;
00229
00230
00231 mtrxTmp.SetToIdentity();
00232 mtrxTmp[tJ2KMath::EMatrix_11] = CosZ;
00233 mtrxTmp[tJ2KMath::EMatrix_22] = CosZ;
00234 mtrxTmp[tJ2KMath::EMatrix_12] = SinZ;
00235 mtrxTmp[tJ2KMath::EMatrix_21] = -SinZ;
00236 *this *= mtrxTmp;
00237 }
00238
00239
00240 void Matrix4By4::AppendScale(const Vector3D& vecScale)
00241 {
00242
00243 Matrix4By4 mtrxTmp;
00244 mtrxTmp[tJ2KMath::EMatrix_11] = vecScale.X();
00245 mtrxTmp[tJ2KMath::EMatrix_22] = vecScale.Y();
00246 mtrxTmp[tJ2KMath::EMatrix_33] = vecScale.Z();
00247
00248
00249 *this *= mtrxTmp;
00250 }
00251
00252 void
00253 Matrix4By4::AppendScale( const double XScale
00254 , const double YScale
00255 , const double ZScale)
00256 {
00257
00258 Matrix4By4 mtrxTmp;
00259 mtrxTmp[tJ2KMath::EMatrix_11] = XScale;
00260 mtrxTmp[tJ2KMath::EMatrix_22] = YScale;
00261 mtrxTmp[tJ2KMath::EMatrix_33] = ZScale;
00262
00263
00264 *this *= mtrxTmp;
00265 }
00266
00267
00268 void Matrix4By4::AppendTranslation(const Vector3D& vecTrans)
00269 {
00270
00271 Matrix4By4 mtrxTmp;
00272 mtrxTmp[tJ2KMath::EMatrix_Xt] = vecTrans.X();
00273 mtrxTmp[tJ2KMath::EMatrix_Yt] = vecTrans.Y();
00274 mtrxTmp[tJ2KMath::EMatrix_Zt] = vecTrans.Z();
00275
00276
00277 *this *= mtrxTmp;
00278 }
00279
00280 void
00281 Matrix4By4::AppendTranslation( const double XTrans
00282 , const double YTrans
00283 , const double ZTrans)
00284 {
00285
00286 Matrix4By4 mtrxTmp;
00287 mtrxTmp[tJ2KMath::EMatrix_Xt] = XTrans;
00288 mtrxTmp[tJ2KMath::EMatrix_Yt] = YTrans;
00289 mtrxTmp[tJ2KMath::EMatrix_Zt] = ZTrans;
00290
00291
00292 *this *= mtrxTmp;
00293 }
00294
00295
00296 void Matrix4By4::SetToIdentity()
00297 {
00298 TRawMem::SetMemBuf(jMatrix, j2klib::TCard1(0), sizeof(jMatrix));
00299 jMatrix[0][0] = 1.0;
00300 jMatrix[1][1] = 1.0;
00301 jMatrix[2][2] = 1.0;
00302 jMatrix[3][3] = 1.0;
00303 }
00304
00305
00306 void Matrix4By4::SetToTransposed(const Matrix4By4& mtrxSrc)
00307 {
00308
00309 for (j2klib::TInt4 i4Outer = 0; i4Outer < 4; i4Outer++)
00310 {
00311 for (j2klib::TInt4 i4Inner = 0; i4Inner < 4; i4Inner++)
00312 {
00313 jMatrix[i4Outer][i4Inner]
00314 = mtrxSrc.jMatrix[i4Inner][i4Outer];
00315 }
00316 }
00317 }
00318
00319
00320 void Matrix4By4::Transform(Vector3D& vecTarget) const
00321 {
00322 double X, Y, Z;
00323
00324 X = (vecTarget.XMag * jMatrix[0][0])
00325 + (vecTarget.YMag * jMatrix[1][0])
00326 + (vecTarget.ZMag * jMatrix[2][0])
00327 + jMatrix[3][0];
00328
00329 Y = (vecTarget.XMag * jMatrix[0][1])
00330 + (vecTarget.YMag * jMatrix[1][1])
00331 + (vecTarget.ZMag * jMatrix[2][1])
00332 + jMatrix[3][1];
00333
00334 Z = (vecTarget.XMag * jMatrix[0][2])
00335 + (vecTarget.YMag * jMatrix[1][2])
00336 + (vecTarget.ZMag * jMatrix[2][2])
00337 + jMatrix[3][2];
00338
00339 vecTarget.XMag = X;
00340 vecTarget.YMag = Y;
00341 vecTarget.ZMag = Z;
00342 }
00343
00344 void
00345 Matrix4By4::Transform(const Vector3D& vecSource, Vector3D& vecTarget) const
00346 {
00347 vecTarget.XMag =
00348 (
00349 (vecSource.XMag * jMatrix[0][0])
00350 + (vecSource.YMag * jMatrix[1][0])
00351 + (vecSource.ZMag * jMatrix[2][0])
00352 + jMatrix[3][0]
00353 );
00354
00355 vecTarget.YMag =
00356 (
00357 (vecSource.XMag * jMatrix[0][1])
00358 + (vecSource.YMag * jMatrix[1][1])
00359 + (vecSource.ZMag * jMatrix[2][1])
00360 + jMatrix[3][1]
00361 );
00362
00363 vecTarget.ZMag =
00364 (
00365 (vecSource.XMag * jMatrix[0][2])
00366 + (vecSource.YMag * jMatrix[1][2])
00367 + (vecSource.ZMag * jMatrix[2][2])
00368 + jMatrix[3][2]
00369 );
00370 }
00371
00372
00373 void Matrix4By4::Transpose()
00374 {
00375 double aTmp[4][4];
00376
00377
00378 TRawMem::CopyMemBuf(aTmp, jMatrix, sizeof(jMatrix));
00379
00380
00381 for (j2klib::TInt4 i4Outer = 0; i4Outer < 4; i4Outer++)
00382 {
00383 for (j2klib::TInt4 i4Inner = 0; i4Inner < 4; i4Inner++)
00384 jMatrix[i4Outer][i4Inner] = aTmp[i4Inner][i4Outer];
00385 }
00386 }
00387
00388 void Matrix4By4::Zero()
00389 {
00390 TRawMem::SetMemBuf(jMatrix, j2klib::TCard1(0), sizeof(jMatrix));
00391 }
00392
00393