Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 94daeaa

Browse files
AlBuSoft_RTX3070AlBuSoft_RTX3070
authored andcommitted
#98 Matrix4x4 finished binary operators and some fixes for these
1 parent f64ab36 commit 94daeaa

File tree

6 files changed

+205
-175
lines changed

6 files changed

+205
-175
lines changed

Libs/ecm.math.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
<ItemGroup>
180180
<ClInclude Include="ecm\ecm_math.hpp" />
181181
<ClInclude Include="ecm\math\functions.hpp" />
182+
<ClInclude Include="ecm\math\matrix.hpp" />
182183
<ClInclude Include="ecm\math\matrix4x4.hpp" />
183184
<ClInclude Include="ecm\math\vector.hpp" />
184185
<ClInclude Include="ecm\math\vector2.hpp" />

Libs/ecm/ecm_math.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include "math/functions.hpp"
1212

1313
#include "math/vector.hpp"
14-
#include "math/vector4.hpp"
15-
16-
#include "math/matrix4x4.hpp"
14+
#include "math/matrix.hpp"
1715

1816
#endif // !_ECM_MATH_HPP_

Libs/ecm/math/matrix.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
#ifndef _ECM_MATRIX_H_
3+
#define _ECM_MATRIX_H_
4+
5+
#include "matrix4x4.hpp"
6+
7+
namespace ecm::math
8+
{
9+
// Matrix4x4
10+
11+
using Matrix4x4 = Matrix4x4_Base<float32>;
12+
13+
using Matrix4x4A = ECM_ALIGN(16) Matrix4x4;
14+
15+
using Matrix4x4i = Matrix4x4_Base<int32>;
16+
17+
using Matrix4x4iA = ECM_ALIGN(16) Matrix4x4i;
18+
19+
using Matrix4x4u = Matrix4x4_Base<uint32>;
20+
21+
using Matrix4x4uA = ECM_ALIGN(16) Matrix4x4u;
22+
} // namespace ecm::math
23+
24+
#endif // !_ECM_MATRIX_H_

Libs/ecm/math/matrix4x4.hpp

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <ecm/ecm_api.h>
1212
#include <ecm/ecm_types.hpp>
13-
#include "vector.hpp"
13+
#include "vector3.hpp"
1414

1515
#include <type_traits>
1616

@@ -106,6 +106,8 @@ namespace ecm::math
106106

107107
// Unary arithmetic operators
108108

109+
constexpr Matrix4x4_Base<T>& operator=(Matrix4x4_Base<T> const& m);
110+
109111
template<typename U, typename = std::enable_if_t<std::is_arithmetic<U>::value>>
110112
constexpr Matrix4x4_Base<T>& operator=(Matrix4x4_Base<U> const& m);
111113

@@ -212,18 +214,6 @@ namespace ecm::math
212214

213215

214216

215-
// TODO: Only temporary
216-
struct Matrix4x4 : public Matrix4x4_Base<float>
217-
{
218-
using Matrix4x4_Base<float>::Matrix4x4_Base;
219-
};
220-
221-
// TODO: Only temporary
222-
__declspec(align(16)) struct Matrix4x4A : public Matrix4x4
223-
{
224-
using Matrix4x4::Matrix4x4;
225-
};
226-
227217
/*
228218
* This function sets a translation matrix with given translation values.
229219
*
@@ -235,9 +225,10 @@ namespace ecm::math
235225
*
236226
* \since v1.0.0
237227
*
238-
* \sa Matrix4x4
228+
* \sa Matrix4x4_Base
239229
*/
240-
ECM_INLINE Matrix4x4 SetTranslation(float32 tx, float32 ty, float32 tz);
230+
template<typename T>
231+
ECM_INLINE Matrix4x4_Base<T> SetTranslation(float32 tx, float32 ty, float32 tz);
241232

242233
/*
243234
* This function sets a translation matrix with a given vector.
@@ -248,10 +239,11 @@ namespace ecm::math
248239
*
249240
* \since v1.0.0
250241
*
251-
* \sa Matrix4x4
242+
* \sa Matrix4x4_Base
252243
* \sa Vector3
253244
*/
254-
ECM_INLINE Matrix4x4 SetTranslation(const Vector3& t);
245+
template<typename T>
246+
ECM_INLINE Matrix4x4_Base<T> SetTranslation(const Vector3_Base<T>& t);
255247

