00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 INLINE_LINMATH const FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3)::
00028 ident_mat() {
00029 return _ident_mat;
00030 }
00031
00032
00033
00034
00035
00036
00037 INLINE_LINMATH FLOATNAME(LMatrix3)::
00038 FLOATNAME(LMatrix3)() {
00039 }
00040
00041
00042
00043
00044
00045
00046 INLINE_LINMATH FLOATNAME(LMatrix3)::
00047 FLOATNAME(LMatrix3)(const FLOATNAME(LMatrix3) ©) {
00048 memcpy(_m.data,copy._m.data,sizeof(_m.data));
00049
00050 }
00051
00052
00053
00054
00055
00056
00057 INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3)::
00058 operator = (const FLOATNAME(LMatrix3) ©) {
00059 memcpy(_m.data,copy._m.data,sizeof(_m.data));
00060
00061
00062
00063 return *this;
00064 }
00065
00066
00067
00068
00069
00070
00071 INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3)::
00072 operator = (FLOATTYPE fill_value) {
00073 fill(fill_value);
00074 return *this;
00075 }
00076
00077
00078
00079
00080
00081
00082 INLINE_LINMATH FLOATNAME(LMatrix3)::
00083 FLOATNAME(LMatrix3)(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02,
00084 FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12,
00085 FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22) {
00086 _m.m._00 = e00;
00087 _m.m._01 = e01;
00088 _m.m._02 = e02;
00089 _m.m._10 = e10;
00090 _m.m._11 = e11;
00091 _m.m._12 = e12;
00092 _m.m._20 = e20;
00093 _m.m._21 = e21;
00094 _m.m._22 = e22;
00095
00096
00097
00098
00099 }
00100
00101
00102
00103
00104
00105
00106 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00107 set(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02,
00108 FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12,
00109 FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22) {
00110 _m.m._00 = e00;
00111 _m.m._01 = e01;
00112 _m.m._02 = e02;
00113 _m.m._10 = e10;
00114 _m.m._11 = e11;
00115 _m.m._12 = e12;
00116 _m.m._20 = e20;
00117 _m.m._21 = e21;
00118 _m.m._22 = e22;
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 }
00131
00132
00133
00134
00135
00136
00137
00138 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00139 set_row(int row, const FLOATNAME(LVecBase3) &v) {
00140 (*this)(row, 0) = v._v.v._0;
00141 (*this)(row, 1) = v._v.v._1;
00142 (*this)(row, 2) = v._v.v._2;
00143 }
00144
00145
00146
00147
00148
00149
00150
00151 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00152 set_col(int col, const FLOATNAME(LVecBase3) &v) {
00153 (*this)(0, col) = v._v.v._0;
00154 (*this)(1, col) = v._v.v._1;
00155 (*this)(2, col) = v._v.v._2;
00156 }
00157
00158
00159
00160
00161
00162
00163
00164 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00165 set_row(int row, const FLOATNAME(LVecBase2) &v) {
00166 (*this)(row, 0) = v._v.v._0;
00167 (*this)(row, 1) = v._v.v._1;
00168 }
00169
00170
00171
00172
00173
00174
00175
00176 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00177 set_col(int col, const FLOATNAME(LVecBase2) &v) {
00178 (*this)(0, col) = v._v.v._0;
00179 (*this)(1, col) = v._v.v._1;
00180 }
00181
00182
00183
00184
00185
00186
00187
00188 INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix3)::
00189 get_row(int row) const {
00190 return FLOATNAME(LVecBase3)((*this)(row, 0), (*this)(row, 1), (*this)(row, 2));
00191 }
00192
00193 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00194 get_row(FLOATNAME(LVecBase3) &result_vec,int row) const {
00195 result_vec._v.v._0 = (*this)(row, 0);
00196 result_vec._v.v._1 = (*this)(row, 1);
00197 result_vec._v.v._2 = (*this)(row, 2);
00198 }
00199
00200
00201
00202
00203
00204
00205
00206 INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix3)::
00207 get_col(int col) const {
00208 return FLOATNAME(LVecBase3)((*this)(0, col), (*this)(1, col), (*this)(2, col));
00209 }
00210
00211
00212
00213
00214
00215
00216
00217 INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LMatrix3)::
00218 get_row2(int row) const {
00219 return FLOATNAME(LVecBase2)((*this)(row, 0), (*this)(row, 1));
00220 }
00221
00222
00223
00224
00225
00226
00227
00228 INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LMatrix3)::
00229 get_col2(int col) const {
00230 return FLOATNAME(LVecBase2)((*this)(0, col), (*this)(1, col));
00231 }
00232
00233
00234
00235
00236
00237
00238 INLINE_LINMATH FLOATTYPE &FLOATNAME(LMatrix3)::
00239 operator () (int row, int col) {
00240 nassertr(row >= 0 && row < 3 && col >= 0 && col < 3, _m.data[0]);
00241 return _m.data[row * 3 + col];
00242 }
00243
00244
00245
00246
00247
00248
00249 INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix3)::
00250 operator () (int row, int col) const {
00251 nassertr(row >= 0 && row < 3 && col >= 0 && col < 3, 0.0);
00252 return _m.data[row * 3 + col];
00253 }
00254
00255
00256
00257
00258
00259
00260
00261 INLINE_LINMATH bool FLOATNAME(LMatrix3)::
00262 is_nan() const {
00263 return
00264 cnan(_m.data[0]) || cnan(_m.data[1]) || cnan(_m.data[2]) ||
00265 cnan(_m.data[3]) || cnan(_m.data[4]) || cnan(_m.data[5]) ||
00266 cnan(_m.data[6]) || cnan(_m.data[7]) || cnan(_m.data[8]);
00267 }
00268
00269
00270
00271
00272
00273
00274 INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix3)::
00275 get_cell(int row, int col) const {
00276 nassertr(row >= 0 && row < 3 && col >= 0 && col < 3, 0.0);
00277 return _m.data[row * 3 + col];
00278 }
00279
00280
00281
00282
00283
00284
00285 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00286 set_cell(int row, int col, FLOATTYPE value) {
00287 nassertv(row >= 0 && row < 3 && col >= 0 && col < 3);
00288 _m.data[row * 3 + col] = value;
00289 }
00290
00291
00292
00293
00294
00295
00296
00297
00298 INLINE_LINMATH const FLOATTYPE *FLOATNAME(LMatrix3)::
00299 get_data() const {
00300 return _m.data;
00301 }
00302
00303
00304
00305
00306
00307
00308 INLINE_LINMATH int FLOATNAME(LMatrix3)::
00309 get_num_components() const {
00310 return 9;
00311 }
00312
00313
00314
00315
00316
00317
00318
00319 INLINE_LINMATH FLOATNAME(LMatrix3)::iterator FLOATNAME(LMatrix3)::
00320 begin() {
00321 return _m.data;
00322 }
00323
00324
00325
00326
00327
00328
00329
00330 INLINE_LINMATH FLOATNAME(LMatrix3)::iterator FLOATNAME(LMatrix3)::
00331 end() {
00332 return begin() + get_num_components();
00333 }
00334
00335
00336
00337
00338
00339
00340
00341 INLINE_LINMATH FLOATNAME(LMatrix3)::const_iterator FLOATNAME(LMatrix3)::
00342 begin() const {
00343 return _m.data;
00344 }
00345
00346
00347
00348
00349
00350
00351
00352 INLINE_LINMATH FLOATNAME(LMatrix3)::const_iterator FLOATNAME(LMatrix3)::
00353 end() const {
00354 return begin() + get_num_components();
00355 }
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366 INLINE_LINMATH bool FLOATNAME(LMatrix3)::
00367 operator < (const FLOATNAME(LMatrix3) &other) const {
00368 return compare_to(other) < 0;
00369 }
00370
00371
00372
00373
00374
00375
00376 INLINE_LINMATH bool FLOATNAME(LMatrix3)::
00377 operator == (const FLOATNAME(LMatrix3) &other) const {
00378 return compare_to(other) == 0;
00379 }
00380
00381
00382
00383
00384
00385
00386 INLINE_LINMATH bool FLOATNAME(LMatrix3)::
00387 operator != (const FLOATNAME(LMatrix3) &other) const {
00388 return !operator == (other);
00389 }
00390
00391
00392
00393
00394
00395
00396
00397 INLINE_LINMATH int FLOATNAME(LMatrix3)::
00398 compare_to(const FLOATNAME(LMatrix3) &other) const {
00399 return compare_to(other, NEARLY_ZERO(FLOATTYPE));
00400 }
00401
00402 #define VECTOR3_MATRIX3_PRODUCT(v_res, v, mat) \
00403 v_res._v.v._0 = v._v.v._0*mat._m.m._00 + v._v.v._1*mat._m.m._10 + v._v.v._2*mat._m.m._20; \
00404 v_res._v.v._1 = v._v.v._0*mat._m.m._01 + v._v.v._1*mat._m.m._11 + v._v.v._2*mat._m.m._21; \
00405 v_res._v.v._2 = v._v.v._0*mat._m.m._02 + v._v.v._1*mat._m.m._12 + v._v.v._2*mat._m.m._22;
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416 INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix3)::
00417 xform(const FLOATNAME(LVecBase3) &v) const {
00418 FLOATNAME(LVecBase3) v_res;
00419
00420
00421
00422 VECTOR3_MATRIX3_PRODUCT(v_res, v,(*this));
00423
00424
00425
00426 return v_res;
00427
00428
00429
00430
00431 }
00432
00433
00434
00435
00436
00437
00438
00439
00440 INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LMatrix3)::
00441 xform_point(const FLOATNAME(LVecBase2) &v) const {
00442
00443 FLOATNAME(LVecBase2) v_res;
00444
00445
00446
00447 v_res._v.v._0 = v._v.v._0*_m.m._00 + v._v.v._1*_m.m._10 + _m.m._20;
00448 v_res._v.v._1 = v._v.v._0*_m.m._01 + v._v.v._1*_m.m._11 + _m.m._21;
00449
00450 return v_res;
00451
00452
00453
00454 }
00455
00456
00457
00458
00459
00460
00461
00462
00463 INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LMatrix3)::
00464 xform_vec(const FLOATNAME(LVecBase2) &v) const {
00465
00466 FLOATNAME(LVecBase2) v_res;
00467
00468
00469
00470 v_res._v.v._0 = v._v.v._0*_m.m._00 + v._v.v._1*_m.m._10;
00471 v_res._v.v._1 = v._v.v._0*_m.m._01 + v._v.v._1*_m.m._11;
00472
00473 return v_res;
00474
00475
00476
00477 }
00478
00479
00480
00481
00482
00483
00484
00485 INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix3)::
00486 mult_cel(const FLOATNAME(LMatrix3) &other, int row, int col) const {
00487 return get_row(row).dot(other.get_col(col));
00488 }
00489
00490
00491 #define MATRIX3_PRODUCT(res, a, b) \
00492 res._m.m._00 = a._m.m._00*b._m.m._00 + a._m.m._01*b._m.m._10 + a._m.m._02*b._m.m._20; \
00493 res._m.m._01 = a._m.m._00*b._m.m._01 + a._m.m._01*b._m.m._11 + a._m.m._02*b._m.m._21; \
00494 res._m.m._02 = a._m.m._00*b._m.m._02 + a._m.m._01*b._m.m._12 + a._m.m._02*b._m.m._22; \
00495 res._m.m._10 = a._m.m._10*b._m.m._00 + a._m.m._11*b._m.m._10 + a._m.m._12*b._m.m._20; \
00496 res._m.m._11 = a._m.m._10*b._m.m._01 + a._m.m._11*b._m.m._11 + a._m.m._12*b._m.m._21; \
00497 res._m.m._12 = a._m.m._10*b._m.m._02 + a._m.m._11*b._m.m._12 + a._m.m._12*b._m.m._22; \
00498 res._m.m._20 = a._m.m._20*b._m.m._00 + a._m.m._21*b._m.m._10 + a._m.m._22*b._m.m._20; \
00499 res._m.m._21 = a._m.m._20*b._m.m._01 + a._m.m._21*b._m.m._11 + a._m.m._22*b._m.m._21; \
00500 res._m.m._22 = a._m.m._20*b._m.m._02 + a._m.m._21*b._m.m._12 + a._m.m._22*b._m.m._22;
00501
00502
00503
00504
00505
00506
00507
00508 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
00509 operator * (const FLOATNAME(LMatrix3) &other) const {
00510 FLOATNAME(LMatrix3) t;
00511
00512 MATRIX3_PRODUCT(t,(*this),other);
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545 return t;
00546 }
00547
00548
00549 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00550 multiply(const FLOATNAME(LMatrix3) &other1, const FLOATNAME(LMatrix3) &other2) {
00551
00552
00553
00554 #ifdef _DEBUG
00555 assert((&other1 != this) && (&other2 != this));
00556 #endif
00557
00558 MATRIX3_PRODUCT((*this),other1,other2);
00559 }
00560
00561
00562 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00563 scale_multiply(const FLOATNAME(LVecBase3) &scale_vector,const FLOATNAME(LMatrix3) &other_mat) {
00564 #ifdef _DEBUG
00565 assert(&other_mat != this);
00566 #endif
00567
00568
00569
00570 _m.m._00 = other_mat._m.m._00 * scale_vector._v.v._0;
00571 _m.m._01 = other_mat._m.m._01 * scale_vector._v.v._0;
00572 _m.m._02 = other_mat._m.m._02 * scale_vector._v.v._0;
00573
00574 _m.m._10 = other_mat._m.m._10 * scale_vector._v.v._1;
00575 _m.m._11 = other_mat._m.m._11 * scale_vector._v.v._1;
00576 _m.m._12 = other_mat._m.m._12 * scale_vector._v.v._1;
00577
00578 _m.m._20 = other_mat._m.m._20 * scale_vector._v.v._2;
00579 _m.m._21 = other_mat._m.m._21 * scale_vector._v.v._2;
00580 _m.m._22 = other_mat._m.m._22 * scale_vector._v.v._2;
00581 }
00582
00583
00584
00585
00586
00587
00588 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
00589 operator * (FLOATTYPE scalar) const {
00590 FLOATNAME(LMatrix3) t;
00591
00592 t._m.m._00 = _m.m._00 * scalar;
00593 t._m.m._01 = _m.m._01 * scalar;
00594 t._m.m._02 = _m.m._02 * scalar;
00595
00596 t._m.m._10 = _m.m._10 * scalar;
00597 t._m.m._11 = _m.m._11 * scalar;
00598 t._m.m._12 = _m.m._12 * scalar;
00599
00600 t._m.m._20 = _m.m._20 * scalar;
00601 t._m.m._21 = _m.m._21 * scalar;
00602 t._m.m._22 = _m.m._22 * scalar;
00603
00604 return t;
00605 }
00606
00607
00608
00609
00610
00611
00612 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
00613 operator / (FLOATTYPE scalar) const {
00614 FLOATTYPE recip_scalar = 1.0f/scalar;
00615 return (*this) * recip_scalar;
00616 }
00617
00618
00619
00620
00621
00622
00623 INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3)::
00624 operator += (const FLOATNAME(LMatrix3) &other) {
00625 _m.m._00 += other._m.m._00;
00626 _m.m._01 += other._m.m._01;
00627 _m.m._02 += other._m.m._02;
00628
00629 _m.m._10 += other._m.m._10;
00630 _m.m._11 += other._m.m._11;
00631 _m.m._12 += other._m.m._12;
00632
00633 _m.m._20 += other._m.m._20;
00634 _m.m._21 += other._m.m._21;
00635 _m.m._22 += other._m.m._22;
00636
00637 return *this;
00638 }
00639
00640
00641
00642
00643
00644
00645 INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3)::
00646 operator -= (const FLOATNAME(LMatrix3) &other) {
00647 _m.m._00 -= other._m.m._00;
00648 _m.m._01 -= other._m.m._01;
00649 _m.m._02 -= other._m.m._02;
00650
00651 _m.m._10 -= other._m.m._10;
00652 _m.m._11 -= other._m.m._11;
00653 _m.m._12 -= other._m.m._12;
00654
00655 _m.m._20 -= other._m.m._20;
00656 _m.m._21 -= other._m.m._21;
00657 _m.m._22 -= other._m.m._22;
00658
00659 return *this;
00660 }
00661
00662
00663
00664
00665
00666
00667 INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3)::
00668 operator *= (const FLOATNAME(LMatrix3) &other) {
00669 (*this) = (*this) * other;
00670
00671
00672 return *this;
00673 }
00674
00675
00676
00677
00678
00679
00680 INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3)::
00681 operator *= (FLOATTYPE scalar) {
00682 _m.m._00 *= scalar;
00683 _m.m._01 *= scalar;
00684 _m.m._02 *= scalar;
00685
00686 _m.m._10 *= scalar;
00687 _m.m._11 *= scalar;
00688 _m.m._12 *= scalar;
00689
00690 _m.m._20 *= scalar;
00691 _m.m._21 *= scalar;
00692 _m.m._22 *= scalar;
00693
00694 return *this;
00695 }
00696
00697
00698
00699
00700
00701
00702 INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3)::
00703 operator /= (FLOATTYPE scalar) {
00704 FLOATTYPE recip_scalar = 1.0f/scalar;
00705 _m.m._00 *= recip_scalar;
00706 _m.m._01 *= recip_scalar;
00707 _m.m._02 *= recip_scalar;
00708
00709 _m.m._10 *= recip_scalar;
00710 _m.m._11 *= recip_scalar;
00711 _m.m._12 *= recip_scalar;
00712
00713 _m.m._20 *= recip_scalar;
00714 _m.m._21 *= recip_scalar;
00715 _m.m._22 *= recip_scalar;
00716
00717 return *this;
00718 }
00719
00720
00721
00722
00723
00724
00725 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00726 transpose_from(const FLOATNAME(LMatrix3) &other) {
00727 _m.m._00 = other._m.m._00;
00728 _m.m._01 = other._m.m._10;
00729 _m.m._02 = other._m.m._20;
00730
00731 _m.m._10 = other._m.m._01;
00732 _m.m._11 = other._m.m._11;
00733 _m.m._12 = other._m.m._21;
00734
00735 _m.m._20 = other._m.m._02;
00736 _m.m._21 = other._m.m._12;
00737 _m.m._22 = other._m.m._22;
00738 }
00739
00740
00741
00742
00743
00744
00745
00746 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00747 transpose_in_place() {
00748
00749
00750
00751 #define SWAP__(x,y) { FLOATTYPE temp = (x); (x) = (y); (y) = temp;}
00752 SWAP__(_m.m._01,_m.m._10);
00753 SWAP__(_m.m._02,_m.m._20);
00754 SWAP__(_m.m._12,_m.m._21);
00755 #undef SWAP__
00756 }
00757
00758
00759
00760
00761 #define DET2(E00,E01,E10,E11) ((E00)*(E11) - (E10)*(E01))
00762 #define MATRIX3_DETERMINANT(mat) \
00763 ( (mat)._00 * DET2((mat)._11,(mat)._12,(mat)._21,(mat)._22) \
00764 -(mat)._01 * DET2((mat)._10,(mat)._12,(mat)._20,(mat)._22) \
00765 +(mat)._02 * DET2((mat)._10,(mat)._11,(mat)._20,(mat)._21))
00766
00767
00768
00769
00770
00771
00772
00773 INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix3)::
00774 det2(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e10, FLOATTYPE e11) const {
00775
00776 return DET2(e00,e01,e10,e11);
00777 }
00778
00779
00780
00781
00782
00783
00784 INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix3)::
00785 determinant() const {
00786
00787
00788
00789
00790
00791
00792
00793 return MATRIX3_DETERMINANT(_m.m);
00794 }
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812 INLINE_LINMATH bool FLOATNAME(LMatrix3)::
00813 invert_from(const FLOATNAME(LMatrix3) &other) {
00814
00815 FLOATTYPE other_det = MATRIX3_DETERMINANT(other._m.m);
00816
00817
00818
00819
00820 if (IS_THRESHOLD_ZERO(other_det, (NEARLY_ZERO(FLOATTYPE) * NEARLY_ZERO(FLOATTYPE)))) {
00821
00822 #ifdef NOTIFY_DEBUG
00823 linmath_cat.warning() << "Tried to invert singular LMatrix3.\n";
00824 #endif
00825 (*this) = ident_mat();
00826 return false;
00827 }
00828
00829 other_det = 1.0f / other_det;
00830 _m.m._00 = other_det * DET2(other._m.m._11, other._m.m._12, other._m.m._21, other._m.m._22);
00831 _m.m._10 = -other_det * DET2(other._m.m._10, other._m.m._12, other._m.m._20, other._m.m._22);
00832 _m.m._20 = other_det * DET2(other._m.m._10, other._m.m._11, other._m.m._20, other._m.m._21);
00833
00834 _m.m._01 = -other_det * DET2(other._m.m._01, other._m.m._02, other._m.m._21, other._m.m._22);
00835 _m.m._11 = other_det * DET2(other._m.m._00, other._m.m._02, other._m.m._20, other._m.m._22);
00836 _m.m._21 = -other_det * DET2(other._m.m._00, other._m.m._01, other._m.m._20, other._m.m._21);
00837
00838 _m.m._02 = other_det * DET2(other._m.m._01, other._m.m._02, other._m.m._11, other._m.m._12);
00839 _m.m._12 = -other_det * DET2(other._m.m._00, other._m.m._02, other._m.m._10, other._m.m._12);
00840 _m.m._22 = other_det * DET2(other._m.m._00, other._m.m._01, other._m.m._10, other._m.m._11);
00841
00842 return true;
00843 }
00844
00845
00846
00847
00848
00849
00850
00851
00852 INLINE_LINMATH bool FLOATNAME(LMatrix3)::
00853 invert_in_place() {
00854 FLOATNAME(LMatrix3) temp = (*this);
00855 return invert_from(temp);
00856 }
00857
00858
00859
00860
00861
00862
00863
00864 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
00865 translate_mat(const FLOATNAME(LVecBase2) &trans) {
00866 return FLOATNAME(LMatrix3)(1.0f, 0.0f, 0.0f,
00867 0.0f, 1.0f, 0.0f,
00868 trans._v.v._0, trans._v.v._1, 1.0f);
00869 }
00870
00871
00872
00873
00874
00875
00876
00877 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
00878 translate_mat(FLOATTYPE tx, FLOATTYPE ty) {
00879 return FLOATNAME(LMatrix3)(1.0f, 0.0f, 0.0f,
00880 0.0f, 1.0f, 0.0f,
00881 tx, ty, 1.0f);
00882 }
00883
00884
00885
00886
00887
00888
00889
00890 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
00891 rotate_mat(FLOATTYPE angle) {
00892 FLOATTYPE angle_rad=deg_2_rad(angle);
00893 FLOATTYPE s,c;
00894 csincos(angle_rad,&s,&c);
00895 return FLOATNAME(LMatrix3)( c, s, 0.0f,
00896 -s, c, 0.0f,
00897 0.0f, 0.0f, 1.0f);
00898 }
00899
00900
00901
00902
00903
00904
00905
00906 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
00907 scale_mat(const FLOATNAME(LVecBase2) &scale) {
00908 return FLOATNAME(LMatrix3)(scale._v.v._0, 0.0f, 0.0f,
00909 0.0f, scale._v.v._1, 0.0f,
00910 0.0f, 0.0f, 1.0f);
00911 }
00912
00913
00914
00915
00916
00917
00918
00919 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
00920 scale_mat(FLOATTYPE sx, FLOATTYPE sy) {
00921 return FLOATNAME(LMatrix3)(sx, 0.0f, 0.0f,
00922 0.0f, sy, 0.0f,
00923 0.0f, 0.0f, 1.0f);
00924 }
00925
00926
00927
00928
00929
00930
00931
00932 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
00933 rotate_mat(FLOATTYPE angle, FLOATNAME(LVecBase3) axis,
00934 CoordinateSystem cs) {
00935 if (cs == CS_default) {
00936 cs = default_coordinate_system;
00937 }
00938 FLOATNAME(LMatrix3) mat;
00939
00940 if(IS_LEFT_HANDED_COORDSYSTEM(cs)) {
00941
00942
00943 angle = -angle;
00944 }
00945
00946 FLOATTYPE axis_0 = axis._v.v._0;
00947 FLOATTYPE axis_1 = axis._v.v._1;
00948 FLOATTYPE axis_2 = axis._v.v._2;
00949
00950
00951 FLOATTYPE length_sq = axis_0 * axis_0 + axis_1 * axis_1 + axis_2 * axis_2;
00952 #ifdef _DEBUG
00953 nassertr(length_sq != 0.0f, ident_mat());
00954 #endif
00955 FLOATTYPE recip_length = 1.0f/csqrt(length_sq);
00956
00957 axis_0 *= recip_length;
00958 axis_1 *= recip_length;
00959 axis_2 *= recip_length;
00960
00961 FLOATTYPE angle_rad=deg_2_rad(angle);
00962 FLOATTYPE s,c;
00963 csincos(angle_rad,&s,&c);
00964 FLOATTYPE t = 1.0f - c;
00965
00966 FLOATTYPE t0,t1,t2,s0,s1,s2;
00967
00968 t0 = t * axis_0;
00969 t1 = t * axis_1;
00970 t2 = t * axis_2;
00971 s0 = s * axis_0;
00972 s1 = s * axis_1;
00973 s2 = s * axis_2;
00974
00975 mat._m.m._00 = t0 * axis_0 + c;
00976 mat._m.m._01 = t0 * axis_1 + s2;
00977 mat._m.m._02 = t0 * axis_2 - s1;
00978
00979 mat._m.m._10 = t1 * axis_0 - s2;
00980 mat._m.m._11 = t1 * axis_1 + c;
00981 mat._m.m._12 = t1 * axis_2 + s0;
00982
00983 mat._m.m._20 = t2 * axis_0 + s1;
00984 mat._m.m._21 = t2 * axis_1 - s0;
00985 mat._m.m._22 = t2 * axis_2 + c;
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001 return mat;
01002 }
01003
01004
01005
01006
01007
01008
01009
01010
01011 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
01012 rotate_mat_normaxis(FLOATTYPE angle, const FLOATNAME(LVecBase3) &axis,
01013 CoordinateSystem cs) {
01014 if (cs == CS_default) {
01015 cs = default_coordinate_system;
01016 }
01017 FLOATNAME(LMatrix3) mat;
01018
01019 if(IS_LEFT_HANDED_COORDSYSTEM(cs)) {
01020
01021
01022 angle = -angle;
01023 }
01024
01025 FLOATTYPE axis_0 = axis._v.v._0;
01026 FLOATTYPE axis_1 = axis._v.v._1;
01027 FLOATTYPE axis_2 = axis._v.v._2;
01028
01029 FLOATTYPE angle_rad=deg_2_rad(angle);
01030 FLOATTYPE s,c;
01031 csincos(angle_rad,&s,&c);
01032 FLOATTYPE t = 1.0f - c;
01033
01034 FLOATTYPE t0,t1,t2,s0,s1,s2;
01035
01036 t0 = t * axis_0;
01037 t1 = t * axis_1;
01038 t2 = t * axis_2;
01039 s0 = s * axis_0;
01040 s1 = s * axis_1;
01041 s2 = s * axis_2;
01042
01043 mat._m.m._00 = t0 * axis_0 + c;
01044 mat._m.m._01 = t0 * axis_1 + s2;
01045 mat._m.m._02 = t0 * axis_2 - s1;
01046
01047 mat._m.m._10 = t1 * axis_0 - s2;
01048 mat._m.m._11 = t1 * axis_1 + c;
01049 mat._m.m._12 = t1 * axis_2 + s0;
01050
01051 mat._m.m._20 = t2 * axis_0 + s1;
01052 mat._m.m._21 = t2 * axis_1 - s0;
01053 mat._m.m._22 = t2 * axis_2 + c;
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069 return mat;
01070 }
01071
01072
01073
01074
01075
01076
01077
01078 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
01079 scale_mat(const FLOATNAME(LVecBase3) &scale) {
01080 return FLOATNAME(LMatrix3)(scale[0], 0.0f, 0.0f,
01081 0.0f, scale._v.v._1, 0.0f,
01082 0.0f, 0.0f, scale._v.v._2);
01083 }
01084
01085
01086
01087
01088
01089
01090
01091 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
01092 scale_mat(FLOATTYPE sx, FLOATTYPE sy, FLOATTYPE sz) {
01093 return FLOATNAME(LMatrix3)(sx, 0.0f, 0.0f,
01094 0.0f, sy, 0.0f,
01095 0.0f, 0.0f, sz);
01096 }
01097
01098
01099
01100
01101
01102
01103
01104 INLINE_LINMATH bool FLOATNAME(LMatrix3)::
01105 almost_equal(const FLOATNAME(LMatrix3) &other) const {
01106 return almost_equal(other, NEARLY_ZERO(FLOATTYPE));
01107 }
01108
01109
01110
01111
01112
01113
01114 INLINE_LINMATH void FLOATNAME(LMatrix3)::
01115 generate_hash(ChecksumHashGenerator &hashgen) const {
01116 generate_hash(hashgen, NEARLY_ZERO(FLOATTYPE));
01117 }
01118
01119
01120
01121
01122
01123
01124 INLINE_LINMATH FLOATNAME(LMatrix3)
01125 transpose(const FLOATNAME(LMatrix3) &a) {
01126 FLOATNAME(LMatrix3) result;
01127 result.transpose_from(a);
01128 return result;
01129 }
01130
01131
01132
01133
01134
01135 INLINE_LINMATH FLOATNAME(LMatrix3)
01136 invert(const FLOATNAME(LMatrix3) &a) {
01137 FLOATNAME(LMatrix3) result;
01138 bool nonsingular = result.invert_from(a);
01139 nassertr(nonsingular, FLOATNAME(LMatrix3)::ident_mat());
01140 return result;
01141 }