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