256248
/*
257249
* This function translates a matrix with given translation values.
@@ -265,9 +257,10 @@ namespace ecm::math
265257
*
266258
* \since v1.0.0
267259
*
268-
* \sa Matrix4x4
260+
* \sa Matrix4x4_Base
269261
*/
270-
ECM_INLINE Matrix4x4 Translate(const Matrix4x4& mat, float32 tx, float32 ty, float32 tz);
262+
template<typename T>
263+
ECM_INLINE Matrix4x4_Base<T> Translate(const Matrix4x4_Base<T>& mat, float32 tx, float32 ty, float32 tz);
271264

272265
/*
273266
* This function translates a matrix with a given vector.
@@ -279,10 +272,11 @@ namespace ecm::math
279272
*
280273
* \since v1.0.0
281274
*
282-
* \sa Matrix4x4
275+
* \sa Matrix4x4_Base
283276
* \sa Vector3
284277
*/
285-
ECM_INLINE Matrix4x4 Translate(const Matrix4x4& mat, const Vector3& t);
278+
template<typename T>
279+
ECM_INLINE Matrix4x4_Base<T> Translate(const Matrix4x4_Base<T>& mat, const Vector3_Base<T>& t);
286280

287281
/*
288282
* This function sets a scale matrix with given scale values.
@@ -295,9 +289,10 @@ namespace ecm::math
295289
*
296290
* \since v1.0.0
297291
*
298-
* \sa Matrix4x4
292+
* \sa Matrix4x4_Base
299293
*/
300-
ECM_INLINE Matrix4x4 SetScale(float32 sx, float32 sy, float32 sz);
294+
template<typename T>
295+
ECM_INLINE Matrix4x4_Base<T> SetScale(float32 sx, float32 sy, float32 sz);
301296

302297
/*
303298
* This function sets a scale matrix with a given vector.
@@ -308,10 +303,11 @@ namespace ecm::math
308303
*
309304
* \since v1.0.0
310305
*
311-
* \sa Matrix4x4
306+
* \sa Matrix4x4_Base
312307
* \sa Vector3
313308
*/
314-
ECM_INLINE Matrix4x4 SetScale(const Vector3& s);
309+
template<typename T>
310+
ECM_INLINE Matrix4x4_Base<T> SetScale(const Vector3_Base<T>& s);
315311

316312
/*
317313
* This function scales a matrix with given scale values.
@@ -325,9 +321,10 @@ namespace ecm::math
325321
*
326322
* \since v1.0.0
327323
*
328-
* \sa Matrix4x4
324+
* \sa Matrix4x4_Base
329325
*/
330-
ECM_INLINE Matrix4x4 Scale(const Matrix4x4& mat, float32 sx, float32 sy, float32 sz);
326+
template<typename T>
327+
ECM_INLINE Matrix4x4_Base<T> Scale(const Matrix4x4_Base<T>& mat, float32 sx, float32 sy, float32 sz);
331328

332329
/*
333330
* This function scales a matrix with a given vector.
@@ -339,10 +336,11 @@ namespace ecm::math
339336
*
340337
* \since v1.0.0
341338
*
342-
* \sa Matrix4x4
339+
* \sa Matrix4x4_Base
343340
* \sa Vector3
344341
*/
345-
ECM_INLINE Matrix4x4 Scale(const Matrix4x4& mat, const Vector3& s);
342+
template<typename T>
343+
ECM_INLINE Matrix4x4_Base<T> Scale(const Matrix4x4_Base<T>& mat, const Vector3_Base<T>& s);
346344

347345
/*
348346
* This function sets a rotation matrix around the x-axis with a given angle.
@@ -353,9 +351,10 @@ namespace ecm::math
353351
*
354352
* \since v1.0.0
355353
*
356-
* \sa Matrix4x4
354+
* \sa Matrix4x4_Base
357355
*/
358-
ECM_INLINE Matrix4x4 SetRotationX(float32 angle);
356+
template<typename T>
357+
ECM_INLINE Matrix4x4_Base<T> SetRotationX(float32 angle);
359358

360359
/*
361360
* This function rotates a matrix around the x-axis with a given angle.
@@ -367,9 +366,10 @@ namespace ecm::math
367366
*
368367
* \since v1.0.0
369368
*
370-
* \sa Matrix4x4
369+
* \sa Matrix4x4_Base
371370
*/
372-
ECM_INLINE Matrix4x4 RotateX(const Matrix4x4& mat, float32 angle);
371+
template<typename T>
372+
ECM_INLINE Matrix4x4_Base<T> RotateX(const Matrix4x4_Base<T>& mat, float32 angle);
373373

