Files
XCEngine/engine/include/XCEngine/Math/Matrix4.h
ssdfasd 7c54a62f9e feat: 添加Math库和Google Test测试框架
- 新增Math库: Vector2/3/4, Matrix3/4, Quaternion, Transform, Color等
- 新增测试框架: Google Test (gtest)
- 新增140个单元测试,覆盖Vector, Matrix, Quaternion, Geometry
- VolumeRenderer支持vcpkg的NanoVDB
- 添加TESTING.md测试文档
2026-03-13 18:43:14 +08:00

67 lines
1.9 KiB
C++

#pragma once
#include "Math.h"
#include "Vector3.h"
#include "Vector4.h"
namespace XCEngine {
namespace Math {
struct Quaternion;
struct Matrix4x4 {
public:
float m[4][4];
Matrix4x4() {
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
m[i][j] = 0.0f;
}
static Matrix4x4 Identity() {
Matrix4x4 result;
result.m[0][0] = 1.0f;
result.m[1][1] = 1.0f;
result.m[2][2] = 1.0f;
result.m[3][3] = 1.0f;
return result;
}
static Matrix4x4 Zero() {
return Matrix4x4();
}
static Matrix4x4 Translation(const Vector3& v);
static Matrix4x4 Rotation(const Quaternion& q);
static Matrix4x4 Scale(const Vector3& v);
static Matrix4x4 TRS(const Vector3& translation, const Quaternion& rotation, const Vector3& scale);
static Matrix4x4 LookAt(const Vector3& eye, const Vector3& target, const Vector3& up);
static Matrix4x4 Perspective(float fov, float aspect, float near, float far);
static Matrix4x4 Orthographic(float left, float right, float bottom, float top, float near, float far);
static Matrix4x4 RotationX(float radians);
static Matrix4x4 RotationY(float radians);
static Matrix4x4 RotationZ(float radians);
Matrix4x4 operator*(const Matrix4x4& other) const;
Vector4 operator*(const Vector4& v) const;
Vector3 MultiplyPoint(const Vector3& v) const;
Vector3 MultiplyVector(const Vector3& v) const;
Matrix4x4 Transpose() const;
Matrix4x4 Inverse() const;
float Determinant() const;
Vector3 GetTranslation() const;
Quaternion GetRotation() const;
Vector3 GetScale() const;
void Decompose(Vector3& translation, Quaternion& rotation, Vector3& scale) const;
float* operator[](int row) { return m[row]; }
const float* operator[](int row) const { return m[row]; }
};
using Matrix4 = Matrix4x4;
} // namespace Math
} // namespace XCEngine