From c66dac6df27cbbdc23aa9d36c45589f2a2feed4b Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Fri, 24 Jun 2016 13:09:38 -0700 Subject: [PATCH] Initial Collision stubs --- Runtime/Collision/CCollidableAABox.cpp | 47 ++++++++++++++++++- Runtime/Collision/CCollidableAABox.hpp | 28 +++++++++-- .../Collision/CCollidableCollisionSurface.cpp | 14 ++++++ .../Collision/CCollidableCollisionSurface.hpp | 17 +++++++ Runtime/Collision/CCollidableOBBTreeGroup.hpp | 4 +- Runtime/Collision/CCollidableSphere.cpp | 33 +++++++++++++ Runtime/Collision/CCollidableSphere.hpp | 25 ++++++++++ Runtime/Collision/CCollisionPrimitive.cpp | 34 +++++++++++++- Runtime/Collision/CCollisionPrimitive.hpp | 17 ++----- Runtime/Collision/CCollisionSurface.cpp | 12 +++++ Runtime/Collision/CCollisionSurface.hpp | 22 +++++++++ Runtime/Collision/CGameCollision.cpp | 12 +++++ .../Collision/CInternalRayCastStructure.hpp | 2 +- Runtime/Collision/CMakeLists.txt | 5 ++ Runtime/Collision/COBBTree.cpp | 31 +++++++++++- Runtime/Collision/COBBTree.hpp | 4 +- Runtime/Collision/InternalColliders.cpp | 17 +++++++ Runtime/Collision/InternalColliders.hpp | 11 +++++ 18 files changed, 310 insertions(+), 25 deletions(-) create mode 100644 Runtime/Collision/CCollidableCollisionSurface.cpp create mode 100644 Runtime/Collision/CCollidableCollisionSurface.hpp create mode 100644 Runtime/Collision/CCollidableSphere.cpp create mode 100644 Runtime/Collision/CCollidableSphere.hpp create mode 100644 Runtime/Collision/CCollisionSurface.cpp create mode 100644 Runtime/Collision/CCollisionSurface.hpp create mode 100644 Runtime/Collision/InternalColliders.cpp create mode 100644 Runtime/Collision/InternalColliders.hpp diff --git a/Runtime/Collision/CCollidableAABox.cpp b/Runtime/Collision/CCollidableAABox.cpp index ee048d470..6b75d91ae 100644 --- a/Runtime/Collision/CCollidableAABox.cpp +++ b/Runtime/Collision/CCollidableAABox.cpp @@ -1,6 +1,51 @@ #include "CCollidableAABox.hpp" +namespace urde +{ +const CCollisionPrimitive::Type CCollidableAABox::sType(CCollidableAABox::SetStaticTableIndex, "CCollidableAABox"); +u32 CCollidableAABox::sTableIndex = -1; + CCollidableAABox::CCollidableAABox() { - +} + +zeus::CAABox CCollidableAABox::Transform(const zeus::CTransform& xf) const +{ + return {xf.origin + x10_aabox.min, xf.origin + x10_aabox.max}; +} + +u32 CCollidableAABox::GetTableIndex() const +{ + return sTableIndex; +} + +zeus::CAABox CCollidableAABox::CalculateAABox(const zeus::CTransform& xf) const +{ + return Transform(xf); +} + +zeus::CAABox CCollidableAABox::CalculateLocalAABox() const +{ + return x10_aabox; +} + +FourCC CCollidableAABox::GetPrimType() const +{ + return SBIG('AABX'); +} + +CRayCastResult CCollidableAABox::CastRayInternal(const CInternalRayCastStructure &) const +{ + return {}; +} + +const CCollisionPrimitive::Type& CCollidableAABox::GetType() +{ + return sType; +} + +void CCollidableAABox::SetStaticTableIndex(u32 index) +{ + sTableIndex = index; +} } diff --git a/Runtime/Collision/CCollidableAABox.hpp b/Runtime/Collision/CCollidableAABox.hpp index b94c3d0c9..a4212131c 100644 --- a/Runtime/Collision/CCollidableAABox.hpp +++ b/Runtime/Collision/CCollidableAABox.hpp @@ -1,11 +1,29 @@ -#ifndef CCOLLIDABLEAABOX_HPP -#define CCOLLIDABLEAABOX_HPP +#ifndef __URDE_CCOLLIDABLEAABOX_HPP__ +#define __URDE_CCOLLIDABLEAABOX_HPP__ +#include "CCollisionPrimitive.hpp" -class CCollidableAABox +namespace urde { +class CCollidableAABox : public CCollisionPrimitive +{ + static const Type sType; + static u32 sTableIndex; + + zeus::CAABox x10_aabox; public: CCollidableAABox(); -}; -#endif // CCOLLIDABLEAABOX_HPP \ No newline at end of file + zeus::CAABox Transform(const zeus::CTransform&) const; + virtual u32 GetTableIndex() const; + virtual zeus::CAABox CalculateAABox(const zeus::CTransform&) const; + virtual zeus::CAABox CalculateLocalAABox() const; + virtual FourCC GetPrimType() const; + virtual CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const; + + static const CCollisionPrimitive::Type& GetType(); + static void SetStaticTableIndex(u32 index); +}; +} + +#endif // __URDE_CCOLLIDABLEAABOX_HPP__ diff --git a/Runtime/Collision/CCollidableCollisionSurface.cpp b/Runtime/Collision/CCollidableCollisionSurface.cpp new file mode 100644 index 000000000..8b7190055 --- /dev/null +++ b/Runtime/Collision/CCollidableCollisionSurface.cpp @@ -0,0 +1,14 @@ +#include "CCollidableCollisionSurface.hpp" + +namespace urde +{ +const CCollisionPrimitive::Type& CCollidableCollisionSurface::GetType() +{ + return sType; +} + +void CCollidableCollisionSurface::SetStaticTableIndex(u32 index) +{ + sTableIndex = index; +} +} diff --git a/Runtime/Collision/CCollidableCollisionSurface.hpp b/Runtime/Collision/CCollidableCollisionSurface.hpp new file mode 100644 index 000000000..cf9a429d6 --- /dev/null +++ b/Runtime/Collision/CCollidableCollisionSurface.hpp @@ -0,0 +1,17 @@ +#ifndef __URDE_COLLIDABLECOLLISIONSURFACE_HPP__ +#define __URDE_COLLIDABLECOLLISIONSURFACE_HPP__ + +#include "CCollisionPrimitive.hpp" + +namespace urde +{ +class CCollidableCollisionSurface +{ + static const CCollisionPrimitive::Type sType; + static u32 sTableIndex; +public: + static const CCollisionPrimitive::Type& GetType(); + static void SetStaticTableIndex(u32 index); +}; +} +#endif // __URDE_COLLIDABLECOLLISIONSURFACE_HPP__ diff --git a/Runtime/Collision/CCollidableOBBTreeGroup.hpp b/Runtime/Collision/CCollidableOBBTreeGroup.hpp index 4f81b840d..d2c2956e4 100644 --- a/Runtime/Collision/CCollidableOBBTreeGroup.hpp +++ b/Runtime/Collision/CCollidableOBBTreeGroup.hpp @@ -11,7 +11,7 @@ namespace urde { class CCollidableOBBTreeGroup : public CCollisionPrimitive { - static const CCollisionPrimitive::Type sType; + static const Type sType; static u32 sTableIndex; std::vector> x0_trees; std::vector x10_aabbs; @@ -26,7 +26,7 @@ public: virtual FourCC GetPrimType() const; virtual CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const; - static const CCollisionPrimitive::Type& GetType(); + static const Type& GetType(); static void SetStaticTableIndex(u32 index); }; diff --git a/Runtime/Collision/CCollidableSphere.cpp b/Runtime/Collision/CCollidableSphere.cpp new file mode 100644 index 000000000..7e9afed7c --- /dev/null +++ b/Runtime/Collision/CCollidableSphere.cpp @@ -0,0 +1,33 @@ +#include "CCollidableSphere.hpp" + +namespace urde +{ +const CCollisionPrimitive::Type CCollidableSphere::sType(CCollidableSphere::SetStaticTableIndex, "CCollidableSphere"); +u32 CCollidableSphere::sTableIndex = -1; + +u32 CCollidableSphere::GetTableIndex() const +{ + return sTableIndex; +} + +zeus::CAABox CCollidableSphere::CalculateAABox(const zeus::CTransform &) const +{ + return {}; +} + +zeus::CAABox CCollidableSphere::CalculateLocalAABox() const +{ + return {}; +} + +FourCC CCollidableSphere::GetPrimType() const +{ + return SBIG('SPHR'); +} + +CRayCastResult CCollidableSphere::CastRayInternal(const CInternalRayCastStructure &) const +{ + return {}; +} + +} diff --git a/Runtime/Collision/CCollidableSphere.hpp b/Runtime/Collision/CCollidableSphere.hpp new file mode 100644 index 000000000..705388b87 --- /dev/null +++ b/Runtime/Collision/CCollidableSphere.hpp @@ -0,0 +1,25 @@ +#ifndef __URDE_CCOLLIDALBESPHERE_HPP +#define __URDE_CCOLLIDALBESPHERE_HPP + +#include "CCollisionPrimitive.hpp" + +namespace urde +{ +class CCollidableSphere : public CCollisionPrimitive +{ + static const Type sType; + static u32 sTableIndex; +public: + + virtual u32 GetTableIndex() const; + virtual zeus::CAABox CalculateAABox(const zeus::CTransform&) const; + virtual zeus::CAABox CalculateLocalAABox() const; + virtual FourCC GetPrimType() const; + virtual CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const; + + static const CCollisionPrimitive::Type& GetType(); + static void SetStaticTableIndex(u32 index); +}; +} + +#endif // __URDE_CCOLLIDALBESPHERE_HPP diff --git a/Runtime/Collision/CCollisionPrimitive.cpp b/Runtime/Collision/CCollisionPrimitive.cpp index 67aa27441..87760ad5c 100644 --- a/Runtime/Collision/CCollisionPrimitive.cpp +++ b/Runtime/Collision/CCollisionPrimitive.cpp @@ -1,6 +1,7 @@ #include "CCollisionPrimitive.hpp" #include "CInternalRayCastStructure.hpp" #include "CMaterialFilter.hpp" +#include "InternalColliders.hpp" namespace urde { @@ -14,7 +15,7 @@ void CCollisionPrimitive::SetMaterial(const CMaterialList& material) x8_material = material; } -const CMaterialList&CCollisionPrimitive::GetMaterial() const +const CMaterialList& CCollisionPrimitive::GetMaterial() const { return x8_material; @@ -26,4 +27,35 @@ CRayCastResult CCollisionPrimitive::CastRay(const zeus::CVector3f& start, const return CastRayInternal(CInternalRayCastStructure(start, end, d, xf, filter)); } +void CCollisionPrimitive::InitBeginTypes() +{ + +} + +void CCollisionPrimitive::InitAddType(const CCollisionPrimitive::Type& tp) +{ + +} + +void CCollisionPrimitive::InitEndTypes() +{ + +} + +CCollisionPrimitive::Type::Type(std::function setter, const char *info) + : x0_setter(setter), + x4_info(info) +{ +} + +const char *CCollisionPrimitive::Type::GetInfo() const +{ + return x4_info; +} + +std::function CCollisionPrimitive::Type::GetSetter() const +{ + return x0_setter; +} + } diff --git a/Runtime/Collision/CCollisionPrimitive.hpp b/Runtime/Collision/CCollisionPrimitive.hpp index e67c09bca..34604c18d 100644 --- a/Runtime/Collision/CCollisionPrimitive.hpp +++ b/Runtime/Collision/CCollisionPrimitive.hpp @@ -23,21 +23,11 @@ public: const char* x4_info; public: Type() = default; - Type(std::function setter, const char * info) - : x0_setter(setter), - x4_info(info) - { - } + Type(std::function setter, const char * info); - const char* GetInfo() const - { - return x4_info; - } + const char* GetInfo() const; - std::function GetSetter() const - { - return x0_setter; - } + std::function GetSetter() const; }; CCollisionPrimitive()=default; @@ -60,6 +50,7 @@ public: static void InitBeginColliders(); static void InitAddCollider(const Type& tp); + static void InitEndColliders(); }; } diff --git a/Runtime/Collision/CCollisionSurface.cpp b/Runtime/Collision/CCollisionSurface.cpp new file mode 100644 index 000000000..b9c38f8dc --- /dev/null +++ b/Runtime/Collision/CCollisionSurface.cpp @@ -0,0 +1,12 @@ +#include "CCollisionSurface.hpp" + +namespace urde +{ +CCollisionSurface::CCollisionSurface(const zeus::CVector3f& a, const zeus::CVector3f& b, const zeus::CVector3f& c, u32 flags) + : x0_a(a), + xc_b(b), + x18_c(c), + x24_flags(flags) +{ +} +} diff --git a/Runtime/Collision/CCollisionSurface.hpp b/Runtime/Collision/CCollisionSurface.hpp new file mode 100644 index 000000000..0f38b5b6b --- /dev/null +++ b/Runtime/Collision/CCollisionSurface.hpp @@ -0,0 +1,22 @@ +#ifndef __URDE_CCOLLISIONSURFACE_HPP__ +#define __URDE_CCOLLISIONSURFACE_HPP__ + +#include "zeus/zeus.hpp" +#include "RetroTypes.hpp" + +namespace urde +{ +class CCollisionSurface +{ + zeus::CVector3f x0_a; + zeus::CVector3f xc_b; + zeus::CVector3f x18_c; + u32 x24_flags; +public: + CCollisionSurface(const zeus::CVector3f&, const zeus::CVector3f&, const zeus::CVector3f&, u32); + + zeus::CVector3f GetPoint(u32) const; +}; +} + +#endif // __URDE_CCOLLISIONSURFACE_HPP__ diff --git a/Runtime/Collision/CGameCollision.cpp b/Runtime/Collision/CGameCollision.cpp index 4abd80232..7b5ff301a 100644 --- a/Runtime/Collision/CGameCollision.cpp +++ b/Runtime/Collision/CGameCollision.cpp @@ -1 +1,13 @@ #include "CMaterialFilter.hpp" +#include "CGameCollision.hpp" +#include "CCollidableOBBTreeGroup.hpp" + +namespace urde +{ + +void CGameCollision::InitCollision() +{ + CCollisionPrimitive::InitBeginTypes(); +} + +} diff --git a/Runtime/Collision/CInternalRayCastStructure.hpp b/Runtime/Collision/CInternalRayCastStructure.hpp index ce8f50ce8..69ab7575d 100644 --- a/Runtime/Collision/CInternalRayCastStructure.hpp +++ b/Runtime/Collision/CInternalRayCastStructure.hpp @@ -24,7 +24,7 @@ public: const zeus::CMRay& GetRay() const { return x0_ray; } const zeus::CVector3f& GetStart() const { return x0_ray.start; } const zeus::CVector3f& GetNormal() const { return x0_ray.normal; } - float GetMaxTime() const { return 0.f; } + float GetMaxTime() const { return x38_maxTime; } const zeus::CTransform& GetTransform() const { return x3c_xf; } const CMaterialFilter& GetFilter() const { return x6c_filter; } }; diff --git a/Runtime/Collision/CMakeLists.txt b/Runtime/Collision/CMakeLists.txt index f6e667126..1302add80 100644 --- a/Runtime/Collision/CMakeLists.txt +++ b/Runtime/Collision/CMakeLists.txt @@ -2,7 +2,12 @@ set(COLLISION_SOURCES CGameCollision.hpp CGameCollision.cpp CCollisionInfo.hpp CCollisionInfo.cpp CCollisionEdge.hpp CCollisionEdge.cpp + CCollisionSurface.hpp CCollisionSurface.cpp + InternalColliders.hpp InternalColliders.cpp COBBTree.hpp COBBTree.cpp + CCollidableAABox.hpp CCollidableAABox.cpp + CCollidableCollisionSurface.hpp CCollidableCollisionSurface.cpp + CCollidableSphere.hpp CCollidableSphere.cpp CCollidableOBBTree.hpp CCollidableOBBTree.cpp CCollidableOBBTreeGroup.hpp CCollidableOBBTreeGroup.cpp CCollisionPrimitive.hpp CCollisionPrimitive.cpp diff --git a/Runtime/Collision/COBBTree.cpp b/Runtime/Collision/COBBTree.cpp index d80a137f8..f990ee8e7 100644 --- a/Runtime/Collision/COBBTree.cpp +++ b/Runtime/Collision/COBBTree.cpp @@ -15,7 +15,9 @@ u32 verify_version(CInputStream& in) return in.readUint32Big(); } -COBBTree::COBBTree(const COBBTree::SIndexData&, const COBBTree::CNode*) +COBBTree::COBBTree(const SIndexData& indexData, const CNode* root) + : x18_indexData(indexData), + x88_root((CNode*)root) { } @@ -114,6 +116,25 @@ const zeus::COBBox& COBBTree::CNode::GetOBB() const return x0_obb; } +size_t COBBTree::CNode::GetMemoryUsage() const +{ + size_t ret = 0; + if (x3c_isLeaf) + ret = x48_leaf->GetMemoryUsage() + 80; + else + { + if (x40_left) + ret = x40_left->GetMemoryUsage() + 80; + if (x44_right) + ret += x44_right->GetMemoryUsage(); + } + + if (!(ret & 3)) + return ret; + + return ret + ((ret & 3) - 4); +} + COBBTree::CLeafData::CLeafData(const std::vector& surface) : x0_surface(surface) { @@ -124,6 +145,14 @@ const std::vector& COBBTree::CLeafData::GetSurfaceVector() const return x0_surface; } +size_t COBBTree::CLeafData::GetMemoryUsage() const +{ + size_t ret = (x0_surface.size() * 2) + 16; + if (!(ret & 3)) + return ret; + return ret + ((ret & 3) - 4); +} + COBBTree::CLeafData::CLeafData(CInputStream& in) { u32 edgeCount = in.readUint32Big(); diff --git a/Runtime/Collision/COBBTree.hpp b/Runtime/Collision/COBBTree.hpp index 38e89d42b..2a8fbe2d1 100644 --- a/Runtime/Collision/COBBTree.hpp +++ b/Runtime/Collision/COBBTree.hpp @@ -32,6 +32,7 @@ public: CLeafData(CInputStream&); const std::vector& GetSurfaceVector() const; + size_t GetMemoryUsage() const; }; class CNode @@ -48,11 +49,12 @@ public: CNode(CInputStream&); bool WasHit() const; - void SetWasHit(bool) const; + void SetHit(bool) const; CNode* GetLeft() const; CNode* GetRight() const; CLeafData* GetLeafData() const; const zeus::COBBox& GetOBB() const; + size_t GetMemoryUsage() const; }; private: diff --git a/Runtime/Collision/InternalColliders.cpp b/Runtime/Collision/InternalColliders.cpp new file mode 100644 index 000000000..55719a145 --- /dev/null +++ b/Runtime/Collision/InternalColliders.cpp @@ -0,0 +1,17 @@ +#include "InternalColliders.hpp" +#include "CCollidableAABox.hpp" +#include "CCollidableCollisionSurface.hpp" +#include "CCollidableSphere.hpp" + +namespace urde +{ +namespace InternalColliders +{ +void AddTypes() +{ + CCollisionPrimitive::InitAddType(CCollidableAABox::GetType()); + CCollisionPrimitive::InitAddType(CCollidableCollisionSurface::GetType()); + CCollisionPrimitive::InitAddType(CCollidableSphere::GetType()); +} +} +} diff --git a/Runtime/Collision/InternalColliders.hpp b/Runtime/Collision/InternalColliders.hpp new file mode 100644 index 000000000..664ab17f0 --- /dev/null +++ b/Runtime/Collision/InternalColliders.hpp @@ -0,0 +1,11 @@ +#ifndef __URDE_INTERNALCOLLIDERS_HPP__ +#define __URDE_INTERNALCOLLIDERS_HPP__ + +namespace urde +{ +namespace InternalColliders +{ + void AddTypes(); +} +} +#endif // __URDE_INTERNALCOLLIDERS_HPP__