#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