00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __UT_DMatrix4_h__
00016 #define __UT_DMatrix4_h__
00017
00018 #include "UT_API.h"
00019 #include <iostream.h>
00020 #include "UT_Assert.h"
00021 #include "UT_Axis.h"
00022 #include "UT_Math.h"
00023
00024 class UT_IStream;
00025 class UT_Matrix3;
00026 class UT_Matrix4;
00027 class UT_DMatrix3;
00028 class UT_DMatrix4;
00029 class UT_XformOrder;
00030 class UT_Quaternion;
00031 class UT_Vector3;
00032 class UT_Vector4;
00033
00034
00035 UT_API UT_DMatrix4 operator+(const UT_DMatrix4 &m1,const UT_DMatrix4 &m2);
00036 UT_API UT_DMatrix4 operator-(const UT_DMatrix4 &m1,const UT_DMatrix4 &m2);
00037 UT_API UT_DMatrix4 operator*(const UT_DMatrix4 &m1,const UT_DMatrix4 &m2);
00038 UT_API UT_DMatrix4 operator+(const UT_DMatrix4 &m, const UT_Vector4 &v);
00039 UT_API UT_DMatrix4 operator+(const UT_Vector4 &v, const UT_DMatrix4 &m);
00040 UT_API UT_DMatrix4 operator-(const UT_DMatrix4 &m, const UT_Vector4 &v);
00041 UT_API UT_DMatrix4 operator-(const UT_Vector4 &v, const UT_DMatrix4 &m);
00042 UT_API UT_DMatrix4 operator+(const UT_DMatrix4 &mat, fpreal64 sc);
00043 inline UT_DMatrix4 operator-(const UT_DMatrix4 &mat, fpreal64 sc);
00044 UT_API UT_DMatrix4 operator*(const UT_DMatrix4 &mat, fpreal64 sc);
00045 inline UT_DMatrix4 operator/(const UT_DMatrix4 &mat, fpreal64 sc);
00046 inline UT_DMatrix4 operator+(fpreal64 sc, const UT_DMatrix4 &mat);
00047 UT_API UT_DMatrix4 operator-(fpreal64 sc, const UT_DMatrix4 &mat);
00048 inline UT_DMatrix4 operator*(fpreal64 sc, const UT_DMatrix4 &mat);
00049 UT_API UT_DMatrix4 operator/(fpreal64 sc, const UT_DMatrix4 &mat);
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 class UT_API UT_DMatrix4
00061 {
00062 public:
00063
00064 UT_DMatrix4()
00065 { }
00066
00067 explicit UT_DMatrix4(fpreal64 val)
00068 {
00069 matx[0][0] = val; matx[0][1] = 0; matx[0][2] = 0; matx[0][3] = 0;
00070 matx[1][0] = 0; matx[1][1] = val; matx[1][2] = 0; matx[1][3] = 0;
00071 matx[2][0] = 0; matx[2][1] = 0; matx[2][2] = val; matx[2][3] = 0;
00072 matx[3][0] = 0; matx[3][1] = 0; matx[3][2] = 0; matx[3][3] = val;
00073 }
00074
00075
00076 explicit UT_DMatrix4(const fpreal32 m[4][4])
00077 {
00078 matx[0][0]=m[0][0]; matx[0][1]=m[0][1];
00079 matx[0][2]=m[0][2]; matx[0][3]=m[0][3];
00080
00081 matx[1][0]=m[1][0]; matx[1][1]=m[1][1];
00082 matx[1][2]=m[1][2]; matx[1][3]=m[1][3];
00083
00084 matx[2][0]=m[2][0]; matx[2][1]=m[2][1];
00085 matx[2][2]=m[2][2]; matx[2][3]=m[2][3];
00086
00087 matx[3][0]=m[3][0]; matx[3][1]=m[3][1];
00088 matx[3][2]=m[3][2]; matx[3][3]=m[3][3];
00089 }
00090 explicit UT_DMatrix4(const fpreal64 m[4][4])
00091 {
00092 matx[0][0]=m[0][0]; matx[0][1]=m[0][1];
00093 matx[0][2]=m[0][2]; matx[0][3]=m[0][3];
00094
00095 matx[1][0]=m[1][0]; matx[1][1]=m[1][1];
00096 matx[1][2]=m[1][2]; matx[1][3]=m[1][3];
00097
00098 matx[2][0]=m[2][0]; matx[2][1]=m[2][1];
00099 matx[2][2]=m[2][2]; matx[2][3]=m[2][3];
00100
00101 matx[3][0]=m[3][0]; matx[3][1]=m[3][1];
00102 matx[3][2]=m[3][2]; matx[3][3]=m[3][3];
00103 }
00104
00105
00106
00107
00108 UT_DMatrix4(fpreal64 val00, fpreal64 val01, fpreal64 val02, fpreal64 val03,
00109 fpreal64 val10, fpreal64 val11, fpreal64 val12, fpreal64 val13,
00110 fpreal64 val20, fpreal64 val21, fpreal64 val22, fpreal64 val23,
00111 fpreal64 val30, fpreal64 val31, fpreal64 val32, fpreal64 val33)
00112 {
00113 matx[0][0] = val00; matx[0][1] = val01; matx[0][2] = val02;
00114 matx[0][3] = val03;
00115 matx[1][0] = val10; matx[1][1] = val11; matx[1][2] = val12;
00116 matx[1][3] = val13;
00117 matx[2][0] = val20; matx[2][1] = val21; matx[2][2] = val22;
00118 matx[2][3] = val23;
00119 matx[3][0] = val30; matx[3][1] = val31; matx[3][2] = val32;
00120 matx[3][3] = val33;
00121 }
00122
00123
00124
00125
00126
00127 explicit UT_DMatrix4(const UT_Matrix4 &m);
00128
00129
00130
00131
00132
00133
00134
00135 UT_DMatrix4 &operator=(const UT_Matrix3 &m);
00136 UT_DMatrix4 &operator=(const UT_Matrix4 &m);
00137 UT_DMatrix4 &operator=(const UT_DMatrix3 &m);
00138
00139
00140 UT_DMatrix4 operator-() const
00141 {
00142 return UT_DMatrix4(
00143 -matx[0][0], -matx[0][1], -matx[0][2], -matx[0][3],
00144 -matx[1][0], -matx[1][1], -matx[1][2], -matx[1][3],
00145 -matx[2][0], -matx[2][1], -matx[2][2], -matx[2][3],
00146 -matx[3][0], -matx[3][1], -matx[3][2], -matx[3][3]);
00147 }
00148
00149 inline
00150 UT_DMatrix4 &operator+=(const UT_DMatrix4 &m)
00151 {
00152 matx[0][0]+=m.matx[0][0]; matx[0][1]+=m.matx[0][1];
00153 matx[0][2]+=m.matx[0][2]; matx[0][3]+=m.matx[0][3];
00154
00155 matx[1][0]+=m.matx[1][0]; matx[1][1]+=m.matx[1][1];
00156 matx[1][2]+=m.matx[1][2]; matx[1][3]+=m.matx[1][3];
00157
00158 matx[2][0]+=m.matx[2][0]; matx[2][1]+=m.matx[2][1];
00159 matx[2][2]+=m.matx[2][2]; matx[2][3]+=m.matx[2][3];
00160
00161 matx[3][0]+=m.matx[3][0]; matx[3][1]+=m.matx[3][1];
00162 matx[3][2]+=m.matx[3][2]; matx[3][3]+=m.matx[3][3];
00163 return *this;
00164 }
00165 inline
00166 UT_DMatrix4 &operator-=(const UT_DMatrix4 &m)
00167 {
00168 matx[0][0]-=m.matx[0][0]; matx[0][1]-=m.matx[0][1];
00169 matx[0][2]-=m.matx[0][2]; matx[0][3]-=m.matx[0][3];
00170
00171 matx[1][0]-=m.matx[1][0]; matx[1][1]-=m.matx[1][1];
00172 matx[1][2]-=m.matx[1][2]; matx[1][3]-=m.matx[1][3];
00173
00174 matx[2][0]-=m.matx[2][0]; matx[2][1]-=m.matx[2][1];
00175 matx[2][2]-=m.matx[2][2]; matx[2][3]-=m.matx[2][3];
00176
00177 matx[3][0]-=m.matx[3][0]; matx[3][1]-=m.matx[3][1];
00178 matx[3][2]-=m.matx[3][2]; matx[3][3]-=m.matx[3][3];
00179 return *this;
00180 }
00181 UT_DMatrix4 &operator*=(const UT_DMatrix4 &m);
00182
00183
00184
00185 unsigned operator==(const UT_DMatrix4 &m) const
00186 {
00187 return (&m == this) ? 1U : (
00188 matx[0][0]==m.matx[0][0] && matx[0][1]==m.matx[0][1] &&
00189 matx[0][2]==m.matx[0][2] && matx[0][3]==m.matx[0][3] &&
00190
00191 matx[1][0]==m.matx[1][0] && matx[1][1]==m.matx[1][1] &&
00192 matx[1][2]==m.matx[1][2] && matx[1][3]==m.matx[1][3] &&
00193
00194 matx[2][0]==m.matx[2][0] && matx[2][1]==m.matx[2][1] &&
00195 matx[2][2]==m.matx[2][2] && matx[2][3]==m.matx[2][3] &&
00196
00197 matx[3][0]==m.matx[3][0] && matx[3][1]==m.matx[3][1] &&
00198 matx[3][2]==m.matx[3][2] && matx[3][3]==m.matx[3][3] );
00199 }
00200
00201 unsigned operator!=(const UT_DMatrix4 &m) const
00202 {
00203 return !(*this == m);
00204 }
00205
00206
00207 UT_DMatrix4 &operator= (fpreal v)
00208 {
00209 matx[0][0]= v; matx[0][1]= 0; matx[0][2]= 0; matx[0][3]= 0;
00210 matx[1][0]= 0; matx[1][1]= v; matx[1][2]= 0; matx[1][3]= 0;
00211 matx[2][0]= 0; matx[2][1]= 0; matx[2][2]= v; matx[2][3]= 0;
00212 matx[3][0]= 0; matx[3][1]= 0; matx[3][2]= 0; matx[3][3]= v;
00213 return *this;
00214 }
00215 UT_DMatrix4 &operator*=(fpreal64 scalar)
00216 {
00217 matx[0][0]*=scalar; matx[0][1]*=scalar;
00218 matx[0][2]*=scalar; matx[0][3]*=scalar;
00219
00220 matx[1][0]*=scalar; matx[1][1]*=scalar;
00221 matx[1][2]*=scalar; matx[1][3]*=scalar;
00222
00223 matx[2][0]*=scalar; matx[2][1]*=scalar;
00224 matx[2][2]*=scalar; matx[2][3]*=scalar;
00225
00226 matx[3][0]*=scalar; matx[3][1]*=scalar;
00227 matx[3][2]*=scalar; matx[3][3]*=scalar;
00228 return *this;
00229 }
00230 UT_DMatrix4 &operator/=(fpreal64 scalar)
00231 {
00232 return operator*=( 1/scalar );
00233 }
00234
00235
00236 inline
00237 UT_DMatrix4 &operator=(const UT_Vector4 &vec);
00238 inline
00239 UT_DMatrix4 &operator+=(const UT_Vector4 &vec);
00240 inline
00241 UT_DMatrix4 &operator-=(const UT_Vector4 &vec);
00242
00243
00244
00245
00246 void leftMult( const UT_DMatrix4 &m );
00247 void preMultiply(const UT_DMatrix4 &m) { leftMult(m); }
00248
00249
00250
00251
00252 fpreal64 coFactor(int k, int l) const;
00253
00254 fpreal64 determinant() const
00255 {
00256 return(matx[0][0]*coFactor(0,0) +
00257 matx[0][1]*coFactor(0,1) +
00258 matx[0][2]*coFactor(0,2) +
00259 matx[0][3]*coFactor(0,3) );
00260 }
00261
00262 fpreal64 determinant3() const
00263 {
00264 return(matx[0][0]*
00265 (matx[1][1]*matx[2][2]-matx[1][2]*matx[2][1]) +
00266 matx[0][1]*
00267 (matx[1][2]*matx[2][0]-matx[1][0]*matx[2][2]) +
00268 matx[0][2]*
00269 (matx[1][0]*matx[2][1]-matx[1][1]*matx[2][0]) );
00270
00271 }
00272 fpreal64 trace() const
00273 { return matx[0][0]+matx[1][1]+matx[2][2]+matx[3][3]; }
00274
00275
00276 int invert();
00277
00278
00279 int invert(UT_DMatrix4 &m)const;
00280 int invertKramer();
00281 int invertKramer(UT_DMatrix4 &m)const;
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297 void instance(const UT_Vector3& p, const UT_Vector3& v, fpreal64 s,
00298 const UT_Vector3* s3,
00299 const UT_Vector3* up, const UT_Quaternion* q,
00300 const UT_Vector3* tr, const UT_Quaternion* orient);
00301
00302
00303 void transpose(void)
00304 {
00305 fpreal64 tmp;
00306 tmp=matx[0][1]; matx[0][1]=matx[1][0]; matx[1][0]=tmp;
00307 tmp=matx[0][2]; matx[0][2]=matx[2][0]; matx[2][0]=tmp;
00308 tmp=matx[0][3]; matx[0][3]=matx[3][0]; matx[3][0]=tmp;
00309 tmp=matx[1][2]; matx[1][2]=matx[2][1]; matx[2][1]=tmp;
00310 tmp=matx[1][3]; matx[1][3]=matx[3][1]; matx[3][1]=tmp;
00311 tmp=matx[2][3]; matx[2][3]=matx[3][2]; matx[3][2]=tmp;
00312 }
00313 UT_DMatrix4 transpose(void) const;
00314
00315
00316 unsigned isEqual( const UT_DMatrix4 &m,
00317 fpreal64 tolerance=UT_DTOLERANCE ) const
00318 {
00319 return (&m == this) ? 1U : (
00320 UTisEqual( matx[0][0], m.matx[0][0], tolerance ) &&
00321 UTisEqual( matx[0][1], m.matx[0][1], tolerance ) &&
00322 UTisEqual( matx[0][2], m.matx[0][2], tolerance ) &&
00323 UTisEqual( matx[0][3], m.matx[0][3], tolerance ) &&
00324
00325 UTisEqual( matx[1][0], m.matx[1][0], tolerance ) &&
00326 UTisEqual( matx[1][1], m.matx[1][1], tolerance ) &&
00327 UTisEqual( matx[1][2], m.matx[1][2], tolerance ) &&
00328 UTisEqual( matx[1][3], m.matx[1][3], tolerance ) &&
00329
00330 UTisEqual( matx[2][0], m.matx[2][0], tolerance ) &&
00331 UTisEqual( matx[2][1], m.matx[2][1], tolerance ) &&
00332 UTisEqual( matx[2][2], m.matx[2][2], tolerance ) &&
00333 UTisEqual( matx[2][3], m.matx[2][3], tolerance ) &&
00334
00335 UTisEqual( matx[3][0], m.matx[3][0], tolerance ) &&
00336 UTisEqual( matx[3][1], m.matx[3][1], tolerance ) &&
00337 UTisEqual( matx[3][2], m.matx[3][2], tolerance ) &&
00338 UTisEqual( matx[3][3], m.matx[3][3], tolerance ) );
00339 }
00340
00341
00342
00343
00344
00345
00346 void rotate(UT_Vector3 &axis, fpreal64 theta, int norm=1);
00347 UT_DMatrix4 rotate(UT_Vector3 &axis, fpreal64 theta, int norm=1) const;
00348 static UT_DMatrix4 rotationMat(UT_Vector3 &axis, fpreal64 theta, int norm=1);
00349 void rotate(UT_Axis3::axis a, fpreal64 theta);
00350 UT_DMatrix4 rotate(UT_Axis3::axis a, fpreal64 theta) const;
00351 static UT_DMatrix4 rotationMat(UT_Axis3::axis a, fpreal64 theta);
00352
00353
00354 void prerotate(UT_Vector3 &axis, fpreal64 theta, int norm=1);
00355 UT_DMatrix4 prerotate(UT_Vector3 &axis, fpreal64 theta, int norm=1) const;
00356 void prerotate(UT_Axis3::axis a, fpreal64 theta);
00357 UT_DMatrix4 prerotate(UT_Axis3::axis a, fpreal64 theta) const;
00358
00359
00360
00361 void rotate(fpreal64 rx, fpreal64 ry, fpreal64 rz,
00362 const UT_XformOrder &ord);
00363 UT_DMatrix4 rotate(fpreal64 rx, fpreal64 ry, fpreal64 rz,
00364 const UT_XformOrder &ord) const;
00365
00366
00367 void prerotate(fpreal64 rx, fpreal64 ry, fpreal64 rz,
00368 const UT_XformOrder &ord);
00369 UT_DMatrix4 prerotate(fpreal64 rx, fpreal64 ry, fpreal64 rz,
00370 const UT_XformOrder &ord) const;
00371
00372
00373 void scale(fpreal64 sx, fpreal64 sy, fpreal64 sz, fpreal64 sw = 1.)
00374 {
00375 matx[0][0] *= sx; matx[0][1] *= sy;
00376 matx[0][2] *= sz; matx[0][3] *= sw;
00377
00378 matx[1][0] *= sx; matx[1][1] *= sy;
00379 matx[1][2] *= sz; matx[1][3] *= sw;
00380
00381 matx[2][0] *= sx; matx[2][1] *= sy;
00382 matx[2][2] *= sz; matx[2][3] *= sw;
00383
00384 matx[3][0] *= sx; matx[3][1] *= sy;
00385 matx[3][2] *= sz; matx[3][3] *= sw;
00386 }
00387 UT_DMatrix4 scale(fpreal64 sx, fpreal64 sy, fpreal64 sz, fpreal64 sw = 1.) const;
00388
00389
00390 void prescale(fpreal64 sx, fpreal64 sy, fpreal64 sz, fpreal64 sw = 1.)
00391 {
00392 matx[0][0] *= sx; matx[1][0] *= sy;
00393 matx[2][0] *= sz; matx[3][0] *= sw;
00394
00395 matx[0][1] *= sx; matx[1][1] *= sy;
00396 matx[2][1] *= sz; matx[3][1] *= sw;
00397
00398 matx[0][2] *= sx; matx[1][2] *= sy;
00399 matx[2][2] *= sz; matx[3][2] *= sw;
00400
00401 matx[0][3] *= sx; matx[1][3] *= sy;
00402 matx[2][3] *= sz; matx[3][3] *= sw;
00403 }
00404 UT_DMatrix4 prescale(fpreal64 sx, fpreal64 sy, fpreal64 sz, fpreal64 sw = 1.) const;
00405
00406
00407 void shear(fpreal64 s_xy, fpreal64 s_xz, fpreal64 s_yz)
00408 {
00409 matx[0][0] += matx[0][1]*s_xy + matx[0][2]*s_xz;
00410 matx[0][1] += matx[0][2]*s_yz;
00411
00412 matx[1][0] += matx[1][1]*s_xy + matx[1][2]*s_xz;
00413 matx[1][1] += matx[1][2]*s_yz;
00414
00415 matx[2][0] += matx[2][1]*s_xy + matx[2][2]*s_xz;
00416 matx[2][1] += matx[2][2]*s_yz;
00417
00418 matx[3][0] += matx[3][1]*s_xy + matx[3][2]*s_xz;
00419 matx[3][1] += matx[3][2]*s_yz;
00420 }
00421
00422
00423 void translate(fpreal64 dx, fpreal64 dy, fpreal64 dz = 0.)
00424 {
00425 fpreal64 a;
00426 a = matx[0][3];
00427 matx[0][0] += a*dx; matx[0][1] += a*dy; matx[0][2] += a*dz;
00428 a = matx[1][3];
00429 matx[1][0] += a*dx; matx[1][1] += a*dy; matx[1][2] += a*dz;
00430 a = matx[2][3];
00431 matx[2][0] += a*dx; matx[2][1] += a*dy; matx[2][2] += a*dz;
00432 a = matx[3][3];
00433 matx[3][0] += a*dx; matx[3][1] += a*dy; matx[3][2] += a*dz;
00434 }
00435 UT_DMatrix4 translate(fpreal64 dx, fpreal64 dy, fpreal64 dz = 0.) const;
00436
00437
00438 void pretranslate(fpreal64 dx, fpreal64 dy, fpreal64 dz = 0.)
00439 {
00440 matx[3][0] += matx[0][0]*dx + matx[1][0]*dy + matx[2][0]*dz;
00441 matx[3][1] += matx[0][1]*dx + matx[1][1]*dy + matx[2][1]*dz;
00442 matx[3][2] += matx[0][2]*dx + matx[1][2]*dy + matx[2][2]*dz;
00443 matx[3][3] += matx[0][3]*dx + matx[1][3]*dy + matx[2][3]*dz;
00444 }
00445 UT_DMatrix4 pretranslate(fpreal64 dx, fpreal64 dy, fpreal64 dz = 0.) const;
00446
00447
00448
00449
00450
00451
00452
00453 void changeSpace(UT_Vector3 &iSrc, UT_Vector3 &jSrc,
00454 UT_Vector3 &iDest,UT_Vector3 &jDest,
00455 int norm=1);
00456 UT_DMatrix4 changeSpace(UT_Vector3 &iSrc, UT_Vector3 &jSrc,
00457 UT_Vector3 &iDest,UT_Vector3 &jDest,
00458 int norm=1) const;
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468 void xform(const UT_XformOrder &order,
00469 fpreal64 tx=0., fpreal64 ty=0., fpreal64 tz=0.,
00470 fpreal64 rx=0., fpreal64 ry=0., fpreal64 rz=0.,
00471 fpreal64 sx=1., fpreal64 sy=1., fpreal64 sz=1.,
00472 fpreal64 px=0., fpreal64 py=0., fpreal64 pz=0.,
00473 int reverse=0);
00474 UT_DMatrix4 xform(const UT_XformOrder &order,
00475 fpreal64 tx=0., fpreal64 ty=0., fpreal64 tz=0.,
00476 fpreal64 rx=0., fpreal64 ry=0., fpreal64 rz=0.,
00477 fpreal64 sx=1., fpreal64 sy=1., fpreal64 sz=1.,
00478 fpreal64 px=0., fpreal64 py=0., fpreal64 pz=0.,
00479 int reverse=0) const;
00480
00481
00482 void xform(const UT_XformOrder &order,
00483 fpreal64 tx, fpreal64 ty, fpreal64 tz,
00484 fpreal64 rx, fpreal64 ry, fpreal64 rz,
00485 fpreal64 sx, fpreal64 sy, fpreal64 sz,
00486 fpreal64 s_xy, fpreal64 s_xz, fpreal64 s_yz,
00487 fpreal64 px, fpreal64 py, fpreal64 pz,
00488 int reverse=0);
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501 enum applyType { BEFORE=1, EQUAL=2, AFTER=4, BEFORE_EQUAL=4, AFTER_EQUAL=6};
00502 void xform(const UT_XformOrder &order,
00503 applyType type, char limit,
00504 fpreal64 tx, fpreal64 ty, fpreal64 tz,
00505 fpreal64 rx, fpreal64 ry, fpreal64 rz,
00506 fpreal64 sx, fpreal64 sy, fpreal64 sz,
00507 fpreal64 px, fpreal64 py, fpreal64 pz);
00508
00509 void rotate(const UT_XformOrder &order,
00510 applyType type, char limit,
00511 fpreal64 rx, fpreal64 ry, fpreal64 rz);
00512
00513
00514 inline
00515 void getTranslates(UT_Vector3 &translates) const;
00516 inline
00517 void setTranslates(const UT_Vector3 &translates);
00518
00519
00520
00521
00522
00523
00524
00525 int explode(const UT_XformOrder &order,
00526 UT_Vector3 &r, UT_Vector3 &s, UT_Vector3 &t,
00527 UT_Vector3 *shears = 0) const;
00528
00529
00530 int explode(const UT_XformOrder &order,
00531 UT_Vector3 &r, UT_Vector3 &s,
00532 UT_Vector3 &t, const UT_Vector3 &p,
00533 UT_Vector3 *shears = 0) const;
00534
00535 void extractRotate(UT_Matrix3 &dst) const;
00536 void extractRotate(UT_DMatrix3 &dst) const;
00537
00538
00539
00540
00541
00542 void stretch(UT_Vector3 &v, fpreal64 amount, int norm=1);
00543 UT_DMatrix4 stretch(UT_Vector3 &v, fpreal64 amount, int norm=1) const;
00544
00545 fpreal64 dot(unsigned i, unsigned j) const
00546 {
00547 return (i <= 3 && j <= 3) ?
00548 matx[i][0]*matx[j][0] + matx[i][1]*matx[j][1] +
00549 matx[i][2]*matx[j][2] + matx[i][3]*matx[j][3] : 0;
00550 }
00551
00552
00553 void identity() { *this = 1; }
00554
00555 void zero() { *this = 0; }
00556
00557 int isIdentity() const
00558 {
00559
00560 return(
00561 matx[0][0]==1.0 && matx[0][1]==0.0
00562 && matx[0][2]==0.0 && matx[0][3]==0.0 &&
00563 matx[1][0]==0.0 && matx[1][1]==1.0
00564 && matx[1][2]==0.0 && matx[1][3]==0.0 &&
00565 matx[2][0]==0.0 && matx[2][1]==0.0
00566 && matx[2][2]==1.0 && matx[2][3]==0.0 &&
00567 matx[3][0]==0.0 && matx[3][1]==0.0
00568 && matx[3][2]==0.0 && matx[3][3]==1.0
00569 );
00570 }
00571
00572
00573 const fpreal64 *data(void) const
00574 { return (const fpreal64 *)&matx[0][0]; }
00575 fpreal64 *data(void)
00576 { return (fpreal64 *)&matx[0][0]; }
00577
00578
00579 inline
00580 fpreal64 &operator()(unsigned row, unsigned col)
00581 {
00582 UT_ASSERT_P(row < 4 && col < 4);
00583 return matx[row][col];
00584 }
00585 inline
00586 fpreal64 operator()(unsigned row, unsigned col) const
00587 {
00588 UT_ASSERT_P(row < 4 && col < 4);
00589 return matx[row][col];
00590 }
00591
00592
00593
00594
00595 fpreal64 *operator()(unsigned row)
00596 {
00597 UT_ASSERT_P(row < 4);
00598 return matx[row];
00599 }
00600 const fpreal64 *operator()(unsigned row) const
00601 {
00602 UT_ASSERT_P(row < 4);
00603 return matx[row];
00604 }
00605 inline
00606 UT_Vector4 operator[](unsigned row) const;
00607
00608
00609
00610
00611 fpreal64 getEuclideanNorm() const
00612 { return SYSsqrt(getEuclideanNorm2()); }
00613
00614 fpreal64 getEuclideanNorm2() const;
00615
00616
00617
00618 int save(ostream &os, int binary) const;
00619 bool load(UT_IStream &is);
00620
00621 void outAsciiNoName(ostream &os) const;
00622 bool inAsciiNoName(UT_IStream &is);
00623
00624 static const UT_DMatrix4 &getIdentityMatrix();
00625
00626
00627 friend ostream &operator<<(ostream &os, const UT_DMatrix4 &v)
00628 {
00629 os << className() << ' ';
00630 v.outAsciiNoName(os);
00631 return os;
00632 }
00633
00634 fpreal64 matx[4][4];
00635
00636 private:
00637 static const char *className(void);
00638 };
00639
00640 #include "UT_Vector4.h"
00641
00642 inline
00643 UT_DMatrix4 &UT_DMatrix4::operator=(const UT_Vector4 &vec)
00644 {
00645 matx[0][0] = matx[0][1] = matx[0][2] = matx[0][3] = vec.x();
00646 matx[1][0] = matx[1][1] = matx[1][2] = matx[1][3] = vec.y();
00647 matx[2][0] = matx[2][1] = matx[2][2] = matx[2][3] = vec.z();
00648 matx[3][0] = matx[3][1] = matx[3][2] = matx[3][3] = vec.w();
00649 return *this;
00650 }
00651
00652 inline
00653 UT_DMatrix4 &UT_DMatrix4::operator+=(const UT_Vector4 &vec)
00654 {
00655 fpreal64 x = vec.x(); fpreal64 y = vec.y();
00656 fpreal64 z = vec.z(); fpreal64 w = vec.w();
00657 matx[0][0]+=x; matx[0][1]+=x; matx[0][2]+=x; matx[0][3]+=x;
00658 matx[1][0]+=y; matx[1][1]+=y; matx[1][2]+=y; matx[1][3]+=y;
00659 matx[2][0]+=z; matx[2][1]+=z; matx[2][2]+=z; matx[2][3]+=z;
00660 matx[3][0]+=w; matx[3][1]+=w; matx[3][2]+=w; matx[3][3]+=w;
00661 return *this;
00662 }
00663
00664 inline
00665 UT_DMatrix4 &UT_DMatrix4::operator-=(const UT_Vector4 &vec)
00666 {
00667 fpreal64 x = vec.x(); fpreal64 y = vec.y();
00668 fpreal64 z = vec.z(); fpreal64 w = vec.w();
00669 matx[0][0]-=x; matx[0][1]-=x; matx[0][2]-=x; matx[0][3]-=x;
00670 matx[1][0]-=y; matx[1][1]-=y; matx[1][2]-=y; matx[1][3]-=y;
00671 matx[2][0]-=z; matx[2][1]-=z; matx[2][2]-=z; matx[2][3]-=z;
00672 matx[3][0]-=w; matx[3][1]-=w; matx[3][2]-=w; matx[3][3]-=w;
00673 return *this;
00674 }
00675
00676 inline
00677 UT_Vector4 UT_DMatrix4::operator[](unsigned row) const
00678 {
00679 return UT_Vector4(matx[row]);
00680 }
00681
00682 inline void UT_DMatrix4::getTranslates(UT_Vector3 &translates) const
00683 {
00684 translates.x() = (fpreal) matx[3][0];
00685 translates.y() = (fpreal) matx[3][1];
00686 translates.z() = (fpreal) matx[3][2];
00687 }
00688
00689 inline void UT_DMatrix4::setTranslates(const UT_Vector3 &translates)
00690 {
00691 matx[3][0] = translates.x();
00692 matx[3][1] = translates.y();
00693 matx[3][2] = translates.z();
00694 }
00695
00696
00697
00698 inline
00699 UT_DMatrix4 operator*(fpreal64 sc, const UT_DMatrix4 &m1)
00700 {
00701 return m1*sc;
00702 }
00703
00704 inline
00705 UT_DMatrix4 operator/(const UT_DMatrix4 &m1, fpreal64 scalar)
00706 {
00707 return m1 * (1.0/scalar);
00708 }
00709
00710
00711 #endif