From 736cec9baa6af8bc275f9b4bb825153a11dececd Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sun, 9 Oct 2022 16:05:06 -0700 Subject: [PATCH] Match and link CCollisionSurface --- include/Kyoto/Math/CPlane.hpp | 2 +- include/WorldFormat/CCollisionSurface.hpp | 13 +++++++++---- src/WorldFormat/CCollisionSurface.cpp | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 src/WorldFormat/CCollisionSurface.cpp diff --git a/include/Kyoto/Math/CPlane.hpp b/include/Kyoto/Math/CPlane.hpp index 58f6f657..2eb7775f 100644 --- a/include/Kyoto/Math/CPlane.hpp +++ b/include/Kyoto/Math/CPlane.hpp @@ -9,7 +9,7 @@ class CPlane { public: CPlane(const CVector3f&, const CUnitVector3f&); // TODO weak - CPlane(float, const CUnitVector3f&); // TODO weak + CPlane(float constant, const CUnitVector3f& normal) : x0_normal(normal), xc_constant(constant) {} CPlane(const CVector3f&, const CVector3f&, const CVector3f&); // TODO diff --git a/include/WorldFormat/CCollisionSurface.hpp b/include/WorldFormat/CCollisionSurface.hpp index 97a62fc1..42b8290e 100644 --- a/include/WorldFormat/CCollisionSurface.hpp +++ b/include/WorldFormat/CCollisionSurface.hpp @@ -4,17 +4,22 @@ #include "types.h" #include "Kyoto/Math/CVector3f.hpp" +#include "Kyoto/Math/CPlane.hpp" class CCollisionSurface { public: - typedef CVector3f TVerts[3]; - // TODO + CCollisionSurface(const CVector3f&, const CVector3f&, const CVector3f&, uint flags); + + CUnitVector3f GetNormal() const; + CPlane GetPlane() const; private: - TVerts x0_data; + CVector3f x0_a; + CVector3f xc_b; + CVector3f x18_c; uint x24_flags; }; -CHECK_SIZEOF(CCollisionSurface, 0x28) +//CHECK_SIZEOF(CCollisionSurface, 0x28) #endif // _CCOLLISIONSURFACE diff --git a/src/WorldFormat/CCollisionSurface.cpp b/src/WorldFormat/CCollisionSurface.cpp new file mode 100644 index 00000000..9eba175a --- /dev/null +++ b/src/WorldFormat/CCollisionSurface.cpp @@ -0,0 +1,16 @@ +#include "WorldFormat/CCollisionSurface.hpp" + +CCollisionSurface::CCollisionSurface(const CVector3f& a, const CVector3f& b, const CVector3f& c, + uint flags) +: x0_a(a), xc_b(b), x18_c(c), x24_flags(flags) {} + +CUnitVector3f CCollisionSurface::GetNormal() const { + CVector3f baDiff = xc_b - x0_a; + CVector3f caDiff = x18_c - x0_a; + CVector3f tmp = CVector3f::Cross(baDiff, caDiff); + return tmp; +} +CPlane CCollisionSurface::GetPlane() const { + const CUnitVector3f norm = GetNormal(); + return CPlane(CVector3f::Dot(norm, x0_a), norm); +}