@@ -33,14 +33,12 @@ template <class T> struct _quaternion;
3333template <class T >
3434struct _matrix
3535{
36- public:
37- typedef T TYPE;
38- typedef _matrix<T> Self;
39- typedef Self& SelfRef;
40- typedef const Self& SelfCRef;
41- typedef _vector3<T> Tvector;
42-
43- public:
36+ using TYPE = T;
37+ using Self = _matrix<T>;
38+ using SelfRef = Self&;
39+ using SelfCRef = const Self&;
40+ using Tvector = _vector3<T>;
41+
4442 union
4543 {
4644 struct // Direct definition
@@ -50,6 +48,7 @@ struct _matrix
5048 T _31, _32, _33, _34;
5149 T _41, _42, _43, _44;
5250 };
51+
5352 struct
5453 {
5554 Tvector i;
@@ -77,6 +76,7 @@ struct _matrix
7776 _44_ = a._44 ;
7877 return *this ;
7978 }
79+
8080 ICF SelfRef set (const Tvector& R, const Tvector& N, const Tvector& D, const Tvector& C)
8181 {
8282 i.set (R);
@@ -89,6 +89,7 @@ struct _matrix
8989 _44_ = 1 ;
9090 return *this ;
9191 }
92+
9293 SelfRef identity ();
9394 SelfRef rotation (const _quaternion<T>& Q);
9495 SelfRef mk_xform (const _quaternion<T>& Q, const Tvector& V);
@@ -106,6 +107,7 @@ struct _matrix
106107 mul (A, B);
107108 return *this ;
108109 };
110+
109111 IC SelfRef mulB_44 (const Self& B) // mul before
110112 {
111113 Self A;
@@ -148,33 +150,39 @@ struct _matrix
148150 transpose (a);
149151 return *this ;
150152 }
153+
151154 IC SelfRef translate (const Tvector& Loc) // setup translation matrix
152155 {
153156 identity ();
154157 c.set (Loc.x , Loc.y , Loc.z );
155158 return *this ;
156159 }
160+
157161 IC SelfRef translate (T _x, T _y, T _z) // setup translation matrix
158162 {
159163 identity ();
160164 c.set (_x, _y, _z);
161165 return *this ;
162166 }
167+
163168 IC SelfRef translate_over (const Tvector& Loc) // modify only translation
164169 {
165170 c.set (Loc.x , Loc.y , Loc.z );
166171 return *this ;
167172 }
173+
168174 IC SelfRef translate_over (T _x, T _y, T _z) // modify only translation
169175 {
170176 c.set (_x, _y, _z);
171177 return *this ;
172178 }
179+
173180 IC SelfRef translate_add (const Tvector& Loc) // combine translation
174181 {
175182 c.add (Loc);
176183 return *this ;
177184 }
185+
178186 IC SelfRef scale (T x, T y, T z) // setup scale matrix
179187 {
180188 identity ();
@@ -183,6 +191,7 @@ struct _matrix
183191 m[2 ][2 ] = z;
184192 return *this ;
185193 }
194+
186195 IC SelfRef scale (const Tvector& v) // setup scale matrix
187196 {
188197 return scale (v.x , v.y , v.z );
@@ -210,11 +219,13 @@ struct _matrix
210219 m[0 ][0 ] = -1 ;
211220 return *this ;
212221 }
222+
213223 IC SelfRef mirrorX_over ()
214224 {
215225 m[0 ][0 ] = -1 ;
216226 return *this ;
217227 }
228+
218229 IC SelfRef mirrorX_add ()
219230 {
220231 m[0 ][0 ] *= -1 ;
@@ -228,11 +239,13 @@ struct _matrix
228239 m[1 ][1 ] = -1 ;
229240 return *this ;
230241 }
242+
231243 IC SelfRef mirrorY_over ()
232244 {
233245 m[1 ][1 ] = -1 ;
234246 return *this ;
235247 }
248+
236249 IC SelfRef mirrorY_add ()
237250 {
238251 m[1 ][1 ] *= -1 ;
@@ -246,11 +259,13 @@ struct _matrix
246259 m[2 ][2 ] = -1 ;
247260 return *this ;
248261 }
262+
249263 IC SelfRef mirrorZ_over ()
250264 {
251265 m[2 ][2 ] = -1 ;
252266 return *this ;
253267 }
268+
254269 IC SelfRef mirrorZ_add ()
255270 {
256271 m[2 ][2 ] *= -1 ;
@@ -261,11 +276,13 @@ struct _matrix
261276 SelfRef mul (T v);
262277 SelfRef div (const Self& A, T v);
263278 SelfRef div (T v);
279+
264280 // fov
265281 IC SelfRef build_projection (T fFOV , T fAspect , T fNearPlane , T fFarPlane )
266282 {
267283 return build_projection_HAT (tanf (fFOV / 2 .f ), fAspect , fNearPlane , fFarPlane );
268284 }
285+
269286 // half_fov-angle-tangent
270287 IC SelfRef build_projection_HAT (T HAT, T fAspect , T fNearPlane , T fFarPlane )
271288 {
@@ -295,6 +312,7 @@ struct _matrix
295312 _44 = 0 ;
296313 return *this ;
297314 }
315+
298316 IC SelfRef build_projection_ortho (T w, T h, T zn, T zf)
299317 {
300318 _11 = T (2 ) / w;
@@ -315,6 +333,7 @@ struct _matrix
315333 _44 = T (1 );
316334 return *this ;
317335 }
336+
318337 IC SelfRef build_camera (const Tvector& vFrom, const Tvector& vAt, const Tvector& vWorldUp)
319338 {
320339 // Get the z basis vector3, which points straight ahead. This is the
@@ -356,6 +375,7 @@ struct _matrix
356375 _44 = 1 .0f ;
357376 return *this ;
358377 }
378+
359379 IC SelfRef build_camera_dir (const Tvector& vFrom, const Tvector& vView, const Tvector& vWorldUp)
360380 {
361381 // Get the dot product, and calculate the projection of the z basis
@@ -405,36 +425,42 @@ struct _matrix
405425 }
406426 return *this ;
407427 }
428+
408429 ICF void transform_tiny (Tvector& dest, const Tvector& v) const // preferred to use
409430 {
410431 dest.x = v.x * _11 + v.y * _21 + v.z * _31 + _41;
411432 dest.y = v.x * _12 + v.y * _22 + v.z * _32 + _42;
412433 dest.z = v.x * _13 + v.y * _23 + v.z * _33 + _43;
413434 }
435+
414436 ICF void transform_tiny32 (Fvector2& dest, const Tvector& v) const // preferred to use
415437 {
416438 dest.x = v.x * _11 + v.y * _21 + v.z * _31 + _41;
417439 dest.y = v.x * _12 + v.y * _22 + v.z * _32 + _42;
418440 }
441+
419442 ICF void transform_tiny23 (Tvector& dest, const Fvector2& v) const // preferred to use
420443 {
421444 dest.x = v.x * _11 + v.y * _21 + _41;
422445 dest.y = v.x * _12 + v.y * _22 + _42;
423446 dest.z = v.x * _13 + v.y * _23 + _43;
424447 }
448+
425449 ICF void transform_dir (Tvector& dest, const Tvector& v) const // preferred to use
426450 {
427451 dest.x = v.x * _11 + v.y * _21 + v.z * _31;
428452 dest.y = v.x * _12 + v.y * _22 + v.z * _32;
429453 dest.z = v.x * _13 + v.y * _23 + v.z * _33;
430454 }
455+
431456 IC void transform (Fvector4& dest, const Tvector& v) const // preferred to use
432457 {
433458 dest.w = v.x * _14 + v.y * _24 + v.z * _34 + _44;
434459 dest.x = (v.x * _11 + v.y * _21 + v.z * _31 + _41) / dest.w ;
435460 dest.y = (v.x * _12 + v.y * _22 + v.z * _32 + _42) / dest.w ;
436461 dest.z = (v.x * _13 + v.y * _23 + v.z * _33 + _43) / dest.w ;
437462 }
463+
438464 IC void transform (Tvector& dest, const Tvector& v) const // preferred to use
439465 {
440466 T iw = 1 .f / (v.x * _14 + v.y * _24 + v.z * _34 + _44);
@@ -457,6 +483,7 @@ struct _matrix
457483 transform_tiny (res, v);
458484 v.set (res);
459485 }
486+
460487 IC void transform (Tvector& v) const
461488 {
462489 Tvector res;
@@ -480,28 +507,30 @@ struct _matrix
480507 IC void getHPB (Tvector& hpb) const { getHPB (hpb.x , hpb.y , hpb.z ); }
481508 IC void getXYZ (T& x, T& y, T& z) const { getHPB (y, x, z); }
482509 IC void getXYZ (Tvector& xyz) const { getXYZ (xyz.x , xyz.y , xyz.z ); }
510+
483511 IC void getXYZi (T& x, T& y, T& z) const
484512 {
485513 getHPB (y, x, z);
486514 x *= -1 .f ;
487515 y *= -1 .f ;
488516 z *= -1 .f ;
489517 }
518+
490519 IC void getXYZi (Tvector& xyz) const
491520 {
492521 getXYZ (xyz.x , xyz.y , xyz.z );
493522 xyz.mul (-1 .f );
494523 }
495524};
496525
497- typedef _matrix<float > Fmatrix ;
498- typedef _matrix<double > Dmatrix ;
526+ using Fmatrix = _matrix<float >;
527+ using Dmatrix = _matrix<double >;
499528
500529template <class T >
501- BOOL _valid (const _matrix<T>& m)
530+ bool _valid (const _matrix<T>& m)
502531{
503- return _valid (m.i ) && _valid (m._14_ ) && _valid (m.j ) && _valid (m._24_ ) && _valid (m. k ) && _valid (m. _34_ ) &&
504- _valid (m.c ) && _valid (m._44_ );
532+ return _valid (m.i ) && _valid (m._14_ ) && _valid (m.j ) && _valid (m._24_ )
533+ && _valid (m. k ) && _valid (m. _34_ ) && _valid (m.c ) && _valid (m._44_ );
505534}
506535
507536extern XRCORE_API Fmatrix Fidentity;
0 commit comments