1 | #pragma once |
2 | |
3 | #include <basis/seadTypes.h> |
4 | #include <math/seadMathPolicies.h> |
5 | #include <math/seadQuat.h> |
6 | #include <math/seadVector.h> |
7 | |
8 | namespace sead |
9 | { |
10 | template <typename T> |
11 | class Matrix22; |
12 | |
13 | template <typename T> |
14 | class Matrix33; |
15 | |
16 | template <typename T> |
17 | class Matrix34; |
18 | |
19 | template <typename T> |
20 | class Matrix44; |
21 | |
22 | template <typename T> |
23 | class Matrix22 : public Policies<T>::Mtx22Base |
24 | { |
25 | private: |
26 | using Self = Matrix22<T>; |
27 | |
28 | public: |
29 | Matrix22() {} |
30 | |
31 | Matrix22(const Self& n) = default; |
32 | |
33 | Matrix22(T a00, T a01, T a10, T a11); |
34 | |
35 | T operator()(s32 i, s32 j) const; |
36 | T& operator()(s32 i, s32 j); |
37 | Self& operator=(const Self& n); |
38 | |
39 | void makeIdentity(); |
40 | void makeZero(); |
41 | |
42 | void setInverse(const Self& n); |
43 | void setInverseTranspose(const Self& n); |
44 | void setMul(const Self& a, const Self& b); |
45 | void setTranspose(const Self& n); |
46 | void transpose(); |
47 | |
48 | static const Matrix22 zero; |
49 | static const Matrix22 ident; |
50 | }; |
51 | |
52 | template <typename T> |
53 | class Matrix33 : public Policies<T>::Mtx33Base |
54 | { |
55 | private: |
56 | using Self = Matrix33<T>; |
57 | using Mtx34 = Matrix34<T>; |
58 | |
59 | using Vec3 = Vector3<T>; |
60 | |
61 | public: |
62 | Matrix33() {} |
63 | |
64 | Matrix33(const Self& n) = default; |
65 | |
66 | Matrix33(T a00, T a01, T a02, T a10, T a11, T a12, T a20, T a21, T a22); |
67 | |
68 | Matrix33(const Mtx34& mtx34); |
69 | |
70 | T operator()(s32 i, s32 j) const; |
71 | T& operator()(s32 i, s32 j); |
72 | Self& operator=(const Self& n); |
73 | |
74 | void makeIdentity(); |
75 | void makeZero(); |
76 | |
77 | void setInverse(const Self& n); |
78 | void setInverseTranspose(const Self& n); |
79 | void setMul(const Self& a, const Self& b); |
80 | void setMul(const Mtx34& a, const Self& b); |
81 | void setMul(const Self& a, const Mtx34& b); |
82 | void setTranspose(const Self& n); |
83 | void transpose(); |
84 | |
85 | void fromQuat(const Quat<T>& q); |
86 | void makeR(const Vec3& r); |
87 | void makeRIdx(u32 xr, u32 yr, u32 zr); |
88 | void makeRzxyIdx(u32 xr, u32 yr, u32 zr); |
89 | void makeS(const Vec3& s); |
90 | void makeS(T x, T y, T z); |
91 | void makeSR(const Vec3& s, const Vec3& r); |
92 | void makeSRIdx(const Vec3& s, const Vector3<u32>& r); |
93 | void makeSRzxyIdx(const Vec3& s, const Vector3<u32>& r); |
94 | void toQuat(Quat<T>& q) const; |
95 | |
96 | Vec3 getBase(s32 axis) const; |
97 | Vec3 getRow(s32 row) const; |
98 | |
99 | void getBase(Vec3& o, s32 axis) const; |
100 | void getRow(Vec3& o, s32 row) const; |
101 | void setBase(s32 axis, const Vec3& v); |
102 | void setRow(s32 row, const Vec3& v); |
103 | |
104 | static const Matrix33 zero; |
105 | static const Matrix33 ident; |
106 | }; |
107 | |
108 | template <typename T> |
109 | class Matrix34 : public Policies<T>::Mtx34Base |
110 | { |
111 | private: |
112 | using Self = Matrix34<T>; |
113 | using Mtx33 = Matrix33<T>; |
114 | using Mtx44 = Matrix44<T>; |
115 | |
116 | using Vec3 = Vector3<T>; |
117 | using Vec4 = Vector4<T>; |
118 | using QuatT = Quat<T>; |
119 | |
120 | public: |
121 | Matrix34() {} |
122 | |
123 | Matrix34(const Self& n) = default; |
124 | |
125 | Matrix34(T _00, T _01, T _02, T _03, T _10, T _11, T _12, T _13, T _20, T _21, T _22, T _23); |
126 | |
127 | Matrix34(const Mtx33& mtx33, const Vec3& t = Vec3::zero); |
128 | Matrix34(const Mtx44& mtx44); |
129 | |
130 | T operator()(s32 i, s32 j) const; |
131 | T& operator()(s32 i, s32 j); |
132 | Self& operator=(const Self& n); |
133 | |
134 | void makeIdentity(); |
135 | void makeZero(); |
136 | |
137 | bool invert(); |
138 | bool invert33(); |
139 | bool invertTranspose(); |
140 | bool setInverse(const Self& n); |
141 | bool setInverse33(const Self& n); |
142 | bool setInverseTranspose(const Self& n); |
143 | |
144 | friend Self operator*(const Self& lhs, const Self& rhs) |
145 | { |
146 | Self result; |
147 | result.setMul(lhs, rhs); |
148 | return result; |
149 | } |
150 | friend Self operator*(const Mtx33& lhs, const Self& rhs) |
151 | { |
152 | Self result; |
153 | result.setMul(lhs, rhs); |
154 | return result; |
155 | } |
156 | void setMul(const Self& a, const Self& b); |
157 | void setMul(const Mtx33& a, const Self& b); |
158 | |
159 | void setTranspose(const Self& n); |
160 | void transpose(); |
161 | |
162 | void fromQuat(const QuatT& q); |
163 | void makeQT(const QuatT& q, const Vec3& t); |
164 | void makeR(const Vec3& r); |
165 | void makeRIdx(u32 xr, u32 yr, u32 zr); |
166 | void makeRT(const Vec3& r, const Vec3& t); |
167 | void makeRTIdx(const Vector3<u32>& r, const Vec3& t); |
168 | void makeRzxyIdx(u32 xr, u32 yr, u32 zr); |
169 | void makeRzxyTIdx(const Vector3<u32>& r, const Vec3& t); |
170 | void makeS(const Vec3& s); |
171 | void makeS(T x, T y, T z); |
172 | void makeSQT(const Vec3& s, const QuatT& q, const Vec3& t); |
173 | void makeSR(const Vec3& s, const Vec3& r); |
174 | void makeSRIdx(const Vec3& s, const Vector3<u32>& r); |
175 | void makeSRT(const Vec3& s, const Vec3& r, const Vec3& t); |
176 | void makeSRTIdx(const Vec3& s, const Vector3<u32>& r, const Vec3& t); |
177 | void makeSRzxyIdx(const Vec3& s, const Vector3<u32>& r); |
178 | void makeSRzxyTIdx(const Vec3& s, const Vector3<u32>& r, const Vec3& t); |
179 | void makeST(const Vec3& s, const Vec3& t); |
180 | void makeT(const Vec3& t); |
181 | void makeT(T x, T y, T z); |
182 | void toQuat(QuatT& q) const; |
183 | |
184 | Vec3 getBase(s32 axis) const; |
185 | Vec4 getRow(s32 row) const; |
186 | Vec3 getTranslation() const; |
187 | Vec3 getRotation() const; |
188 | |
189 | void getBase(Vec3& o, s32 axis) const; |
190 | void getRow(Vec4& o, s32 row) const; |
191 | void getTranslation(Vec3& o) const; |
192 | void getRotation(Vec3& o) const; |
193 | |
194 | void scaleAllElements(T s); |
195 | void scaleBases(T sx, T sy, T sz); |
196 | void setBase(s32 axis, const Vec3& v); |
197 | void setRow(s32 row, const Vec4& v); |
198 | void setTranslation(const Vec3& t); |
199 | void setTranslation(T x, T y, T z); |
200 | |
201 | static const Matrix34 zero; |
202 | static const Matrix34 ident; |
203 | }; |
204 | |
205 | template <typename T> |
206 | class Matrix44 : public Policies<T>::Mtx44Base |
207 | { |
208 | private: |
209 | using Self = Matrix44<T>; |
210 | using Mtx33 = Matrix33<T>; |
211 | using Mtx34 = Matrix34<T>; |
212 | |
213 | using Vec3 = Vector3<T>; |
214 | using Vec4 = Vector4<T>; |
215 | |
216 | public: |
217 | Matrix44() {} |
218 | |
219 | Matrix44(const Self& n) = default; |
220 | |
221 | Matrix44(T _00, T _01, T _02, T _03, T _10, T _11, T _12, T _13, T _20, T _21, T _22, T _23, |
222 | T _30, T _31, T _32, T _33); |
223 | |
224 | Matrix44(const Mtx33& mtx33, const Vec3& t = Vec3::zero, const Vec4& vw = Vec4::ew); |
225 | Matrix44(const Mtx34& mtx34, const Vec4& vw = Vec4::ew); |
226 | |
227 | T operator()(s32 i, s32 j) const; |
228 | T& operator()(s32 i, s32 j); |
229 | Self& operator=(const Self& n); |
230 | |
231 | void makeIdentity(); |
232 | void makeZero(); |
233 | |
234 | void setInverse(const Self& n); |
235 | void setInverseTranspose(const Self& n); |
236 | void setMul(const Self& a, const Self& b); |
237 | void setMul(const Mtx34& a, const Self& b); |
238 | void setMul(const Self& a, const Mtx34& b); |
239 | void setTranspose(const Self& n); |
240 | void transpose(); |
241 | |
242 | void fromQuat(const Quat<T>& q); |
243 | void makeR(const Vec3& r); |
244 | void makeRIdx(u32 xr, u32 yr, u32 zr); |
245 | void makeRzxyIdx(u32 xr, u32 yr, u32 zr); |
246 | void toQuat(Quat<T>& q) const; |
247 | |
248 | Vec4 getCol(s32 axis) const; |
249 | Vec4 getRow(s32 row) const; |
250 | |
251 | void getCol(Vec4& o, s32 axis) const; |
252 | void getRow(Vec4& o, s32 row) const; |
253 | |
254 | void scaleAllElements(T s); |
255 | void scaleBases(T sx, T sy, T sz, T sw); |
256 | void setCol(s32 axis, const Vec4& v); |
257 | void setRow(s32 row, const Vec4& v); |
258 | |
259 | static const Matrix44 zero; |
260 | static const Matrix44 ident; |
261 | }; |
262 | |
263 | typedef Matrix22<f32> Matrix22f; |
264 | typedef Matrix33<f32> Matrix33f; |
265 | typedef Matrix34<f32> Matrix34f; |
266 | typedef Matrix44<f32> Matrix44f; |
267 | |
268 | typedef Matrix34<f32> Matrixf; |
269 | |
270 | template <> |
271 | const Matrix22f Matrix22f::zero; |
272 | |
273 | template <> |
274 | const Matrix22f Matrix22f::ident; |
275 | |
276 | template <> |
277 | const Matrix33f Matrix33f::zero; |
278 | |
279 | template <> |
280 | const Matrix33f Matrix33f::ident; |
281 | |
282 | template <> |
283 | const Matrix34f Matrix34f::zero; |
284 | |
285 | template <> |
286 | const Matrix34f Matrix34f::ident; |
287 | |
288 | template <> |
289 | const Matrix44f Matrix44f::zero; |
290 | |
291 | template <> |
292 | const Matrix44f Matrix44f::ident; |
293 | |
294 | template <> |
295 | const Matrix22<f64> Matrix22<f64>::zero; |
296 | |
297 | template <> |
298 | const Matrix22<f64> Matrix22<f64>::ident; |
299 | |
300 | template <> |
301 | const Matrix33<f64> Matrix33<f64>::zero; |
302 | |
303 | template <> |
304 | const Matrix33<f64> Matrix33<f64>::ident; |
305 | |
306 | template <> |
307 | const Matrix34<f64> Matrix34<f64>::zero; |
308 | |
309 | template <> |
310 | const Matrix34<f64> Matrix34<f64>::ident; |
311 | |
312 | template <> |
313 | const Matrix44<f64> Matrix44<f64>::zero; |
314 | |
315 | template <> |
316 | const Matrix44<f64> Matrix44<f64>::ident; |
317 | |
318 | template <typename T> |
319 | bool operator==(const Matrix34<T>& lhs, const Matrix34<T>& rhs); |
320 | template <typename T> |
321 | bool operator!=(const Matrix34<T>& lhs, const Matrix34<T>& rhs); |
322 | |
323 | } // namespace sead |
324 | |
325 | #define SEAD_MATH_MATRIX_H_ |
326 | #include <math/seadMatrix.hpp> |
327 | #undef SEAD_MATH_MATRIX_H_ |
328 | |