1 | #ifndef __MATRIX4x4_H
|
---|
2 | #define __MATRIX4x4_H
|
---|
3 |
|
---|
4 | #include <iostream>
|
---|
5 |
|
---|
6 |
|
---|
7 | //namespace GtpVisibilityPreprocessor {
|
---|
8 |
|
---|
9 | class Vector3;
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 | class Matrix4x4
|
---|
14 | {
|
---|
15 | public:
|
---|
16 | float x[4][4]; // first index is column [x], the second is row [y]
|
---|
17 |
|
---|
18 | Matrix4x4() { }
|
---|
19 |
|
---|
20 | // here xXY - 'X' is row, and 'Y' is column - classical mathematical notation
|
---|
21 | Matrix4x4(float x11, float x12, float x13, float x14,
|
---|
22 | float x21, float x22, float x23, float x24,
|
---|
23 | float x31, float x32, float x33, float x34,
|
---|
24 | float x41, float x42, float x43, float x44);
|
---|
25 |
|
---|
26 | Matrix4x4(const Vector3 &a, const Vector3 &b, const Vector3 &c);
|
---|
27 |
|
---|
28 |
|
---|
29 | // Assignment operators
|
---|
30 | Matrix4x4& operator+= (const Matrix4x4 &A); // add-to
|
---|
31 | Matrix4x4& operator-= (const Matrix4x4 &A); // subtract-from
|
---|
32 | Matrix4x4& operator*= (const Matrix4x4 &A); // multiply by matrix
|
---|
33 | Matrix4x4& operator*= (float A); // scale by scalar
|
---|
34 |
|
---|
35 | // Fundamental operations
|
---|
36 | /// Invert the matrix .. returns 0 = regular
|
---|
37 | int Invert();
|
---|
38 | /// Transpose the matrix
|
---|
39 | void Transpose();
|
---|
40 |
|
---|
41 | void
|
---|
42 | SetColumns(const Vector3 &a, const Vector3 &b, const Vector3 &c);
|
---|
43 |
|
---|
44 | float Det3x3() const {
|
---|
45 | return (x[0][0]*x[1][1]*x[2][2] + \
|
---|
46 | x[1][0]*x[2][1]*x[0][2] + \
|
---|
47 | x[2][0]*x[0][1]*x[1][2] - \
|
---|
48 | x[2][0]*x[1][1]*x[0][2] - \
|
---|
49 | x[0][0]*x[2][1]*x[1][2] - \
|
---|
50 | x[1][0]*x[0][1]*x[2][2]);
|
---|
51 | }
|
---|
52 |
|
---|
53 |
|
---|
54 | friend Matrix4x4 Invert(const Matrix4x4 &M); // Invert a given matrix
|
---|
55 | friend Matrix4x4 Transpose(const Matrix4x4 &M); // Transpose a given matrix
|
---|
56 |
|
---|
57 | // Create various types of matrix.
|
---|
58 | friend Matrix4x4 IdentityMatrix();
|
---|
59 | friend Matrix4x4 ZeroMatrix();
|
---|
60 | friend Matrix4x4 TranslationMatrix(const Vector3 &Location);
|
---|
61 | friend Matrix4x4 RotationXMatrix(float Angle);
|
---|
62 | friend Matrix4x4 RotationYMatrix(float Angle);
|
---|
63 | friend Matrix4x4 RotationZMatrix(float Angle);
|
---|
64 | friend Matrix4x4 RotationYPRMatrix(float Yaw, float Pitch, float Roll);
|
---|
65 | // about axis 'axis' by angle 'Angle'
|
---|
66 | friend Matrix4x4 RotationAxisMatrix(const Vector3 &axis, float Angle);
|
---|
67 | // create the rotation matrix that rotates 'vecFrom' to 'vecTo'
|
---|
68 | friend Matrix4x4 RotationVectorsMatrix(const Vector3 &vecFrom,
|
---|
69 | const Vector3 &vecTo);
|
---|
70 |
|
---|
71 | friend Matrix4x4 ScaleMatrix(float X, float Y, float Z);
|
---|
72 | friend Matrix4x4 GenRotation(const Vector3 &x, const Vector3 &y,
|
---|
73 | const Vector3 &z);
|
---|
74 | friend Matrix4x4 QuadricMatrix(float a, float b, float c, float d, float e,
|
---|
75 | float f, float g, float h, float j, float k);
|
---|
76 | // returns matrix for transforming normal
|
---|
77 | friend Matrix4x4 NormalTransformMatrix(const Matrix4x4 &M);
|
---|
78 |
|
---|
79 | friend Matrix4x4 MirrorX();
|
---|
80 | friend Matrix4x4 MirrorY();
|
---|
81 | friend Matrix4x4 MirrorZ();
|
---|
82 | friend Matrix4x4 RotationOnly(const Matrix4x4 &x);
|
---|
83 |
|
---|
84 | // Binary operators
|
---|
85 | friend Matrix4x4 operator+ (const Matrix4x4 &A, const Matrix4x4 &B);
|
---|
86 | friend Matrix4x4 operator- (const Matrix4x4 &A, const Matrix4x4 &B);
|
---|
87 | friend Matrix4x4 operator* (const Matrix4x4 &A, float B);
|
---|
88 | friend Matrix4x4 operator* (const Matrix4x4 &A, const Matrix4x4 &B);
|
---|
89 |
|
---|
90 | // friends returning Vector3
|
---|
91 | friend Vector3 operator*(const Matrix4x4 &M, const Vector3 &v);
|
---|
92 | friend Vector3 RotateOnly(const Matrix4x4 &M, const Vector3 &v);
|
---|
93 | friend Vector3 TransformNormal(const Matrix4x4 &M, const Vector3 &v);
|
---|
94 | friend Vector3 GetTranslation(const Matrix4x4 &M);
|
---|
95 |
|
---|
96 | // Construct rotation description according VRML'97 specification
|
---|
97 | // const CVector4D SFRotation(void) const;
|
---|
98 |
|
---|
99 |
|
---|
100 |
|
---|
101 | // Overloaded output operator.
|
---|
102 | friend std::ostream& operator<< (std::ostream &s, const Matrix4x4 &M);
|
---|
103 | };
|
---|
104 |
|
---|
105 | // forward declaration
|
---|
106 | Matrix4x4 IdentityMatrix();
|
---|
107 | Matrix4x4 Invert(const Matrix4x4 &M); // Invert a given matrix
|
---|
108 | Matrix4x4 Transpose(const Matrix4x4 &M); // Transpose a given matrix
|
---|
109 |
|
---|
110 | // Create various types of matrix.
|
---|
111 | Matrix4x4 IdentityMatrix();
|
---|
112 | Matrix4x4 ZeroMatrix();
|
---|
113 | Matrix4x4 TranslationMatrix(const Vector3 &Location);
|
---|
114 | Matrix4x4 RotationXMatrix(float Angle);
|
---|
115 | Matrix4x4 RotationYMatrix(float Angle);
|
---|
116 | Matrix4x4 RotationZMatrix(float Angle);
|
---|
117 | Matrix4x4 RotationYPRMatrix(float Yaw, float Pitch, float Roll);
|
---|
118 | // about axis 'axis' by angle 'Angle'
|
---|
119 | Matrix4x4 RotationAxisMatrix(const Vector3 &axis, float Angle);
|
---|
120 | // create the rotation matrix that rotates 'vecFrom' to 'vecTo'
|
---|
121 | Matrix4x4 RotationVectorsMatrix(const Vector3 &vecFrom,
|
---|
122 | const Vector3 &vecTo);
|
---|
123 |
|
---|
124 | Matrix4x4 ScaleMatrix(float X, float Y, float Z);
|
---|
125 | Matrix4x4 GenRotation(const Vector3 &x, const Vector3 &y,
|
---|
126 | const Vector3 &z);
|
---|
127 | Matrix4x4 QuadricMatrix(float a, float b, float c, float d, float e,
|
---|
128 | float f, float g, float h, float j, float k);
|
---|
129 | // returns matrix for transforming normal
|
---|
130 | Matrix4x4 NormalTransformMatrix(const Matrix4x4 &M);
|
---|
131 |
|
---|
132 | Matrix4x4 MirrorX();
|
---|
133 | Matrix4x4 MirrorY();
|
---|
134 | Matrix4x4 MirrorZ();
|
---|
135 | Matrix4x4 RotationOnly(const Matrix4x4 &x);
|
---|
136 |
|
---|
137 | // Binary operators
|
---|
138 | Matrix4x4 operator+ (const Matrix4x4 &A, const Matrix4x4 &B);
|
---|
139 | Matrix4x4 operator- (const Matrix4x4 &A, const Matrix4x4 &B);
|
---|
140 | Matrix4x4 operator* (const Matrix4x4 &A, float B);
|
---|
141 | Matrix4x4 operator* (const Matrix4x4 &A, const Matrix4x4 &B);
|
---|
142 |
|
---|
143 | // friends returning Vector3
|
---|
144 | Vector3 operator*(const Matrix4x4 &M, const Vector3 &v);
|
---|
145 | Vector3 RotateOnly(const Matrix4x4 &M, const Vector3 &v);
|
---|
146 | Vector3 TransformNormal(const Matrix4x4 &M, const Vector3 &v);
|
---|
147 | Vector3 GetTranslation(const Matrix4x4 &M);
|
---|
148 |
|
---|
149 |
|
---|
150 | //}
|
---|
151 |
|
---|
152 |
|
---|
153 |
|
---|
154 | #endif
|
---|