37template<
typename T, std::
size_t M, std::
size_t N>
43 static constexpr size_t MN =
M *
N;
55 Matrix(std::initializer_list<T> data)
58 for (
auto iter : data)
84 for (
size_t i = 0; i <
MN; ++i)
111 for (
size_t k = 0; k <
MN; ++k)
120 for (
size_t k = 0; k <
MN; ++k)
133 static_assert(
M ==
N);
134 for (
size_t i = 0; i <
M; ++i)
137 for (
size_t j = 0; j <
N; ++j)
139 for (
size_t k = 0; k <
N; ++k)
140 row[j] +=
_col[k][i] * b[j][k];
142 for (
size_t j = 0; j <
N; ++j)
183 static_assert(
M ==
N);
184 for (
size_t j = 0; j <
N; ++j)
186 for (
size_t i = 0; i <
M; ++i)
200 static_assert(
M ==
N);
201 for (
size_t j = 0; j <
N; ++j)
203 for (
size_t i = 0; i < j; ++i)
212 log_(
"{:=^32}", fmt::format(
"Matrix: {}x{}",
M,
N));
216 for (
size_t i = 0; i <
M; ++i)
218 for (
size_t j = 0; j <
N; ++j)
221 const T& v =
_col[j][i];
222 if (std::abs(v) < 0.00001)
224 else if(v > 0.09 && v < 1.01)
226 else if (v > -1.01 && v < -0.09)
229 str = fmt::format(
"{}", v);
235 for (
size_t i = 0; i <
M; ++i)
238 std::string str =
"Memory: ";
239 for (
size_t k = 0; k <
MN; ++k)
241 str += fmt::format(
"{} ",
_d[k]);
246 const T&
At(
size_t i)
const
267template<
typename T,
size_t M,
size_t N>
270 for (
size_t k = 0; k < Matrix<T, M, N>::MN; ++k)
272 if (a.
At(k) != b.
At(k))
282template<
typename T,
size_t M,
size_t N,
size_t P>
286 for (
size_t j = 0; j <
N; ++j)
288 for (
size_t i = 0; i <
M; ++i)
291 for (
size_t k = 0; k <
P; ++k)
292 ret[j][i] += a[k][i] * b[j][k];
303template<
typename T,
size_t M,
size_t N>
307 for (
size_t i = 0; i <
M; ++i)
309 for (
size_t j = 0; j <
N; ++j)
310 ret[i] += a[j][i] * v[j];
395 for (
size_t i = 0; i < 3; ++i)
Matrix & operator*=(const Matrix &b)
矩阵 乘 矩阵
const Col & operator[](size_t j) const
返回第j列
Matrix(std::initializer_list< T > data)
初始化
Matrix(const T *p)
传入地址构造,注意矩阵存储方式
Matrix & operator+=(const Matrix &b)
矩阵 加 矩阵
Col & operator[](size_t j)
返回第j列
Matrix & operator*=(const T &v)
矩阵 乘 值
const T & At(size_t i) const
static constexpr size_t MN
void Identity()
获得行列式的值,Determinant(A)
void Transpose()
转置(M不等于N时还需另外实现)
Matrix4 CreateRotation(const Position3 &axis, Float angle)
创建旋转矩阵
Matrix4 CreateLookAt(const Position3 &eye, const Position3 &target, const Position3 &up)
创建LookAt矩阵
Matrix4 CreatePerspective(Float fovy, Float aspect, Float z_near, Float z_far)
创建透视投影矩阵 [0, 1]
Matrix4 CreateTranslation(const Position3 &t)
创建平移矩阵
void ApplyTranslation(Matrix4 &m, const Position3 &t)
平移矩阵
Matrix4 GetInverse(const Matrix4 &m)
获得逆矩阵
Position3 ApplyDir(const Matrix4 &mat, const Position3 &dir)
变换向量
Matrix4 CreateOrthogonal(Float left, Float top, Float right, Float bottom, Float z_near, Float z_far)
创建正交投影矩阵 [0, 1]
Matrix4 CreateLookTo(const Position3 &eye, const Position3 &dir, const Position3 &up)
创建LookTo矩阵
Matrix4 CreateScaling(const Position3 &s)
创建缩放矩阵
Matrix4 CreateIdentity()
创建单位矩阵
Matrix3 ToMatrix3(const Matrix4 &mat)
Position3 ApplyDot(const Matrix4 &mat, const Position3 &dot)
变换点
constexpr Position3 AXIS_FORWARD
constexpr ArrayS2< T, N - M > toShorter(const ArrayS2< T, N > &a)
constexpr Array< T, N+M > toLonger(const Array< T, N > &a, const T &v={})
长度+M
constexpr Position3 AXIS_Z
constexpr Position3 AXIS_X
void log(std::string_view str, DL_SOURCE_LOCATION)
以当前设置输出
Matrix< Float, 4, 4 > Matrix4
Array< Float, 3 > Position3
Matrix< Float, 3, 3 > Matrix3
Array< Float, 4 > Position4
constexpr Position3 AXIS_UP
constexpr Position3 AXIS_Y
constexpr ArrayS2< T, N > operator*(const ArrayS2< T, N > &a, const Array< T, 2 > &b)
constexpr bool operator==(const Array< T, N > &a, const Array< T, N > &b)