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); +}