73 lines
1.0 KiB
C++
73 lines
1.0 KiB
C++
#include "dl_matrix.h"
|
|
#include "dl_string.h"
|
|
|
|
namespace dl::Mat
|
|
{
|
|
void Test()
|
|
{
|
|
//平移矩阵
|
|
Matrix4 mat0 = Mat::CreateTranslation({ 7, 13, 17 });
|
|
|
|
Matrix4 mat1({
|
|
1, 0, 0, 7,
|
|
0, 1, 0, 13,
|
|
0, 0, 1, 17,
|
|
0, 0, 0, 1
|
|
});
|
|
assert(mat0 == mat1);
|
|
|
|
Position4 pos = { 10, 100, 1000, 1};
|
|
pos = mat0 * pos;
|
|
log(to_string(pos));
|
|
|
|
assert((pos == Position4{17, 113, 1017, 1}));
|
|
|
|
//矩阵乘法
|
|
Matrix<int, 3, 2> mat2({
|
|
1, 2,
|
|
3, 4,
|
|
5, 6
|
|
});
|
|
Matrix<int, 2, 4> mat3({
|
|
1, 2, 3, 4,
|
|
5, 6, 7, 8
|
|
});
|
|
Matrix mat4 = mat2 * mat3;
|
|
decltype(mat4) mat5({
|
|
11, 14, 17, 20,
|
|
23, 30, 37, 44,
|
|
35, 46, 57, 68
|
|
});
|
|
assert(mat4 == mat5);
|
|
|
|
mat0.Dump();
|
|
mat2.Dump();
|
|
mat3.Dump();
|
|
mat4.Dump();
|
|
|
|
//方阵自乘
|
|
mat0 *= mat1;
|
|
mat0.Dump();
|
|
|
|
Matrix4 mat6({
|
|
1, 0, 0, 14,
|
|
0, 1, 0, 26,
|
|
0, 0, 1, 34,
|
|
0, 0, 0, 1
|
|
});
|
|
assert(mat4 == mat5);
|
|
|
|
//逆矩阵
|
|
Matrix4 mat7 = Mat::GetInverse(mat6);
|
|
mat7.Dump();
|
|
Matrix4 mat8({
|
|
1, 0, 0, -14,
|
|
0, 1, 0, -26,
|
|
0, 0, 1, -34,
|
|
0, 0, 0, 1
|
|
});
|
|
assert(mat7 == mat8);
|
|
}
|
|
}
|
|
|