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:
44
engine/src/Math/Transform.cpp
Normal file
44
engine/src/Math/Transform.cpp
Normal 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
|
||||
Reference in New Issue
Block a user