2023-08-10 18:53:35 +08:00
|
|
|
#include "math/MathBase.h"
|
2020-08-04 00:14:35 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_MATH_BEGIN
|
2020-08-04 00:14:35 +08:00
|
|
|
|
2023-08-10 18:53:35 +08:00
|
|
|
// both metal and GLSL3/ESSL3 mat3 is identical to mat3x4,
|
|
|
|
// so provide this helper struct to construct mat3 match with GPU
|
|
|
|
struct Mat3
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
2023-08-10 18:53:35 +08:00
|
|
|
enum Index
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
2023-08-10 18:53:35 +08:00
|
|
|
_M00 = 0,
|
|
|
|
_M01 = 1,
|
|
|
|
_M02 = 2,
|
|
|
|
_M10 = 4,
|
|
|
|
_M11 = 5,
|
|
|
|
_M12 = 6,
|
|
|
|
_M20 = 8,
|
|
|
|
_M21 = 9,
|
|
|
|
_M22 = 10
|
|
|
|
};
|
|
|
|
Mat3() = default;
|
|
|
|
Mat3(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
|
2023-08-09 13:52:28 +08:00
|
|
|
{
|
2023-08-10 18:53:35 +08:00
|
|
|
this->set(m00, m01, m02, m10, m11, m12, m20, m21, m22);
|
2023-07-27 22:36:51 +08:00
|
|
|
}
|
2023-08-10 18:53:35 +08:00
|
|
|
void set(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
|
2023-08-10 18:36:45 +08:00
|
|
|
{
|
2023-08-10 18:53:35 +08:00
|
|
|
m[_M00] = m00;
|
|
|
|
m[_M01] = m01;
|
|
|
|
m[_M02] = m02;
|
|
|
|
// 0 3 = 0 * 4 + 3 = 3
|
|
|
|
m[_M10] = m10;
|
|
|
|
m[_M11] = m11;
|
|
|
|
m[_M12] = m12;
|
|
|
|
// 1 3 = 1 * 4 + 3 = 7
|
|
|
|
m[_M20] = m20;
|
|
|
|
m[_M21] = m21;
|
|
|
|
m[_M22] = m22;
|
|
|
|
// 2 3 = 2 * 4 + 3 = 11
|
2023-08-09 14:37:43 +08:00
|
|
|
}
|
2023-08-10 18:53:35 +08:00
|
|
|
float* operator[](size_t rowIndex) {
|
|
|
|
assert(rowIndex < 3);
|
|
|
|
return &m[rowIndex * 4];
|
|
|
|
}
|
|
|
|
float m[12] = {};
|
2020-08-04 00:14:35 +08:00
|
|
|
};
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_MATH_END
|