forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlmatrix4_src.I
More file actions
1718 lines (1498 loc) · 45.5 KB
/
lmatrix4_src.I
File metadata and controls
1718 lines (1498 loc) · 45.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file lmatrix4_src.I
* @author drose
* @date 1999-01-15
*/
/**
* Defines a row-level index accessor to the matrix.
*/
INLINE_LINMATH FLOATNAME(LMatrix4)::Row::
Row(FLOATTYPE *row) : _row(row) {
}
/**
*
*/
INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix4)::Row::
operator [](int i) const {
nassertr(i >= 0 && i < 4, 0.0);
return _row[i];
}
/**
*
*/
INLINE_LINMATH FLOATTYPE &FLOATNAME(LMatrix4)::Row::
operator [](int i) {
nassertr(i >= 0 && i < 4, _row[0]);
return _row[i];
}
/**
* Returns 4: the number of columns of a LMatrix4.
*/
INLINE_LINMATH int FLOATNAME(LMatrix4)::Row::
size() {
return 4;
}
/**
*
*/
INLINE_LINMATH FLOATNAME(LMatrix4)::Row::
operator const FLOATNAME(LVecBase4) &() const {
return *(const FLOATNAME(LVecBase4) *)_row;
}
/**
* Defines a row-level constant accessor to the matrix.
*/
INLINE_LINMATH FLOATNAME(LMatrix4)::CRow::
CRow(const FLOATTYPE *row) : _row(row) {
}
/**
*
*/
INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix4)::CRow::
operator [](int i) const {
nassertr(i >= 0 && i < 4, 0.0);
return _row[i];
}
/**
* Returns 4: the number of columns of a LMatrix4.
*/
INLINE_LINMATH int FLOATNAME(LMatrix4)::CRow::
size() {
return 4;
}
/**
*
*/
INLINE_LINMATH FLOATNAME(LMatrix4)::CRow::
operator const FLOATNAME(LVecBase4) &() const {
return *(const FLOATNAME(LVecBase4) *)_row;
}
/**
* Returns an identity matrix.
*
* This function definition must appear first, since some inline functions
* below take advantage of it.
*/
INLINE_LINMATH const FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4)::
ident_mat() {
return _ident_mat;
}
/**
* Returns an matrix filled with ones.
*/
INLINE_LINMATH const FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4)::
ones_mat() {
return _ones_mat;
}
/**
* Returns an matrix filled with zeros.
*/
INLINE_LINMATH const FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4)::
zeros_mat() {
return _zeros_mat;
}
/**
*
*/
INLINE_LINMATH FLOATNAME(LMatrix4)::
FLOATNAME(LMatrix4)(const FLOATNAME(UnalignedLMatrix4) ©) {
operator = (copy);
}
/**
*
*/
INLINE_LINMATH FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4)::
operator = (const FLOATNAME(UnalignedLMatrix4) ©) {
TAU_PROFILE("void LMatrix4::operator = (const UnalignedLMatrix4 &)", " ", TAU_USER);
memcpy(&_m(0, 0), copy.get_data(), sizeof(FLOATTYPE) * num_components);
return *this;
}
/**
*
*/
INLINE_LINMATH FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4)::
operator = (FLOATTYPE fill_value) {
fill(fill_value);
return *this;
}
/**
*
*/
INLINE_LINMATH FLOATNAME(LMatrix4)::
FLOATNAME(LMatrix4)(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, FLOATTYPE e03,
FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12, FLOATTYPE e13,
FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22, FLOATTYPE e23,
FLOATTYPE e30, FLOATTYPE e31, FLOATTYPE e32, FLOATTYPE e33) {
TAU_PROFILE("LMatrix4::LMatrix4(FLOATTYPE, ...)", " ", TAU_USER);
_m(0, 0) = e00;
_m(0, 1) = e01;
_m(0, 2) = e02;
_m(0, 3) = e03;
_m(1, 0) = e10;
_m(1, 1) = e11;
_m(1, 2) = e12;
_m(1, 3) = e13;
_m(2, 0) = e20;
_m(2, 1) = e21;
_m(2, 2) = e22;
_m(2, 3) = e23;
_m(3, 0) = e30;
_m(3, 1) = e31;
_m(3, 2) = e32;
_m(3, 3) = e33;
}
/**
* Constructs the matrix from four individual rows.
*/
INLINE_LINMATH FLOATNAME(LMatrix4)::
FLOATNAME(LMatrix4)(const FLOATNAME(LVecBase4) &row0,
const FLOATNAME(LVecBase4) &row1,
const FLOATNAME(LVecBase4) &row2,
const FLOATNAME(LVecBase4) &row3) {
TAU_PROFILE("LMatrix4::LMatrix4(const LVecBase4 &, ...)", " ", TAU_USER);
#ifdef HAVE_EIGEN
_m.row(0) = row0._v;
_m.row(1) = row1._v;
_m.row(2) = row2._v;
_m.row(3) = row3._v;
#else
_m(0, 0) = row0._v(0);
_m(0, 1) = row0._v(1);
_m(0, 2) = row0._v(2);
_m(0, 3) = row0._v(3);
_m(1, 0) = row1._v(0);
_m(1, 1) = row1._v(1);
_m(1, 2) = row1._v(2);
_m(1, 3) = row1._v(3);
_m(2, 0) = row2._v(0);
_m(2, 1) = row2._v(1);
_m(2, 2) = row2._v(2);
_m(2, 3) = row2._v(3);
_m(3, 0) = row3._v(0);
_m(3, 1) = row3._v(1);
_m(3, 2) = row3._v(2);
_m(3, 3) = row3._v(3);
#endif // HAVE_EIGEN
}
/**
*
*/
INLINE_LINMATH FLOATNAME(LMatrix4)::
FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix3) &upper3) {
TAU_PROFILE("void LMatrix4::LMatrix4(const LMatrix3 &)", " ", TAU_USER);
_m(0, 0) = upper3._m(0, 0);
_m(0, 1) = upper3._m(0, 1);
_m(0, 2) = upper3._m(0, 2);
_m(0, 3) = 0.0f;
_m(1, 0) = upper3._m(1, 0);
_m(1, 1) = upper3._m(1, 1);
_m(1, 2) = upper3._m(1, 2);
_m(1, 3) = 0.0f;
_m(2, 0) = upper3._m(2, 0);
_m(2, 1) = upper3._m(2, 1);
_m(2, 2) = upper3._m(2, 2);
_m(2, 3) = 0.0f;
_m(3, 0) = 0.0f;
_m(3, 1) = 0.0f;
_m(3, 2) = 0.0f;
_m(3, 3) = 1.0f;
}
/**
*
*/
INLINE_LINMATH FLOATNAME(LMatrix4)::
FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix3) &upper3,
const FLOATNAME(LVecBase3) &trans) {
TAU_PROFILE("void LMatrix4::LMatrix4(upper3, const LVecBase3 &)", " ", TAU_USER);
_m(0, 0) = upper3._m(0, 0);
_m(0, 1) = upper3._m(0, 1);
_m(0, 2) = upper3._m(0, 2);
_m(0, 3) = 0.0f;
_m(1, 0) = upper3._m(1, 0);
_m(1, 1) = upper3._m(1, 1);
_m(1, 2) = upper3._m(1, 2);
_m(1, 3) = 0.0f;
_m(2, 0) = upper3._m(2, 0);
_m(2, 1) = upper3._m(2, 1);
_m(2, 2) = upper3._m(2, 2);
_m(2, 3) = 0.0f;
_m(3, 0) = trans._v(0);
_m(3, 1) = trans._v(1);
_m(3, 2) = trans._v(2);
_m(3, 3) = 1.0f;
}
/**
* Sets each element of the matrix to the indicated fill_value. This is of
* questionable value, but is sometimes useful when initializing to zero.
*/
INLINE_LINMATH void FLOATNAME(LMatrix4)::
fill(FLOATTYPE fill_value) {
TAU_PROFILE("void LMatrix4::fill(FLOATTYPE)", " ", TAU_USER);
#ifdef HAVE_EIGEN
_m = EMatrix4::Constant(fill_value);
#else
set(fill_value, fill_value, fill_value, fill_value,
fill_value, fill_value, fill_value, fill_value,
fill_value, fill_value, fill_value, fill_value,
fill_value, fill_value, fill_value, fill_value);
#endif // HAVE_EIGEN
}
/**
*
*/
INLINE_LINMATH void FLOATNAME(LMatrix4)::
set(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, FLOATTYPE e03,
FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12, FLOATTYPE e13,
FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22, FLOATTYPE e23,
FLOATTYPE e30, FLOATTYPE e31, FLOATTYPE e32, FLOATTYPE e33) {
TAU_PROFILE("void LMatrix4::set(FLOATTYPE, ...)", " ", TAU_USER);
_m(0, 0) = e00;
_m(0, 1) = e01;
_m(0, 2) = e02;
_m(0, 3) = e03;
_m(1, 0) = e10;
_m(1, 1) = e11;
_m(1, 2) = e12;
_m(1, 3) = e13;
_m(2, 0) = e20;
_m(2, 1) = e21;
_m(2, 2) = e22;
_m(2, 3) = e23;
_m(3, 0) = e30;
_m(3, 1) = e31;
_m(3, 2) = e32;
_m(3, 3) = e33;
}
/**
* Sets the upper 3x3 submatrix.
*/
INLINE_LINMATH void FLOATNAME(LMatrix4)::
set_upper_3(const FLOATNAME(LMatrix3) &upper3) {
TAU_PROFILE("void LMatrix4::set_upper_3(const LMatrix3 &)", " ", TAU_USER);
#ifdef HAVE_EIGEN
_m.block<3, 3>(0, 0) = upper3._m;
#else
_m(0, 0) = upper3(0, 0);
_m(0, 1) = upper3(0, 1);
_m(0, 2) = upper3(0, 2);
_m(1, 0) = upper3(1, 0);
_m(1, 1) = upper3(1, 1);
_m(1, 2) = upper3(1, 2);
_m(2, 0) = upper3(2, 0);
_m(2, 1) = upper3(2, 1);
_m(2, 2) = upper3(2, 2);
#endif // HAVE_EIGEN
}
/**
* Retrieves the upper 3x3 submatrix.
*/
INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix4)::
get_upper_3() const {
TAU_PROFILE("LMatrix3 LMatrix4::get_upper_3()", " ", TAU_USER);
#ifdef HAVE_EIGEN
return FLOATNAME(LMatrix3)(_m.block<3, 3>(0, 0));
#else
return FLOATNAME(LMatrix3)
(_m(0, 0), _m(0, 1), _m(0, 2),
_m(1, 0), _m(1, 1), _m(1, 2),
_m(2, 0), _m(2, 1), _m(2, 2));
#endif // HAVE_EIGEN
}
/**
* Replaces the indicated row of the matrix.
*/
INLINE_LINMATH void FLOATNAME(LMatrix4)::
set_row(int row, const FLOATNAME(LVecBase4) &v) {
#ifdef HAVE_EIGEN
_m.row(row) = v._v;
#else
(*this)(row, 0) = v._v(0);
(*this)(row, 1) = v._v(1);
(*this)(row, 2) = v._v(2);
(*this)(row, 3) = v._v(3);
#endif // HAVE_EIGEN
}
/**
* Replaces the indicated column of the matrix.
*/
INLINE_LINMATH void FLOATNAME(LMatrix4)::
set_col(int col, const FLOATNAME(LVecBase4) &v) {
#ifdef HAVE_EIGEN
_m.col(col) = v._v;
#else
(*this)(0, col) = v._v(0);
(*this)(1, col) = v._v(1);
(*this)(2, col) = v._v(2);
(*this)(3, col) = v._v(3);
#endif // HAVE_EIGEN
}
/**
* Replaces the indicated row of the matrix with the indicated 3-component
* vector, ignoring the last column.
*/
INLINE_LINMATH void FLOATNAME(LMatrix4)::
set_row(int row, const FLOATNAME(LVecBase3) &v) {
#ifdef HAVE_EIGEN
_m.block<1, 3>(row, 0) = v._v;
#else
(*this)(row, 0) = v._v(0);
(*this)(row, 1) = v._v(1);
(*this)(row, 2) = v._v(2);
#endif // HAVE_EIGEN
}
/**
* Replaces the indicated column of the matrix with the indicated 3-component
* vector, ignoring the last row.
*/
INLINE_LINMATH void FLOATNAME(LMatrix4)::
set_col(int col, const FLOATNAME(LVecBase3) &v) {
#ifdef HAVE_EIGEN
_m.block<3, 1>(0, col) = v._v;
#else
(*this)(0, col) = v._v(0);
(*this)(1, col) = v._v(1);
(*this)(2, col) = v._v(2);
#endif
}
/**
* Retrieves the indicated row of the matrix as a 4-component vector.
*/
INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LMatrix4)::
get_row(int row) const {
#ifdef HAVE_EIGEN
return FLOATNAME(LVecBase4)(_m.row(row));
#else
return FLOATNAME(LVecBase4)((*this)(row, 0),
(*this)(row, 1),
(*this)(row, 2),
(*this)(row, 3));
#endif // HAVE_EIGEN
}
/**
* Stores the indicated row of the matrix as a 4-component vector.
*/
INLINE_LINMATH void FLOATNAME(LMatrix4)::
get_row(FLOATNAME(LVecBase4) &result_vec, int row) const {
#ifdef HAVE_EIGEN
result_vec._v = _m.row(row);
#else
result_vec._v(0) = (*this)(row, 0);
result_vec._v(1) = (*this)(row, 1);
result_vec._v(2) = (*this)(row, 2);
result_vec._v(3) = (*this)(row, 3);
#endif // HAVE_EIGEN
}
/**
* Retrieves the indicated column of the matrix as a 4-component vector.
*/
INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LMatrix4)::
get_col(int col) const {
#ifdef HAVE_EIGEN
return FLOATNAME(LVecBase4)(_m.col(col));
#else
return FLOATNAME(LVecBase4)((*this)(0, col),
(*this)(1, col),
(*this)(2, col),
(*this)(3, col));
#endif // HAVE_EIGEN
}
/**
* Retrieves the row column of the matrix as a 3-component vector, ignoring
* the last column.
*/
INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix4)::
get_row3(int row) const {
return FLOATNAME(LVecBase3)((*this)(row, 0),
(*this)(row, 1),
(*this)(row, 2));
}
/**
* Stores the row column of the matrix as a 3-component vector, ignoring the
* last column.
*/
INLINE_LINMATH void FLOATNAME(LMatrix4)::
get_row3(FLOATNAME(LVecBase3) &result_vec,int row) const {
#ifdef HAVE_EIGEN
result_vec._v = _m.block<1, 3>(row, 0);
#else
result_vec._v(0) = (*this)(row, 0);
result_vec._v(1) = (*this)(row, 1);
result_vec._v(2) = (*this)(row, 2);
#endif // HAVE_EIGEN
}
/**
* Retrieves the indicated column of the matrix as a 3-component vector,
* ignoring the last row.
*/
INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix4)::
get_col3(int col) const {
return FLOATNAME(LVecBase3)((*this)(0, col),
(*this)(1, col),
(*this)(2, col));
}
/**
*
*/
INLINE_LINMATH FLOATTYPE &FLOATNAME(LMatrix4)::
operator () (int row, int col) {
nassertr(row >= 0 && row < 4 && col >= 0 && col < 4, _m(0, 0));
return _m(row, col);
}
/**
*
*/
INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix4)::
operator () (int row, int col) const {
nassertr(row >= 0 && row < 4 && col >= 0 && col < 4, _m(0, 0));
return _m(row, col);
}
/**
*
*/
INLINE_LINMATH FLOATNAME(LMatrix4)::CRow FLOATNAME(LMatrix4)::
operator [](int i) const {
nassertr(i >= 0 && i < 4, CRow(&_m(0, 0)));
return CRow(&_m(i, 0));
}
/**
*
*/
INLINE_LINMATH FLOATNAME(LMatrix4)::Row FLOATNAME(LMatrix4)::
operator [](int i) {
nassertr(i >= 0 && i < 4, Row(&_m(0, 0)));
return Row(&_m(i, 0));
}
/**
* Returns 4: the number of rows of a LMatrix4.
*/
INLINE_LINMATH int FLOATNAME(LMatrix4)::
size() {
return 4;
}
/**
* Returns true if any component of the matrix is not-a-number, false
* otherwise.
*/
INLINE_LINMATH bool FLOATNAME(LMatrix4)::
is_nan() const {
TAU_PROFILE("bool LMatrix4::is_nan()", " ", TAU_USER);
return
cnan(_m(0, 0)) || cnan(_m(0, 1)) || cnan(_m(0, 2)) || cnan(_m(0, 3)) ||
cnan(_m(1, 0)) || cnan(_m(1, 1)) || cnan(_m(1, 2)) || cnan(_m(1, 3)) ||
cnan(_m(2, 0)) || cnan(_m(2, 1)) || cnan(_m(2, 2)) || cnan(_m(2, 3)) ||
cnan(_m(3, 0)) || cnan(_m(3, 1)) || cnan(_m(3, 2)) || cnan(_m(3, 3));
}
/**
* Returns true if this is (close enough to) the identity matrix, false
* otherwise.
*/
INLINE_LINMATH bool FLOATNAME(LMatrix4)::
is_identity() const {
// Eigen has isIdentity, but it seems to be twice as slow as this.
return almost_equal(ident_mat(), NEARLY_ZERO(FLOATTYPE));
}
/**
* Returns a particular element of the matrix.
*/
INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix4)::
get_cell(int row, int col) const {
nassertr(row >= 0 && row < 4 && col >= 0 && col < 4, 0.0f);
return _m(row, col);
}
/**
* Changes a particular element of the matrix.
*/
INLINE_LINMATH void FLOATNAME(LMatrix4)::
set_cell(int row, int col, FLOATTYPE value) {
nassertv(row >= 0 && row < 4 && col >= 0 && col < 4);
_m(row, col) = value;
}
/**
* Returns the address of the first of the nine data elements in the matrix.
* The remaining elements occupy the next eight positions in row-major order.
*/
INLINE_LINMATH const FLOATTYPE *FLOATNAME(LMatrix4)::
get_data() const {
return &_m(0, 0);
}
/**
* Returns the number of elements in the matrix, 16.
*/
INLINE_LINMATH int FLOATNAME(LMatrix4)::
get_num_components() const {
return 16;
}
/**
* Returns an iterator that may be used to traverse the elements of the
* matrix, STL-style.
*/
INLINE_LINMATH FLOATNAME(LMatrix4)::iterator FLOATNAME(LMatrix4)::
begin() {
return &_m(0);
}
/**
* Returns an iterator that may be used to traverse the elements of the
* matrix, STL-style.
*/
INLINE_LINMATH FLOATNAME(LMatrix4)::iterator FLOATNAME(LMatrix4)::
end() {
return begin() + 16;
}
/**
* Returns an iterator that may be used to traverse the elements of the
* matrix, STL-style.
*/
INLINE_LINMATH FLOATNAME(LMatrix4)::const_iterator FLOATNAME(LMatrix4)::
begin() const {
return &_m(0);
}
/**
* Returns an iterator that may be used to traverse the elements of the
* matrix, STL-style.
*/
INLINE_LINMATH FLOATNAME(LMatrix4)::const_iterator FLOATNAME(LMatrix4)::
end() const {
return begin() + 16;
}
/**
* This performs a lexicographical comparison. It's of questionable
* mathematical meaning, but sometimes has a practical purpose for sorting
* unique vectors, especially in an STL container. Also see compare_to().
*/
INLINE_LINMATH bool FLOATNAME(LMatrix4)::
operator < (const FLOATNAME(LMatrix4) &other) const {
return compare_to(other) < 0;
}
/**
*
*/
INLINE_LINMATH bool FLOATNAME(LMatrix4)::
operator == (const FLOATNAME(LMatrix4) &other) const {
return compare_to(other) == 0;
}
/**
*
*/
INLINE_LINMATH bool FLOATNAME(LMatrix4)::
operator != (const FLOATNAME(LMatrix4) &other) const {
return compare_to(other) != 0;
}
/**
* This flavor of compare_to uses a default threshold value based on the
* numeric type.
*/
INLINE_LINMATH int FLOATNAME(LMatrix4)::
compare_to(const FLOATNAME(LMatrix4) &other) const {
return compare_to(other, NEARLY_ZERO(FLOATTYPE));
}
/**
* Returns a suitable hash for phash_map.
*/
INLINE_LINMATH size_t FLOATNAME(LMatrix4)::
get_hash() const {
return add_hash(0);
}
/**
* Returns a suitable hash for phash_map.
*/
INLINE_LINMATH size_t FLOATNAME(LMatrix4)::
get_hash(FLOATTYPE threshold) const {
return add_hash(0, threshold);
}
/**
* Adds the vector into the running hash.
*/
INLINE_LINMATH size_t FLOATNAME(LMatrix4)::
add_hash(size_t hash) const {
return add_hash(hash, NEARLY_ZERO(FLOATTYPE));
}
/**
* Adds the vector into the running hash.
*/
INLINE_LINMATH size_t FLOATNAME(LMatrix4)::
add_hash(size_t hash, FLOATTYPE threshold) const {
TAU_PROFILE("size_t LMatrix4::add_hash(size_t, FLOATTYPE)", " ", TAU_USER);
float_hash fhasher(threshold);
hash = fhasher.add_hash(hash, _m(0, 0));
hash = fhasher.add_hash(hash, _m(0, 1));
hash = fhasher.add_hash(hash, _m(0, 2));
hash = fhasher.add_hash(hash, _m(0, 3));
hash = fhasher.add_hash(hash, _m(1, 0));
hash = fhasher.add_hash(hash, _m(1, 1));
hash = fhasher.add_hash(hash, _m(1, 2));
hash = fhasher.add_hash(hash, _m(1, 3));
hash = fhasher.add_hash(hash, _m(2, 0));
hash = fhasher.add_hash(hash, _m(2, 1));
hash = fhasher.add_hash(hash, _m(2, 2));
hash = fhasher.add_hash(hash, _m(2, 3));
hash = fhasher.add_hash(hash, _m(3, 0));
hash = fhasher.add_hash(hash, _m(3, 1));
hash = fhasher.add_hash(hash, _m(3, 2));
hash = fhasher.add_hash(hash, _m(3, 3));
return hash;
}
#define VECTOR4_MATRIX4_PRODUCT(v_res, v, mat) \
v_res._v(0) = v._v(0)*mat._m(0, 0) + v._v(1)*mat._m(1, 0) + v._v(2)*mat._m(2, 0) + v._v(3)*mat._m(3, 0); \
v_res._v(1) = v._v(0)*mat._m(0, 1) + v._v(1)*mat._m(1, 1) + v._v(2)*mat._m(2, 1) + v._v(3)*mat._m(3, 1); \
v_res._v(2) = v._v(0)*mat._m(0, 2) + v._v(1)*mat._m(1, 2) + v._v(2)*mat._m(2, 2) + v._v(3)*mat._m(3, 2); \
v_res._v(3) = v._v(0)*mat._m(0, 3) + v._v(1)*mat._m(1, 3) + v._v(2)*mat._m(2, 3) + v._v(3)*mat._m(3, 3);
/**
* 4-component vector or point times matrix. This is a fully general
* operation.
*/
INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LMatrix4)::
xform(const FLOATNAME(LVecBase4) &v) const {
TAU_PROFILE("LVecBase3 LMatrix4::xform(const LVecBase3 &)", " ", TAU_USER);
FLOATNAME(LVecBase4) v_res;
#ifdef HAVE_EIGEN
v_res._v.noalias() = v._v * _m;
#else
VECTOR4_MATRIX4_PRODUCT(v_res, v,(*this));
#endif // HAVE_EIGEN
return v_res;
}
#undef VECTOR4_MATRIX4_PRODUCT
/**
* The matrix transforms a 3-component point (including translation component)
* and returns the result. This assumes the matrix is an affine transform.
*/
INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix4)::
xform_point(const FLOATNAME(LVecBase3) &v) const {
TAU_PROFILE("LVecBase3 LMatrix4::xform_point(const LVecBase3 &)", " ", TAU_USER);
FLOATNAME(LVecBase3) v_res;
// v._v(3) == 1.0f for this case
#ifdef HAVE_EIGEN
v_res._v.noalias() = v._v * _m.block<3, 3>(0, 0) + _m.block<1, 3>(3, 0);
#else
v_res._v(0) = v._v(0)*_m(0, 0) + v._v(1)*_m(1, 0) + v._v(2)*_m(2, 0) + _m(3, 0);
v_res._v(1) = v._v(0)*_m(0, 1) + v._v(1)*_m(1, 1) + v._v(2)*_m(2, 1) + _m(3, 1);
v_res._v(2) = v._v(0)*_m(0, 2) + v._v(1)*_m(1, 2) + v._v(2)*_m(2, 2) + _m(3, 2);
#endif // HAVE_EIGEN
return v_res;
}
/**
* The matrix transforms a 3-component point (including translation component)
* and returns the result, as a fully general operation.
*/
INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix4)::
xform_point_general(const FLOATNAME(LVecBase3) &v) const {
TAU_PROFILE("LVecBase3 LMatrix4::xform_point_general(const LVecBase3 &)", " ", TAU_USER);
FLOATNAME(LVecBase4) v4(v[0], v[1], v[2], 1.0);
v4 = xform(v4);
return FLOATNAME(LVecBase3)(v4[0] / v4[3], v4[1] / v4[3], v4[2] / v4[3]);
}
/**
* The matrix transforms a 3-component vector (without translation component)
* and returns the result. This assumes the matrix is an orthonormal
* transform.
*/
INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix4)::
xform_vec(const FLOATNAME(LVecBase3) &v) const {
TAU_PROFILE("LVecBase3 LMatrix4::xform_vec(const LVecBase3 &)", " ", TAU_USER);
FLOATNAME(LVecBase3) v_res;
// v._v(3) == 0.0f for this case
#ifdef HAVE_EIGEN
v_res._v.noalias() = v._v * _m.block<3, 3>(0, 0);
#else
v_res._v(0) = v._v(0)*_m(0, 0) + v._v(1)*_m(1, 0) + v._v(2)*_m(2, 0);
v_res._v(1) = v._v(0)*_m(0, 1) + v._v(1)*_m(1, 1) + v._v(2)*_m(2, 1);
v_res._v(2) = v._v(0)*_m(0, 2) + v._v(1)*_m(1, 2) + v._v(2)*_m(2, 2);
#endif // HAVE_EIGEN
return v_res;
}
/**
* The matrix transforms a 3-component vector (without translation component)
* and returns the result, as a fully general operation.
*/
INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix4)::
xform_vec_general(const FLOATNAME(LVecBase3) &v) const {
TAU_PROFILE("LVecBase3 LMatrix4::xform_vec_general(const LVecBase3 &)", " ", TAU_USER);
#ifdef HAVE_EIGEN
return FLOATNAME(LVecBase3)(v._v * _m.block<3, 3>(0, 0).inverse().transpose());
#else
FLOATNAME(LMatrix3) i;
i.invert_transpose_from(*this);
return i.xform(v);
#endif // HAVE_EIGEN
}
/**
* 4-component vector or point times matrix. This is a fully general
* operation.
*/
INLINE_LINMATH void FLOATNAME(LMatrix4)::
xform_in_place(FLOATNAME(LVecBase4) &v) const {
TAU_PROFILE("void LMatrix4::xform_in_place(LVecBase3 &)", " ", TAU_USER);
#ifdef HAVE_EIGEN
v._v = v._v * _m;
#else
v = xform(v);
#endif // HAVE_EIGEN
}
/**
* The matrix transforms a 3-component point (including translation
* component). This assumes the matrix is an affine transform.
*/
INLINE_LINMATH void FLOATNAME(LMatrix4)::
xform_point_in_place(FLOATNAME(LVecBase3) &v) const {
TAU_PROFILE("void LMatrix4::xform_point_in_place(LVecBase3 &)", " ", TAU_USER);
// v._v(3) == 1.0f for this case
#ifdef HAVE_EIGEN
v._v = v._v * _m.block<3, 3>(0, 0) + _m.block<1, 3>(3, 0);
#else
v = xform_point(v);
#endif // HAVE_EIGEN
}
/**
* The matrix transforms a 3-component point (including translation
* component), as a fully general operation.
*/
INLINE_LINMATH void FLOATNAME(LMatrix4)::
xform_point_general_in_place(FLOATNAME(LVecBase3) &v) const {
TAU_PROFILE("void LMatrix4::xform_point_general_in_place(LVecBase3 &)", " ", TAU_USER);
v = xform_point_general(v);
}
/**
* The matrix transforms a 3-component vector (without translation component).
* This assumes the matrix is an orthonormal transform.
*/
INLINE_LINMATH void FLOATNAME(LMatrix4)::
xform_vec_in_place(FLOATNAME(LVecBase3) &v) const {
TAU_PROFILE("void LMatrix4::xform_vec_in_place(LVecBase3 &)", " ", TAU_USER);
// v._v(3) == 0.0f for this case
#ifdef HAVE_EIGEN
v._v = v._v * _m.block<3, 3>(0, 0);
#else
v = xform_vec(v);
#endif // HAVE_EIGEN
}
/**
* The matrix transforms a 3-component vector (without translation component),
* as a fully general operation.
*/
INLINE_LINMATH void FLOATNAME(LMatrix4)::
xform_vec_general_in_place(FLOATNAME(LVecBase3) &v) const {
TAU_PROFILE("void LMatrix4::xform_vec_general_in_place(LVecBase3 &)", " ", TAU_USER);
#ifdef HAVE_EIGEN
v._v = v._v * _m.block<3, 3>(0, 0).inverse().transpose();
#else
v = xform_vec_general(v);
#endif // HAVE_EIGEN
}
#define MATRIX4_PRODUCT(res, a, b) \
res._m(0, 0) = a._m(0, 0)*b._m(0, 0) + a._m(0, 1)*b._m(1, 0) + a._m(0, 2)*b._m(2, 0) + a._m(0, 3)*b._m(3, 0); \
res._m(0, 1) = a._m(0, 0)*b._m(0, 1) + a._m(0, 1)*b._m(1, 1) + a._m(0, 2)*b._m(2, 1) + a._m(0, 3)*b._m(3, 1); \
res._m(0, 2) = a._m(0, 0)*b._m(0, 2) + a._m(0, 1)*b._m(1, 2) + a._m(0, 2)*b._m(2, 2) + a._m(0, 3)*b._m(3, 2); \
res._m(0, 3) = a._m(0, 0)*b._m(0, 3) + a._m(0, 1)*b._m(1, 3) + a._m(0, 2)*b._m(2, 3) + a._m(0, 3)*b._m(3, 3); \
\
res._m(1, 0) = a._m(1, 0)*b._m(0, 0) + a._m(1, 1)*b._m(1, 0) + a._m(1, 2)*b._m(2, 0) + a._m(1, 3)*b._m(3, 0); \
res._m(1, 1) = a._m(1, 0)*b._m(0, 1) + a._m(1, 1)*b._m(1, 1) + a._m(1, 2)*b._m(2, 1) + a._m(1, 3)*b._m(3, 1); \
res._m(1, 2) = a._m(1, 0)*b._m(0, 2) + a._m(1, 1)*b._m(1, 2) + a._m(1, 2)*b._m(2, 2) + a._m(1, 3)*b._m(3, 2); \
res._m(1, 3) = a._m(1, 0)*b._m(0, 3) + a._m(1, 1)*b._m(1, 3) + a._m(1, 2)*b._m(2, 3) + a._m(1, 3)*b._m(3, 3); \
\
res._m(2, 0) = a._m(2, 0)*b._m(0, 0) + a._m(2, 1)*b._m(1, 0) + a._m(2, 2)*b._m(2, 0) + a._m(2, 3)*b._m(3, 0); \
res._m(2, 1) = a._m(2, 0)*b._m(0, 1) + a._m(2, 1)*b._m(1, 1) + a._m(2, 2)*b._m(2, 1) + a._m(2, 3)*b._m(3, 1); \
res._m(2, 2) = a._m(2, 0)*b._m(0, 2) + a._m(2, 1)*b._m(1, 2) + a._m(2, 2)*b._m(2, 2) + a._m(2, 3)*b._m(3, 2); \
res._m(2, 3) = a._m(2, 0)*b._m(0, 3) + a._m(2, 1)*b._m(1, 3) + a._m(2, 2)*b._m(2, 3) + a._m(2, 3)*b._m(3, 3); \
\
res._m(3, 0) = a._m(3, 0)*b._m(0, 0) + a._m(3, 1)*b._m(1, 0) + a._m(3, 2)*b._m(2, 0) + a._m(3, 3)*b._m(3, 0); \
res._m(3, 1) = a._m(3, 0)*b._m(0, 1) + a._m(3, 1)*b._m(1, 1) + a._m(3, 2)*b._m(2, 1) + a._m(3, 3)*b._m(3, 1); \
res._m(3, 2) = a._m(3, 0)*b._m(0, 2) + a._m(3, 1)*b._m(1, 2) + a._m(3, 2)*b._m(2, 2) + a._m(3, 3)*b._m(3, 2); \
res._m(3, 3) = a._m(3, 0)*b._m(0, 3) + a._m(3, 1)*b._m(1, 3) + a._m(3, 2)*b._m(2, 3) + a._m(3, 3)*b._m(3, 3);
/**
*
*/
INLINE_LINMATH FLOATNAME(LMatrix4) FLOATNAME(LMatrix4)::
operator * (const FLOATNAME(LMatrix4) &other) const {
TAU_PROFILE("LMatrix4 LMatrix4::operator *(const LMatrix4 &)", " ", TAU_USER);
FLOATNAME(LMatrix4) t;
t.multiply(*this, other);
return t;
}
// this = other1 * other2
INLINE_LINMATH void FLOATNAME(LMatrix4)::
multiply(const FLOATNAME(LMatrix4) &other1, const FLOATNAME(LMatrix4) &other2) {
TAU_PROFILE("LMatrix4 multiply(const LMatrix4 &, const LMatrix4 &)", " ", TAU_USER);
// faster than operator * since it writes result in place, avoiding extra
// copying this will fail if you try to mat.multiply(mat,other_mat)
nassertv((&other1 != this) && (&other2 != this));
#ifdef HAVE_EIGEN
_m.noalias() = other1._m * other2._m;
#else
MATRIX4_PRODUCT((*this),other1,other2);
#endif // HAVE_EIGEN
}
#undef MATRIX4_PRODUCT
/**
*
*/
INLINE_LINMATH FLOATNAME(LMatrix4) FLOATNAME(LMatrix4)::
operator * (FLOATTYPE scalar) const {
TAU_PROFILE("LMatrix4 operator *(const LMatrix4 &, FLOATTYPE)", " ", TAU_USER);
FLOATNAME(LMatrix4) t;
#ifdef HAVE_EIGEN
t._m = _m * scalar;
#else
t._m(0, 0) = _m(0, 0) * scalar;
t._m(0, 1) = _m(0, 1) * scalar;
t._m(0, 2) = _m(0, 2) * scalar;
t._m(0, 3) = _m(0, 3) * scalar;
t._m(1, 0) = _m(1, 0) * scalar;
t._m(1, 1) = _m(1, 1) * scalar;
t._m(1, 2) = _m(1, 2) * scalar;
t._m(1, 3) = _m(1, 3) * scalar;
t._m(2, 0) = _m(2, 0) * scalar;
t._m(2, 1) = _m(2, 1) * scalar;
t._m(2, 2) = _m(2, 2) * scalar;
t._m(2, 3) = _m(2, 3) * scalar;
t._m(3, 0) = _m(3, 0) * scalar;
t._m(3, 1) = _m(3, 1) * scalar;
t._m(3, 2) = _m(3, 2) * scalar;
t._m(3, 3) = _m(3, 3) * scalar;
#endif // HAVE_EIGEN
return t;
}
/**
*
*/
INLINE_LINMATH FLOATNAME(LMatrix4) FLOATNAME(LMatrix4)::
operator / (FLOATTYPE scalar) const {
FLOATTYPE recip_scalar = 1.0f/scalar;
return (*this) * recip_scalar;
}
/**
* Performs a memberwise addition between two matrices.
*/
INLINE_LINMATH FLOATNAME(LMatrix4) &FLOATNAME(LMatrix4)::
operator += (const FLOATNAME(LMatrix4) &other) {
TAU_PROFILE("LMatrix4 LMatrix4::operator +=(const LMatrix4 &)", " ", TAU_USER);
#ifdef HAVE_EIGEN
_m += other._m;
#else
_m(0, 0) += other._m(0, 0);
_m(0, 1) += other._m(0, 1);