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
8namespace sead
9{
10template <typename T>
11class Matrix22;
12
13template <typename T>
14class Matrix33;
15
16template <typename T>
17class Matrix34;
18
19template <typename T>
20class Matrix44;
21
22template <typename T>
23class Matrix22 : public Policies<T>::Mtx22Base
24{
25private:
26 using Self = Matrix22<T>;
27
28public:
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
52template <typename T>
53class Matrix33 : public Policies<T>::Mtx33Base
54{
55private:
56 using Self = Matrix33<T>;
57 using Mtx34 = Matrix34<T>;
58
59 using Vec3 = Vector3<T>;
60
61public:
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
108template <typename T>
109class Matrix34 : public Policies<T>::Mtx34Base
110{
111private:
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
120public:
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 friend Self operator*=(Self& lhs, const Self& rhs)
157 {
158 lhs = lhs * rhs;
159 return lhs;
160 }
161 friend Self operator*=(Mtx33& lhs, const Self& rhs)
162 {
163 lhs = lhs * rhs;
164 return lhs * rhs;
165 }
166
167 void setMul(const Self& a, const Self& b);
168 void setMul(const Mtx33& a, const Self& b);
169
170 void setTranspose(const Self& n);
171 void transpose();
172
173 void fromQuat(const QuatT& q);
174 void makeQT(const QuatT& q, const Vec3& t);
175 void makeR(const Vec3& r);
176 void makeRIdx(u32 xr, u32 yr, u32 zr);
177 void makeRT(const Vec3& r, const Vec3& t);
178 void makeRTIdx(const Vector3<u32>& r, const Vec3& t);
179 void makeRzxyIdx(u32 xr, u32 yr, u32 zr);
180 void makeRzxyTIdx(const Vector3<u32>& r, const Vec3& t);
181 void makeS(const Vec3& s);
182 void makeS(T x, T y, T z);
183 void makeSQT(const Vec3& s, const QuatT& q, const Vec3& t);
184 void makeSR(const Vec3& s, const Vec3& r);
185 void makeSRIdx(const Vec3& s, const Vector3<u32>& r);
186 void makeSRT(const Vec3& s, const Vec3& r, const Vec3& t);
187 void makeSRTIdx(const Vec3& s, const Vector3<u32>& r, const Vec3& t);
188 void makeSRzxyIdx(const Vec3& s, const Vector3<u32>& r);
189 void makeSRzxyTIdx(const Vec3& s, const Vector3<u32>& r, const Vec3& t);
190 void makeST(const Vec3& s, const Vec3& t);
191 void makeT(const Vec3& t);
192 void makeT(T x, T y, T z);
193 void toQuat(QuatT& q) const;
194
195 Vec3 getBase(s32 axis) const;
196 Vec4 getRow(s32 row) const;
197 Vec3 getTranslation() const;
198 Vec3 getRotation() const;
199
200 void getBase(Vec3& o, s32 axis) const;
201 void getRow(Vec4& o, s32 row) const;
202 void getTranslation(Vec3& o) const;
203 void getRotation(Vec3& o) const;
204
205 void scaleAllElements(T s);
206 void scaleBases(T sx, T sy, T sz);
207 void setBase(s32 axis, const Vec3& v);
208 void setRow(s32 row, const Vec4& v);
209 void setTranslation(const Vec3& t);
210 void setTranslation(T x, T y, T z);
211
212 static const Matrix34 zero;
213 static const Matrix34 ident;
214};
215
216template <typename T>
217class Matrix44 : public Policies<T>::Mtx44Base
218{
219private:
220 using Self = Matrix44<T>;
221 using Mtx33 = Matrix33<T>;
222 using Mtx34 = Matrix34<T>;
223
224 using Vec3 = Vector3<T>;
225 using Vec4 = Vector4<T>;
226
227public:
228 Matrix44() {}
229
230 Matrix44(const Self& n) = default;
231
232 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,
233 T _30, T _31, T _32, T _33);
234
235 Matrix44(const Mtx33& mtx33, const Vec3& t = Vec3::zero, const Vec4& vw = Vec4::ew);
236 Matrix44(const Mtx34& mtx34, const Vec4& vw = Vec4::ew);
237
238 T operator()(s32 i, s32 j) const;
239 T& operator()(s32 i, s32 j);
240 Self& operator=(const Self& n);
241
242 void makeIdentity();
243 void makeZero();
244
245 void setInverse(const Self& n);
246 void setInverseTranspose(const Self& n);
247 void setMul(const Self& a, const Self& b);
248 void setMul(const Mtx34& a, const Self& b);
249 void setMul(const Self& a, const Mtx34& b);
250 void setTranspose(const Self& n);
251 void transpose();
252
253 void fromQuat(const Quat<T>& q);
254 void makeR(const Vec3& r);
255 void makeRIdx(u32 xr, u32 yr, u32 zr);
256 void makeRzxyIdx(u32 xr, u32 yr, u32 zr);
257 void toQuat(Quat<T>& q) const;
258
259 Vec4 getCol(s32 axis) const;
260 Vec4 getRow(s32 row) const;
261
262 void getCol(Vec4& o, s32 axis) const;
263 void getRow(Vec4& o, s32 row) const;
264
265 void scaleAllElements(T s);
266 void scaleBases(T sx, T sy, T sz, T sw);
267 void setCol(s32 axis, const Vec4& v);
268 void setRow(s32 row, const Vec4& v);
269
270 static const Matrix44 zero;
271 static const Matrix44 ident;
272};
273
274typedef Matrix22<f32> Matrix22f;
275typedef Matrix33<f32> Matrix33f;
276typedef Matrix34<f32> Matrix34f;
277typedef Matrix44<f32> Matrix44f;
278
279typedef Matrix34<f32> Matrixf;
280
281template <>
282const Matrix22f Matrix22f::zero;
283
284template <>
285const Matrix22f Matrix22f::ident;
286
287template <>
288const Matrix33f Matrix33f::zero;
289
290template <>
291const Matrix33f Matrix33f::ident;
292
293template <>
294const Matrix34f Matrix34f::zero;
295
296template <>
297const Matrix34f Matrix34f::ident;
298
299template <>
300const Matrix44f Matrix44f::zero;
301
302template <>
303const Matrix44f Matrix44f::ident;
304
305template <>
306const Matrix22<f64> Matrix22<f64>::zero;
307
308template <>
309const Matrix22<f64> Matrix22<f64>::ident;
310
311template <>
312const Matrix33<f64> Matrix33<f64>::zero;
313
314template <>
315const Matrix33<f64> Matrix33<f64>::ident;
316
317template <>
318const Matrix34<f64> Matrix34<f64>::zero;
319
320template <>
321const Matrix34<f64> Matrix34<f64>::ident;
322
323template <>
324const Matrix44<f64> Matrix44<f64>::zero;
325
326template <>
327const Matrix44<f64> Matrix44<f64>::ident;
328
329template <typename T>
330bool operator==(const Matrix34<T>& lhs, const Matrix34<T>& rhs);
331template <typename T>
332bool operator!=(const Matrix34<T>& lhs, const Matrix34<T>& rhs);
333
334} // namespace sead
335
336#define SEAD_MATH_MATRIX_H_
337#include <math/seadMatrix.hpp>
338#undef SEAD_MATH_MATRIX_H_
339