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测试文档
This commit is contained in:
2026-03-13 18:43:14 +08:00
parent 5efa171050
commit 7c54a62f9e
41 changed files with 8530 additions and 1845 deletions

View File

@@ -0,0 +1,44 @@
#include "Math/Transform.h"
#include "Math/Matrix4.h"
namespace XCEngine {
namespace Math {
Matrix4 Transform::ToMatrix() const {
return Matrix4x4::TRS(position, rotation, scale);
}
Transform Transform::Inverse() const {
Transform result;
result.rotation = rotation.Inverse();
result.scale = Vector3::One() / scale;
result.position = result.rotation * (Vector3::Zero() - position) * result.scale;
return result;
}
Transform Transform::operator*(const Transform& other) const {
Transform result;
result.position = position + rotation * (scale * other.position);
result.rotation = rotation * other.rotation;
result.scale = scale * other.scale;
return result;
}
Vector3 Transform::TransformPoint(const Vector3& point) const {
return position + rotation * (scale * point);
}
Vector3 Transform::TransformDirection(const Vector3& direction) const {
return rotation * (scale * direction);
}
Vector3 Transform::InverseTransformPoint(const Vector3& point) const {
return (rotation.Inverse() * (point - position)) / scale;
}
Vector3 Transform::InverseTransformDirection(const Vector3& direction) const {
return rotation.Inverse() * direction / scale;
}
} // namespace Math
} // namespace XCEngine