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