374374
/*
375375
* This function sets a rotation matrix around the y-axis with a given angle.
@@ -380,9 +380,10 @@ namespace ecm::math
380380
*
381381
* \since v1.0.0
382382
*
383-
* \sa Matrix4x4
383+
* \sa Matrix4x4_Base
384384
*/
385-
ECM_INLINE Matrix4x4 SetRotationY(float32 angle);
385+
template<typename T>
386+
ECM_INLINE Matrix4x4_Base<T> SetRotationY(float32 angle);
386387

387388
/*
388389
* This function rotates a matrix around the y-axis with a given angle.
@@ -394,9 +395,10 @@ namespace ecm::math
394395
*
395396
* \since v1.0.0
396397
*
397-
* \sa Matrix4x4
398+
* \sa Matrix4x4_Base
398399
*/
399-
ECM_INLINE Matrix4x4 RotateY(const Matrix4x4& mat, float32 angle);
400+
template<typename T>
401+
ECM_INLINE Matrix4x4_Base<T> RotateY(const Matrix4x4_Base<T>& mat, float32 angle);
400402

401403
/*
402404
* This function sets a rotation matrix around the z-axis with a given angle.
@@ -407,9 +409,10 @@ namespace ecm::math
407409
*
408410
* \since v1.0.0
409411
*
410-
* \sa Matrix4x4
412+
* \sa Matrix4x4_Base
411413
*/
412-
ECM_INLINE Matrix4x4 SetRotationZ(float32 angle);
414+
template<typename T>
415+
ECM_INLINE Matrix4x4_Base<T> SetRotationZ(float32 angle);
413416

414417
/*
415418
* This function rotates a matrix around the z-axis with a given angle.
@@ -421,9 +424,10 @@ namespace ecm::math
421424
*
422425
* \since v1.0.0
423426
*
424-
* \sa Matrix4x4
427+
* \sa Matrix4x4_Base
425428
*/
426-
ECM_INLINE Matrix4x4 RotateZ(const Matrix4x4& mat, float32 angle);
429+
template<typename T>
430+
ECM_INLINE Matrix4x4_Base<T> RotateZ(const Matrix4x4_Base<T>& mat, float32 angle);
427431

428432
/*
429433
* This function sets a rotation matrix around an arbitrary axis with a
@@ -438,9 +442,10 @@ namespace ecm::math
438442
*
439443
* \since v1.0.0
440444
*
441-
* \sa Matrix4x4
445+
* \sa Matrix4x4_Base
442446
*/
443-
ECM_INLINE Matrix4x4 SetRotation(float32 angle, float32 x, float32 y, float32 z);
447+
template<typename T>
448+
ECM_INLINE Matrix4x4_Base<T> SetRotation(float32 angle, float32 x, float32 y, float32 z);
444449

445450
/*
446451
* This function sets a rotation matrix around an arbitrary axis with a
@@ -453,10 +458,11 @@ namespace ecm::math
453458
*
454459
* \since v1.0.0
455460
*
456-
* \sa Matrix4x4
461+
* \sa Matrix4x4_Base
457462
* \sa Vector3
458463
*/
459-
ECM_INLINE Matrix4x4 SetRotation(float32 angle, const Vector3& r);
464+
template<typename T>
465+
ECM_INLINE Matrix4x4_Base<T> SetRotation(float32 angle, const Vector3_Base<T>& r);
460466

461467
/*
462468
* This function rotates a matrix around an arbitrary axis with given axis
@@ -472,9 +478,10 @@ namespace ecm::math
472478
*
473479
* \since v1.0.0
474480
*
475-
* \sa Matrix4x4
481+
* \sa Matrix4x4_Base
476482
*/
477-
ECM_INLINE Matrix4x4 Rotate(const Matrix4x4& mat, float32 angle, float32 x, float32 y, float32 z);
483+
template<typename T>
484+
ECM_INLINE Matrix4x4_Base<T> Rotate(const Matrix4x4_Base<T>& mat, float32 angle, float32 x, float32 y, float32 z);
478485

479486
/*
480487
* This function rotates a matrix around an arbitrary axis with given vector.
@@ -487,9 +494,10 @@ namespace ecm::math
487494
*
488495
* \since v1.0.0
489496
*
490-
* \sa Matrix4x4
497+
* \sa Matrix4x4_Base
491498
*/
492-
ECM_INLINE Matrix4x4 Rotate(const Matrix4x4& mat, float32 angle, const Vector3& r);
499+
template<typename T>
500+
ECM_INLINE Matrix4x4_Base<T> Rotate(const Matrix4x4_Base<T>& mat, float32 angle, const Vector3_Base<T>& r);
493501
} // namespace ecm::math
494502

495503
#include "matrix4x4.inl"

0 commit comments

Comments
 (0)