-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix4_.h
More file actions
1351 lines (1194 loc) · 41.2 KB
/
Matrix4_.h
File metadata and controls
1351 lines (1194 loc) · 41.2 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
#ifndef MATRIX4__H
#define MATRIX4__H
#include "VmUtil.h"
#include "Matrix3_.h"
#include "Vector4.h"
#include "Point4.h"
VM_BEGIN_NS
/**
* A 4 x 4 matrix.
* @version specification 1.1, implementation $Revision: 1.3 $, $Date: 1999/10/06 02:52:46 $
* @author Kenji hiranabe
*/
template<class T>
class Matrix4 {
protected:
static T abs(T t) { return VmUtil<T>::abs(t); }
/*
* $Log: Matrix4_.h,v $
* Revision 1.3 1999/10/06 02:52:46 hiranabe
* Java3D 1.2 and namespace
*
* Revision 1.2 1999/05/26 00:59:37 hiranabe
* support Visual C++
*
* Revision 1.1 1999/03/04 11:07:09 hiranabe
* Initial revision
*
* Revision 1.1 1999/03/04 11:07:09 hiranabe
* Initial revision
*
*/
public:
/**
* the type for values
*/
typedef T value_type;
/**
* the type for index
*/
typedef size_t size_type;
/**
* dimension
*/
enum { DIMENSION = 4 };
/**
* the type for tuple
*/
typedef Tuple4<T> tuple_type;
/**
* the type for vector
*/
typedef Vector4<T> vector_type;
/**
* the type for point
*/
typedef Point4<T> point_type;
/**
* The first element of the first row.
*/
T m00;
/**
* The second element of the first row.
*/
T m01;
/**
* third element of the first row.
*/
T m02;
/**
* The fourth element of the first row.
*/
T m03;
/**
* The first element of the second row.
*/
T m10;
/**
* The second element of the second row.
*/
T m11;
/**
* The third element of the second row.
*/
T m12;
/**
* The fourth element of the second row.
*/
T m13;
/**
* The first element of the third row.
*/
T m20;
/**
* The second element of the third row.
*/
T m21;
/**
* The third element of the third row.
*/
T m22;
/**
* The fourth element of the third row.
*/
T m23;
/**
* The first element of the fourth row.
*/
T m30;
/**
* The second element of the fourth row.
*/
T m31;
/**
* The third element of the fourth row.
*/
T m32;
/**
* The fourth element of the fourth row.
*/
T m33;
/**
* Constructs and initializes a Matrix4 from the specified 16 values.
* @param m00 the [0][0] element
* @param m01 the [0][1] element
* @param m02 the [0][2] element
* @param m03 the [0][3] element
* @param m10 the [1][0] element
* @param m11 the [1][1] element
* @param m12 the [1][2] element
* @param m13 the [1][3] element
* @param m20 the [2][0] element
* @param m21 the [2][1] element
* @param m22 the [2][2] element
* @param m23 the [2][3] element
* @param m30 the [3][0] element
* @param m31 the [3][1] element
* @param m32 the [3][2] element
* @param m33 the [3][3] element
*/
Matrix4(T m00, T m01, T m02, T m03,
T m10, T m11, T m12, T m13,
T m20, T m21, T m22, T m23,
T m30, T m31, T m32, T m33);
/**
* Constructs and initializes a Matrix4 from the specified 16
* element array. this.m00 =v[0], this.m01=v[1], etc.
* @param v the array of length 16 containing in order
*/
Matrix4(const T v[]);
/**
* Constructs and initializes a Matrix4 from the specified 4x4
* element array. this.m00 =m[0][0], this.m01=m[0][1], etc.
* @param m the array of 4 x 4 containing in order
*/
Matrix4(const T m[][4]);
/**
* Constructs and initializes a Matrix4 from the quaternion,
* translation, and scale values; the scale is applied only to the
* rotational components of the matrix (upper 3x3) and not to the
* translational components.
* @param q1 The quaternion value representing the rotational component
* @param t1 The translational component of the matrix
* @param s The scale value applied to the rotational components
*/
Matrix4(const Quat4<T>& q1, const Vector3<T>& t1, T s);
#if 0
/**
* Constructs and initializes a Matrix4 from the quaternion,
* translation, and scale values; the scale is applied only to the
* rotational components of the matrix (upper 3x3) and not to the
* translational components.
* @param q1 The quaternion value representing the rotational component
* @param t1 The translational component of the matrix
* @param s The scale value applied to the rotational components
*/
Matrix4(Quat4f q1, Vector3d t1, T s) {
set(q1, t1, s);
}
/**
* Constructs a new matrix with the same values as the Matrix4f parameter.
* @param m1 The source matrix.
*/
Matrix4(Matrix4f m1) {
set(m1);
}
/**
* Constructs and initializes a Matrix4 from the rotation matrix,
* translation, and scale values; the scale is applied only to the
* rotational components of the matrix (upper 3x3) and not to the
* translational components.
* @param m1 The rotation matrix representing the rotational components
* @param t1 The translational components of the matrix
* @param s The scale value applied to the rotational components
*/
Matrix4(Matrix3f m1, Vector3d t1, T s) {
// why no set(Matrix3f, Vector3d, T) ?
// set(Matrix3f, Vector3f, float) is there.
// feel inconsistent.
set(m1);
mulRotationScale(s);
setTranslation(t1);
m33 = 1.0;
}
#endif
/**
* Constructs and initializes a Matrix4 from the rotation matrix,
* translation, and scale values; the scale is applied only to the
* rotational components of the matrix (upper 3x3) and not to the
* translational components.
* @param m1 The rotation matrix representing the rotational components
* @param t1 The translational components of the matrix
* @param s The scale value applied to the rotational components
*/
Matrix4(const Matrix3<T>& m1, const Vector3<T>& t1, T s);
/**
* Constructs and initializes a Matrix4 to all zeros.
*/
Matrix4();
/**
* Sets 16 values
* @param m00 the [0][0] element
* @param m01 the [0][1] element
* @param m02 the [0][2] element
* @param m03 the [0][3] element
* @param m10 the [1][0] element
* @param m11 the [1][1] element
* @param m12 the [1][2] element
* @param m13 the [1][3] element
* @param m20 the [2][0] element
* @param m21 the [2][1] element
* @param m22 the [2][2] element
* @param m23 the [2][3] element
* @param m30 the [3][0] element
* @param m31 the [3][1] element
* @param m32 the [3][2] element
* @param m33 the [3][3] element
*/
void set(T m00, T m01, T m02, T m03,
T m10, T m11, T m12, T m13,
T m20, T m21, T m22, T m23,
T m30, T m31, T m32, T m33);
/**
* Sets the values in this Matrix4 equal to the row-major array parameter
* (ie, the first four elements of the array will be copied into the first
* row of this matrix, etc.).
*/
void set(const T m[]);
/**
* Sets the values in this Matrix4 equal to the row-major array parameter
* (ie, the first four elements of the array will be copied into the first
* row of this matrix, etc.).
*/
void set(const T m[][4]);
/**
* Sets the value of this matrix to a copy of the
* passed matrix m1.
* @param m1 the matrix to be copied
*/
void set(const Matrix4<T>& m1);
/**
* Sets the rotational component (upper 3x3) of this matrix to the matrix
* values in the T precision Matrix3d argument; the other elements of
* this matrix are initialized as if this were an identity matrix
* (ie, affine matrix with no translational component).
* @param m1 the 3x3 matrix
*/
void set(const Matrix3<T>& m1);
/**
* Sets the value of this matrix to the matrix conversion of the
* (T precision) quaternion argument.
* @param q1 the quaternion to be converted
*/
void set(const Quat4<T>& q1);
/**
* Sets the value of this matrix to the matrix conversion of the
* T precision axis and angle argument.
* @param a1 the axis and angle to be converted
*/
void set(const AxisAngle4<T>& a1);
/**
* Sets this Matrix4 to identity.
*/
void setIdentity();
/**
* Sets the specified element of this matrix4d to the value provided.
* @param row the row number to be modified (zero indexed)
* @param column the column number to be modified (zero indexed)
* @param value the new value
*/
void setElement(size_t row, size_t column, T value);
/**
* Retrieves the value at the specified row and column of this matrix.
* @param row the row number to be retrieved (zero indexed)
* @param column the column number to be retrieved (zero indexed)
* @return the value at the indexed element
*/
T getElement(size_t row, size_t column) const;
/**
* Retrieves the lvalue at the specified row and column of this matrix.
* @param row the row number to be retrieved (zero indexed)
* @param column the column number to be retrieved (zero indexed)
* @return the lvalue at the indexed element
*/
T& getElementReference(size_type row, size_type column);
/**
* Performs an SVD normalization of this matrix in order to acquire the
* normalized rotational component; the values are placed into the Matrix3d parameter.
* @param m1 matrix into which the rotational component is placed
*/
void get(Matrix3<T>* m1) const;
#if 0
/**
* Performs an SVD normalization of this matrix in order to acquire the
* normalized rotational component; the values are placed into the Matrix3f parameter.
* @param m1 matrix into which the rotational component is placed
*/
void get(Matrix3f m1) const{
SVD(m1);
}
#endif
/**
* Performs an SVD normalization of this matrix to calculate the rotation
* as a 3x3 matrix, the translation, and the scale. None of the matrix values are modified.
* @param m1 The normalized matrix representing the rotation
* @param t1 The translation component
* @return The scale component of this transform
*/
T get(Matrix3<T>* m1, Vector3<T>* t1) const;
/**
* Performs an SVD normalization of this matrix in order to acquire the
* normalized rotational component; the values are placed into
* the Quat4f parameter.
* @param q1 quaternion into which the rotation component is placed
*/
void get(Quat4<T>* q1) const;
#if 0
/**
* Performs an SVD normalization of this matrix to calculate the rotation
* as a 3x3 matrix, the translation, and the scale. None of the matrix values are modified.
* @param m1 The normalized matrix representing the rotation
* @param t1 The translation component
* @return The scale component of this transform
*/
T get(Matrix3f m1, Vector3d t1) {
get(t1);
return SVD(m1);
}
/**
* Performs an SVD normalization of this matrix in order to acquire the
* normalized rotational component; the values are placed into
* the Quat4f parameter.
* @param q1 quaternion into which the rotation component is placed
*/
void get(Quat4f q1) {
q1.set(this);
q1.normalize();
}
/**
* Gets the upper 3x3 values of this matrix and places them into the matrix m1.
* @param m1 The matrix that will hold the values
*/
void getRotationScale(Matrix3f m1) {
m1.m00 = (float)m00; m1.m01 = (float)m01; m1.m02 = (float)m02;
m1.m10 = (float)m10; m1.m11 = (float)m11; m1.m12 = (float)m12;
m1.m20 = (float)m20; m1.m21 = (float)m21; m1.m22 = (float)m22;
}
#endif
/**
* Retrieves the translational components of this matrix.
* @param trans the vector that will receive the translational component
*/
void get(Vector3<T>* trans) const {
assert(trans != 0);
trans->x = m03;
trans->y = m13;
trans->z = m23;
}
/**
* Gets the upper 3x3 values of this matrix and places them into the matrix m1.
* @param m1 The matrix that will hold the values
*/
void getRotationScale(Matrix3<T>* m1) const;
/**
* Performs an SVD normalization of this matrix to calculate and return the
* uniform scale factor. This matrix is not modified.
* @return the scale factor of this matrix
*/
T getScale() const;
/**
* Replaces the upper 3x3 matrix values of this matrix with the values in the matrix m1.
* @param m1 The matrix that will be the new upper 3x3
*/
void setRotationScale(const Matrix3<T>& m1);
#if 0
/**
* Replaces the upper 3x3 matrix values of this matrix with the values in the matrix m1.
* @param m1 The matrix that will be the new upper 3x3
*/
void setRotationScale(Matrix3f m1) {
m00 = m1.m00; m01 = m1.m01; m02 = m1.m02;
m10 = m1.m10; m11 = m1.m11; m12 = m1.m12;
m20 = m1.m20; m21 = m1.m21; m22 = m1.m22;
}
#endif
/**
* Sets the scale component of the current matrix by factoring out the
* current scale (by doing an SVD) from the rotational component and
* multiplying by the new scale.
* note: this method doesn't change m44.
* @param scale the new scale amount
*/
void setScale(T scale);
/**
* Sets the specified row of this matrix4d to the four values provided.
* @param row the row number to be modified (zero indexed)
* @param x the first column element
* @param y the second column element
* @param z the third column element
* @param w the fourth column element
*/
void setRow(size_t row, T x, T y, T z, T w);
/**
* Sets the specified row of this matrix4d to the Vector provided.
* @param row the row number to be modified (zero indexed)
* @param v the replacement row
*/
void setRow(size_t row, const Vector4<T>& v);
/**
* Sets the specified row of this matrix4d to the four values provided.
* @param row the row number to be modified (zero indexed)
* @param v the replacement row
*/
void setRow(size_t row, const T v[]);
/**
* Copies the matrix values in the specified row into the
* vector parameter.
* @param row the matrix row
* @param v The vector into which the matrix row values will be copied
*/
void getRow(size_t row, Vector4<T>* v) const;
/**
* Copies the matrix values in the specified row into the
* array parameter.
* @param row the matrix row
* @param v The array into which the matrix row values will be copied
*/
void getRow(size_t row, T v[]) const;
/**
* Sets the specified column of this matrix4d to the four values provided.
* @param column the column number to be modified (zero indexed)
* @param x the first row element
* @param y the second row element
* @param z the third row element
* @param w the fourth row element
*/
void setColumn(size_t column, T x, T y, T z, T w);
/**
* Sets the specified column of this matrix4d to the vector provided.
* @param column the column number to be modified (zero indexed)
* @param v the replacement column
*/
void setColumn(size_t column, const Vector4<T>& v);
/**
* Sets the specified column of this matrix4d to the four values provided.
* @param column the column number to be modified (zero indexed)
* @param v the replacement column
*/
void setColumn(size_t column, const T v[]);
/**
* Copies the matrix values in the specified column into the
* vector parameter.
* @param column the matrix column
* @param v The vector into which the matrix column values will be copied
*/
void getColumn(size_t column, Vector4<T>* v) const;
/**
* Copies the matrix values in the specified column into the
* array parameter.
* @param column the matrix column
* @param v The array into which the matrix column values will be copied
*/
void getColumn(size_t column, T v[]) const;
/**
* Adds a scalar to each component of this matrix.
* @param scalar The scalar adder.
*/
void add(T scalar);
/**
* Substracts a scalar from each component of this matrix.
* @param scalar The scalar adder.
*/
void sub(T scalar);
/**
* Adds a scalar to each component of the matrix m1 and places
* the result into this. Matrix m1 is not modified.
* @param scalar The scalar adder.
* @parm m1 The original matrix values.
*/
void add(T scalar, const Matrix4& m1) {
set(m1);
add(scalar);
}
/**
* Sets the value of this matrix to the matrix sum of matrices m1 and m2.
* @param m1 the first matrix
* @param m2 the second matrix
*/
void add(const Matrix4& m1, const Matrix4& m2);
/**
* Sets the value of this matrix to sum of itself and matrix m1.
* @param m1 the other matrix
*/
void add(const Matrix4& m1);
/**
* Sets the value of this matrix to the matrix difference
* of matrices m1 and m2.
* @param m1 the first matrix
* @param m2 the second matrix
*/
void sub(const Matrix4& m1, const Matrix4& m2);
/**
* Sets the value of this matrix to the matrix difference of itself
* and matrix m1 (this = this - m1).
* @param m1 the other matrix
*/
void sub(const Matrix4& m1);
/**
* Sets the value of this matrix to its transpose.
*/
void transpose();
/**
* Sets the value of this matrix to the transpose of the argument matrix
* @param m1 the matrix to be transposed
*/
void transpose(const Matrix4& m1) {
// alias-safe
set(m1);
transpose();
}
#if 0
/**
* Sets the rotational component (upper 3x3) of this matrix to the matrix
* values in the single precision Matrix3f argument; the other elements of
* this matrix are initialized as if this were an identity matrix
* (ie, affine matrix with no translational component).
* @param m1 the 3x3 matrix
*/
void set(Matrix3f m1) {
m00 = m1.m00; m01 = m1.m01; m02 = m1.m02; m03 = 0.0;
m10 = m1.m10; m11 = m1.m11; m12 = m1.m12; m13 = 0.0;
m20 = m1.m20; m21 = m1.m21; m22 = m1.m22; m23 = 0.0;
m30 = 0.0; m31 = 0.0; m32 = 0.0; m33 = 1.0;
}
/**
* Sets the value of this matrix to the matrix conversion of the
* single precision quaternion argument.
* @param q1 the quaternion to be converted
*/
void set(Quat4f q1) {
setFromQuat(q1.x, q1.y, q1.z, q1.w);
}
/**
* Sets the value of this matrix to the matrix conversion of the
* single precision axis and angle argument.
* @param a1 the axis and angle to be converted
*/
void set(AxisAngle4f a1) {
setFromAxisAngle(a1.x, a1.y, a1.z, a1.angle);
}
#endif
/**
* Sets the value of this matrix from the rotation expressed by the
* quaternion q1, the translation t1, and the scale s.
* @param q1 the rotation expressed as a quaternion
* @param t1 the translation
* @param s the scale value
*/
void set(const Quat4<T>& q1, const Vector3<T>& t1, T s);
#if 0
/**
* Sets the value of this matrix from the rotation expressed by the
* quaternion q1, the translation t1, and the scale s.
* @param q1 the rotation expressed as a quaternion
* @param t1 the translation
* @param s the scale value
*/
void set(Quat4f q1, Vector3d t1, T s) {
set(q1);
mulRotationScale(s);
m03 = t1.x;
m13 = t1.y;
m23 = t1.z;
}
/**
* Sets the value of this matrix from the rotation expressed by the
* quaternion q1, the translation t1, and the scale s.
* @param q1 the rotation expressed as a quaternion
* @param t1 the translation
* @param s the scale value
*/
void set(Quat4f q1, Vector3f t1, float s) {
set(q1);
mulRotationScale(s);
m03 = t1.x;
m13 = t1.y;
m23 = t1.z;
}
/**
* Sets the value of this matrix to the T value of the
* passed matrix4f.
* @param m1 the matrix4f
*/
void set(Matrix4f m1) {
m00 = m1.m00; m01 = m1.m01; m02 = m1.m02; m03 = m1.m03;
m10 = m1.m10; m11 = m1.m11; m12 = m1.m12; m13 = m1.m13;
m20 = m1.m20; m21 = m1.m21; m22 = m1.m22; m23 = m1.m23;
m30 = m1.m30; m31 = m1.m31; m32 = m1.m32; m33 = m1.m33;
}
#endif
/**
* Sets the value of this matrix to the matrix inverse
* of the passed matrix m1.
* @param m1 the matrix to be inverted
*/
void invert(const Matrix4<T>& m1);
/**
* Sets the value of this matrix to its inverse.
*/
void invert();
/**
* Computes the determinant of this matrix.
* @return the determinant of the matrix
*/
T determinant() const;
/**
* Sets the value of this matrix to a scale matrix with the
* passed scale amount.
* @param scale the scale factor for the matrix
*/
void set(T scale);
/**
* Modifies the translational components of this matrix to the values of
* the Vector3d argument; the other values of this matrix are not modified.
* @param trans the translational component
*/
void setTranslation(const Vector3<T>& trans) {
m03 = trans.x;
m13 = trans.y;
m23 = trans.z;
}
/**
* Sets the value of this matrix to a translate matrix by the
* passed translation value.
* @param v1 the translation amount
*/
void set(const Vector3<T>& v1) {
setIdentity();
setTranslation(v1);
}
/**
* Sets the value of this matrix to a scale and translation matrix;
* scale is not applied to the translation and all of the matrix
* values are modified.
* @param scale the scale factor for the matrix
* @param v1 the translation amount
*/
void set(T scale, const Vector3<T>& v1) {
set(scale);
setTranslation(v1);
}
/**
* Sets the value of this matrix to a scale and translation matrix;
* the translation is scaled by the scale factor and all of the
* matrix values are modified.
* @param v1 the translation amount
* @param scale the scale factor for the matrix
*/
void set(const Vector3<T>& v1, T scale);
#if 0
/**
* Sets the value of this matrix from the rotation expressed by the
* rotation matrix m1, the translation t1, and the scale s. The translation
* is not modified by the scale.
* @param m1 The rotation component
* @param t1 The translation component
* @param scale The scale component
*/
void set(Matrix3f m1, Vector3f t1, float scale) {
setRotationScale(m1);
mulRotationScale(scale);
setTranslation(t1);
m33 = 1.0;
}
#endif
/**
* Sets the value of this matrix from the rotation expressed by the
* rotation matrix m1, the translation t1, and the scale s. The translation
* is not modified by the scale.
* @param m1 The rotation component
* @param t1 The translation component
* @param scale The scale component
*/
void set(const Matrix3<T>& m1, const Vector3<T>& t1, T scale);
/**
* Sets the value of this matrix to a rotation matrix about the x axis
* by the passed angle.
* @param angle the angle to rotate about the X axis in radians
*/
void rotX(T angle);
/**
* Sets the value of this matrix to a rotation matrix about the y axis
* by the passed angle.
* @param angle the angle to rotate about the Y axis in radians
*/
void rotY(T angle);
/**
* Sets the value of this matrix to a rotation matrix about the z axis
* by the passed angle.
* @param angle the angle to rotate about the Z axis in radians
*/
void rotZ(T angle);
/**
* Multiplies each element of this matrix by a scalar.
* @param scalar The scalar multiplier.
*/
void mul(T scalar);
/**
* Multiplies each element of matrix m1 by a scalar and places the result
* into this. Matrix m1 is not modified.
* @param scalar The scalar multiplier.
* @param m1 The original matrix.
*/
void mul(T scalar, const Matrix4& m1) {
set(m1);
mul(scalar);
}
/**
* Sets the value of this matrix to the result of multiplying itself
* with matrix m1.
* @param m1 the other matrix
*/
void mul(const Matrix4& m1) {
mul(*this, m1);
}
/**
* Sets the value of this matrix to the result of multiplying
* the two argument matrices together.
* @param m1 the first matrix
* @param m2 the second matrix
*/
void mul(const Matrix4& m1, const Matrix4& m2);
/**
* Multiplies the transpose of matrix m1 times the transpose of matrix m2,
* and places the result into this.
* @param m1 The matrix on the left hand side of the multiplication
* @param m2 The matrix on the right hand side of the multiplication
*/
void mulTransposeBoth(const Matrix4& m1, const Matrix4& m2) {
mul(m2, m1);
transpose();
}
/**
* Multiplies matrix m1 times the transpose of matrix m2, and places the
* result into this.
* @param m1 The matrix on the left hand side of the multiplication
* @param m2 The matrix on the right hand side of the multiplication
*/
void mulTransposeRight(const Matrix4& m1, const Matrix4& m2);
/**
* Multiplies the transpose of matrix m1 times matrix m2, and places the
* result into this.
* @param m1 The matrix on the left hand side of the multiplication
* @param m2 The matrix on the right hand side of the multiplication
*/
void mulTransposeLeft(const Matrix4& m1, const Matrix4& m2);
/**
* Returns true if all of the data members of Matrix4 m1 are
* equal to the corresponding data members in this Matrix4.
* @param m1 The matrix with which the comparison is made.
* @return true or false
*/
bool equals(const Matrix4& m1) const;
/**
* Returns true if the L-infinite distance between this matrix and matrix
* m1 is less than or equal to the epsilon parameter, otherwise returns
* false. The L-infinite distance is equal to MAX[i=0,1,2,3 ; j=0,1,2,3 ;
* abs(this.m(i,j) - m1.m(i,j)]
* @param m1 The matrix to be compared to this matrix
* @param epsilon the threshold value
*/
bool epsilonEquals(const Matrix4& m1, T epsilon) const;
/**
* Returns a hash number based on the data values in this
* object. Two different Matrix4 objects with identical data values
* (ie, returns true for equals(Matrix4) ) will return the same hash
* number. Two objects with different data members may return the
* same hash value, although this is not likely.
* @return the integer hash value
*/
size_t hashCode() const {
return VmUtil<T>::hashCode(sizeof *this, this);
}
/**
* Transform the vector vec using this Matrix4 and place the
* result into vecOut.
* @param vec the T precision vector to be transformed
* @param vecOut the vector into which the transformed values are placed
*/
void transform(const Tuple4<T>& vec, Tuple4<T>* vecOut) const;
/**
* Transform the vector vec using this Matrix4 and place the
* result back into vec.
* @param vec the T precision vector to be transformed
*/
void transform(Tuple4<T>* vec) const {
transform(*vec, vec);
}
#if 0
/**
* Transform the vector vec using this Matrix4 and place the
* result into vecOut.
* @param vec the single precision vector to be transformed
* @param vecOut the vector into which the transformed values are placed
*/
void transform(Tuple4f vec, Tuple4f vecOut) {
// alias-safe
vecOut.set(
(float)(m00*vec.x + m01*vec.y + m02*vec.z + m03*vec.w),
(float)(m10*vec.x + m11*vec.y + m12*vec.z + m13*vec.w),
(float)(m20*vec.x + m21*vec.y + m22*vec.z + m23*vec.w),
(float)(m30*vec.x + m31*vec.y + m32*vec.z + m33*vec.w)
);
}
/**
* Transform the vector vec using this Matrix4 and place the
* result back into vec.
* @param vec the single precision vector to be transformed
*/
void transform(Tuple4f vec) {
transform(vec, vec);
}
#endif
/**
* Transforms the point parameter with this Matrix4 and places the result
* into pointOut. The fourth element of the point input paramter is assumed
* to be one.
* @param point the input point to be transformed.
* @param pointOut the transformed point
*/
void transform(const Point3<T>& point, Point3<T>* pointOut) const;
/**
* Transforms the point parameter with this Matrix4 and
* places the result back into point. The fourth element of the
* point input paramter is assumed to be one.
* @param point the input point to be transformed.
*/
void transform(Point3<T>* point) const {
assert(point != 0);
transform(*point, point);
}
#if 0
/**
* Transforms the point parameter with this Matrix4 and places the result
* into pointOut. The fourth element of the point input paramter is assumed
* to be one.
* @param point the input point to be transformed.
* @param pointOut the transformed point
*/
void transform(Point3f point, Point3f pointOut) {
pointOut.set(
(float)(m00*point.x + m01*point.y + m02*point.z + m03),
(float)(m10*point.x + m11*point.y + m12*point.z + m13),
(float)(m20*point.x + m21*point.y + m22*point.z + m23)
);
}
/**
* Transforms the point parameter with this Matrix4 and
* places the result back into point. The fourth element of the
* point input paramter is assumed to be one.
* @param point the input point to be transformed.
*/
void transform(Point3f point) {
transform(point, point);
}
#endif
/**