30template<
typename T, std::
size_t M, std::
size_t N>
36 static constexpr size_t MN =
M *
N;
48 Matrix(std::initializer_list<T> data)
51 for (
auto iter : data)
77 for (
size_t i = 0; i <
MN; ++i)
104 for (
size_t k = 0; k <
MN; ++k)
113 for (
size_t k = 0; k <
MN; ++k)
126 static_assert(
M ==
N);
127 for (
size_t i = 0; i <
M; ++i)
130 for (
size_t j = 0; j <
N; ++j)
132 for (
size_t k = 0; k <
N; ++k)
133 row[j] +=
_col[k][i] * b[j][k];
135 for (
size_t j = 0; j <
N; ++j)
176 static_assert(
M ==
N);
177 for (
size_t j = 0; j <
N; ++j)
179 for (
size_t i = 0; i <
M; ++i)
193 static_assert(
M ==
N);
194 for (
size_t j = 0; j <
N; ++j)
196 for (
size_t i = 0; i < j; ++i)
205 log_(
"{:=^32}", fmt::format(
"Matrix: {}x{}",
M,
N));
209 for (
size_t i = 0; i <
M; ++i)
211 for (
size_t j = 0; j <
N; ++j)
213 str_wh[i][j] = fmt::format(
"{}",
_col[j][i]);
218 for (
size_t i = 0; i <
M; ++i)
221 std::string str =
"Memory: ";
222 for (
size_t k = 0; k <
MN; ++k)
224 str += fmt::format(
"{} ",
_d[k]);
229 const T&
At(
size_t i)
const
249template<
typename T,
size_t M,
size_t N>
252 for (
size_t k = 0; k < Matrix<T, M, N>::MN; ++k)
254 if (a.
At(k) != b.
At(k))
264template<
typename T,
size_t M,
size_t N,
size_t P>
268 for (
size_t j = 0; j <
N; ++j)
270 for (
size_t i = 0; i <
M; ++i)
273 for (
size_t k = 0; k <
P; ++k)
274 ret[j][i] += a[k][i] * b[j][k];
285template<
typename T,
size_t M,
size_t N>
289 for (
size_t i = 0; i <
M; ++i)
291 for (
size_t j = 0; j <
N; ++j)
292 ret[i] += a[j][i] * v[j];
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 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)
获得逆矩阵
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()
创建单位矩阵
Matrix< Float, 4, 4 > Matrix4
void log(std::string_view str, const std::source_location location=std::source_location::current())
以当前设置输出
Array< Float, 3 > Position3
Array< Float, 4 > Position4
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)