From 2af6117ef8c0a7b935d80b4c6d94891c6d6a6719 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Tue, 26 Apr 2016 17:26:02 -0700 Subject: [PATCH] More collision imps and stubs --- Runtime/Collision/CCollidableOBBTree.cpp | 32 ++++++++++ Runtime/Collision/CCollidableOBBTree.hpp | 20 ++++++- Runtime/Collision/CCollidableOBBTreeGroup.cpp | 48 ++++++++++++++- Runtime/Collision/CCollidableOBBTreeGroup.hpp | 23 +++++++- Runtime/Collision/CCollisionPrimitive.cpp | 29 +++++++++ Runtime/Collision/CCollisionPrimitive.hpp | 20 +++++++ .../Collision/CInternalRayCastStructure.cpp | 1 + .../Collision/CInternalRayCastStructure.hpp | 33 +++++++++++ Runtime/Collision/CMakeLists.txt | 2 + Runtime/Collision/COBBTree.cpp | 59 ++++++++++++++++++- Runtime/Collision/COBBTree.hpp | 31 +++++++--- Runtime/Collision/CRayCastResult.cpp | 8 +++ Runtime/Collision/CRayCastResult.hpp | 11 +++- Runtime/World/CPhysicsActor.hpp | 6 +- Runtime/World/CWorldLight.hpp | 6 +- 15 files changed, 306 insertions(+), 23 deletions(-) create mode 100644 Runtime/Collision/CInternalRayCastStructure.cpp create mode 100644 Runtime/Collision/CInternalRayCastStructure.hpp diff --git a/Runtime/Collision/CCollidableOBBTree.cpp b/Runtime/Collision/CCollidableOBBTree.cpp index e69de29bb..445b40785 100644 --- a/Runtime/Collision/CCollidableOBBTree.cpp +++ b/Runtime/Collision/CCollidableOBBTree.cpp @@ -0,0 +1,32 @@ +#include "CCollidableOBBTree.hpp" + +namespace urde +{ + +CCollidableOBBTree::CCollidableOBBTree(const COBBTree* tree, const urde::CMaterialList& material) + : CCollisionPrimitive(material), + x10_tree((COBBTree*)tree) +{ + +} + +FourCC CCollidableOBBTree::GetPrimType() const +{ + return SBIG('OBBT'); +} + +CRayCastResult CCollidableOBBTree::CastRayInternal(const CInternalRayCastStructure&) const +{ + +} + +zeus::CAABox CCollidableOBBTree::CalculateAABox(const zeus::CTransform&) const +{ + +} + +zeus::CAABox CCollidableOBBTree::CalculateLocalAABox() const +{ +} + +} diff --git a/Runtime/Collision/CCollidableOBBTree.hpp b/Runtime/Collision/CCollidableOBBTree.hpp index f7eb5c9d5..e3e3d5aac 100644 --- a/Runtime/Collision/CCollidableOBBTree.hpp +++ b/Runtime/Collision/CCollidableOBBTree.hpp @@ -1,11 +1,27 @@ #ifndef __URDE_CCOLLIDABLEOBBTREE_HPP__ #define __URDE_CCOLLIDABLEOBBTREE_HPP__ +#include "Collision/CCollisionPrimitive.hpp" +#include "COBBTree.hpp" + namespace urde { - -class CCollidableOBBTree +class CCollidableOBBTree : public CCollisionPrimitive { + COBBTree* x10_tree = nullptr; + u32 x14_ = 0; + u32 x18_ = 0; + u32 x1c_ = 0; +public: + CCollidableOBBTree(const COBBTree* tree, const CMaterialList& material); + virtual ~CCollidableOBBTree() {} + void ResetTestStats() const; + void ResetTestStatsRecurse(const COBBTree::CNode&) const; + u32 GetTableIndex() const { return -1; } + zeus::CAABox CalculateAABox(const zeus::CTransform &) const; + zeus::CAABox CalculateLocalAABox() const; + virtual FourCC GetPrimType() const; + virtual CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const; }; } diff --git a/Runtime/Collision/CCollidableOBBTreeGroup.cpp b/Runtime/Collision/CCollidableOBBTreeGroup.cpp index 8f2e76076..aea243748 100644 --- a/Runtime/Collision/CCollidableOBBTreeGroup.cpp +++ b/Runtime/Collision/CCollidableOBBTreeGroup.cpp @@ -1,9 +1,11 @@ #include "CCollidableOBBTreeGroup.hpp" -#include "COBBTree.hpp" +#include "CCollidableOBBTree.hpp" #include "CToken.hpp" namespace urde { +const CCollisionPrimitive::Type CCollidableOBBTreeGroup::sType(CCollidableOBBTreeGroup::SetStaticTableIndex, "CCollidableOBBTreeGroup"); +u32 CCollidableOBBTreeGroup::sTableIndex = -1; CCollidableOBBTreeGroup::CCollidableOBBTreeGroup(CInputStream& in) { @@ -11,7 +13,49 @@ CCollidableOBBTreeGroup::CCollidableOBBTreeGroup(CInputStream& in) x0_trees.reserve(treeCount); for (u32 i = 0 ; i < treeCount ; i++) - x0_trees.push_back(in); + { + std::unique_ptr tree(new COBBTree(in)); + x0_trees.push_back(std::move(tree)); + } + + x10_aabbs.reserve(x0_trees.size()); + + for (const std::unique_ptr& tree : x0_trees) + x10_aabbs.push_back(CCollidableOBBTree(tree.get(), CMaterialList()).CalculateLocalAABox()); +} + +u32 CCollidableOBBTreeGroup::GetTableIndex() const +{ + +} + +zeus::CAABox CCollidableOBBTreeGroup::CalculateAABox(const zeus::CTransform&) const +{ + +} + +zeus::CAABox CCollidableOBBTreeGroup::CalculateLocalAABox() const +{ + +} + +FourCC CCollidableOBBTreeGroup::GetPrimType() const +{ + return SBIG('OBTG'); +} + +CRayCastResult CCollidableOBBTreeGroup::CastRayInternal(const CInternalRayCastStructure&) const +{ +} + +const CCollisionPrimitive::Type& CCollidableOBBTreeGroup::GetType() +{ + return sType; +} + +void CCollidableOBBTreeGroup::SetStaticTableIndex(u32 index) +{ + sTableIndex = index; } CFactoryFnReturn FCollidableOBBTreeGroupFactory(const SObjectTag &tag, CInputStream &in, diff --git a/Runtime/Collision/CCollidableOBBTreeGroup.hpp b/Runtime/Collision/CCollidableOBBTreeGroup.hpp index c1c934e64..4f81b840d 100644 --- a/Runtime/Collision/CCollidableOBBTreeGroup.hpp +++ b/Runtime/Collision/CCollidableOBBTreeGroup.hpp @@ -3,14 +3,31 @@ #include "IOStreams.hpp" #include "CFactoryMgr.hpp" +#include "COBBTree.hpp" +#include "zeus/CAABox.hpp" +#include "CCollisionPrimitive.hpp" + namespace urde { -class COBBTree; -class CCollidableOBBTreeGroup +class CCollidableOBBTreeGroup : public CCollisionPrimitive { - std::vector x0_trees; + static const CCollisionPrimitive::Type sType; + static u32 sTableIndex; + std::vector> x0_trees; + std::vector x10_aabbs; public: CCollidableOBBTreeGroup(CInputStream& in); + virtual ~CCollidableOBBTreeGroup() {} + + void ResetTestStats() 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); }; CFactoryFnReturn FCollidableOBBTreeGroupFactory(const SObjectTag &tag, CInputStream &in, diff --git a/Runtime/Collision/CCollisionPrimitive.cpp b/Runtime/Collision/CCollisionPrimitive.cpp index e69de29bb..67aa27441 100644 --- a/Runtime/Collision/CCollisionPrimitive.cpp +++ b/Runtime/Collision/CCollisionPrimitive.cpp @@ -0,0 +1,29 @@ +#include "CCollisionPrimitive.hpp" +#include "CInternalRayCastStructure.hpp" +#include "CMaterialFilter.hpp" + +namespace urde +{ +CCollisionPrimitive::CCollisionPrimitive(const CMaterialList& list) + : x8_material(list) +{ +} + +void CCollisionPrimitive::SetMaterial(const CMaterialList& material) +{ + x8_material = material; +} + +const CMaterialList&CCollisionPrimitive::GetMaterial() const +{ + return x8_material; + +} + +CRayCastResult CCollisionPrimitive::CastRay(const zeus::CVector3f& start, const zeus::CVector3f& end, float d, const + CMaterialFilter& filter, const zeus::CTransform& xf) const +{ + return CastRayInternal(CInternalRayCastStructure(start, end, d, xf, filter)); +} + +} diff --git a/Runtime/Collision/CCollisionPrimitive.hpp b/Runtime/Collision/CCollisionPrimitive.hpp index 4457567ec..e67c09bca 100644 --- a/Runtime/Collision/CCollisionPrimitive.hpp +++ b/Runtime/Collision/CCollisionPrimitive.hpp @@ -2,11 +2,17 @@ #define __URDE_CCOLLISIONPRIMITIVE_HPP__ #include "Collision/CMaterialList.hpp" +#include "CRayCastResult.hpp" +#include "zeus/CAABox.hpp" + #include namespace urde { +class COBBTree; +class CInternalRayCastStructure; +class CMaterialFilter; class CCollisionPrimitive { CMaterialList x8_material; @@ -34,6 +40,20 @@ public: } }; + CCollisionPrimitive()=default; + CCollisionPrimitive(const CMaterialList& list); + virtual u32 GetTableIndex() const=0; + virtual void SetMaterial(const CMaterialList&); + virtual const CMaterialList& GetMaterial() const; + virtual zeus::CAABox CalculateAABox(const zeus::CTransform&) const=0; + virtual zeus::CAABox CalculateLocalAABox() const=0; + virtual FourCC GetPrimType() const=0; + virtual ~CCollisionPrimitive() {} + virtual CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const=0; + CRayCastResult CastRay(const zeus::CVector3f&, const zeus::CVector3f&, float, const CMaterialFilter&, + const zeus::CTransform&) const; + + static void InitBeginTypes(); static void InitAddType(const Type& tp); static void InitEndTypes(); diff --git a/Runtime/Collision/CInternalRayCastStructure.cpp b/Runtime/Collision/CInternalRayCastStructure.cpp new file mode 100644 index 000000000..ffac94d86 --- /dev/null +++ b/Runtime/Collision/CInternalRayCastStructure.cpp @@ -0,0 +1 @@ +#include "CInternalRayCastStructure.hpp" diff --git a/Runtime/Collision/CInternalRayCastStructure.hpp b/Runtime/Collision/CInternalRayCastStructure.hpp new file mode 100644 index 000000000..ce8f50ce8 --- /dev/null +++ b/Runtime/Collision/CInternalRayCastStructure.hpp @@ -0,0 +1,33 @@ +#ifndef __URDE_CINTERNALRAYCASTSTRUCTURE_HPP__ +#define __URDE_CINTERNALRAYCASTSTRUCTURE_HPP__ + +#include "zeus/CTransform.hpp" +#include "zeus/CMRay.hpp" +#include "CMaterialFilter.hpp" +namespace urde +{ +class CInternalRayCastStructure +{ + zeus::CMRay x0_ray; + float x38_maxTime; + zeus::CTransform x3c_xf; + CMaterialFilter x6c_filter; +public: + CInternalRayCastStructure(const zeus::CVector3f& start, const zeus::CVector3f& end, float d, const zeus::CTransform& xf, + const CMaterialFilter& filter) + : x0_ray(start, end, d), + x3c_xf(xf), + x6c_filter(filter) + { + } + + 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; } + const zeus::CTransform& GetTransform() const { return x3c_xf; } + const CMaterialFilter& GetFilter() const { return x6c_filter; } +}; +} + +#endif // __URDE_CINTERNALRAYCASTSTRUCTURE_HPP__ diff --git a/Runtime/Collision/CMakeLists.txt b/Runtime/Collision/CMakeLists.txt index f241968bd..f6e667126 100644 --- a/Runtime/Collision/CMakeLists.txt +++ b/Runtime/Collision/CMakeLists.txt @@ -5,8 +5,10 @@ set(COLLISION_SOURCES COBBTree.hpp COBBTree.cpp CCollidableOBBTree.hpp CCollidableOBBTree.cpp CCollidableOBBTreeGroup.hpp CCollidableOBBTreeGroup.cpp + CCollisionPrimitive.hpp CCollisionPrimitive.cpp CMaterialList.hpp CMaterialFilter.hpp CMaterialFilter.cpp + CInternalRayCastStructure.hpp CInternalRayCastStructure.cpp CRayCastResult.hpp CRayCastResult.cpp) runtime_add_list(Collision COLLISION_SOURCES) diff --git a/Runtime/Collision/COBBTree.cpp b/Runtime/Collision/COBBTree.cpp index f135780a2..f0f34bc5d 100644 --- a/Runtime/Collision/COBBTree.cpp +++ b/Runtime/Collision/COBBTree.cpp @@ -23,7 +23,8 @@ COBBTree::COBBTree(CInputStream& in) : x0_magic(verify_deaf_babe(in)), x4_version(verify_version(in)), x8_memsize(in.readUint32()), - x18_indexData(in) + x18_indexData(in), + x88_root(new CNode(in)) { } @@ -57,9 +58,65 @@ COBBTree::SIndexData::SIndexData(CInputStream& in) x60_.push_back(zeus::CVector3f::ReadBig(in)); } +COBBTree::CNode::CNode(const zeus::CTransform& xf, const zeus::CVector3f& point, + const COBBTree::CNode* left, const COBBTree::CNode* right, + const COBBTree::CLeafData* leaf) + : x0_obb(xf, point), + x3c_isLeaf(leaf != nullptr) +{ + x40_left.reset((CNode*)left); + x44_right.reset((CNode*)right); + x48_leaf.reset((CLeafData*)leaf); +} + COBBTree::CNode::CNode(CInputStream& in) { x0_obb = zeus::COBBox::ReadBig(in); + x3c_isLeaf = in.readBool(); + if (x3c_isLeaf) + x48_leaf.reset(new CLeafData(in)); + else + { + x40_left.reset(new CNode(in)); + x44_right.reset(new CNode(in)); + } +} + +COBBTree::CNode* COBBTree::CNode::GetLeft() const +{ + return x40_left.get(); +} + +COBBTree::CNode*COBBTree::CNode::GetRight() const +{ + return x44_right.get(); +} + +COBBTree::CLeafData*COBBTree::CNode::GetLeafData() const +{ + return x48_leaf.get(); +} + +const zeus::COBBox& COBBTree::CNode::GetOBB() const +{ + return x0_obb; +} + +COBBTree::CLeafData::CLeafData(const std::vector& surface) + : x0_surface(surface) +{ +} + +const std::vector& COBBTree::CLeafData::GetSurfaceVector() const +{ + return x0_surface; +} + +COBBTree::CLeafData::CLeafData(CInputStream& in) +{ + u32 edgeCount = in.readUint32Big(); + for (u32 i = 0 ; i < edgeCount ; i++) + x0_surface.push_back(in.readUint16Big()); } } diff --git a/Runtime/Collision/COBBTree.hpp b/Runtime/Collision/COBBTree.hpp index a43d3c336..285a9bacf 100644 --- a/Runtime/Collision/COBBTree.hpp +++ b/Runtime/Collision/COBBTree.hpp @@ -23,20 +23,36 @@ public: SIndexData(CInputStream&); }; - class CNodeLeafData + class CLeafData { + std::vector x0_surface; + public: + CLeafData()=default; + CLeafData(const std::vector&); + CLeafData(CInputStream&); + + const std::vector& GetSurfaceVector() const; }; class CNode { zeus::COBBox x0_obb; - bool x3c_ = false; - std::unique_ptr x40_; - std::unique_ptr x44_; - std::unique_ptr x48_; + bool x3c_isLeaf = false; + std::unique_ptr x40_left; + std::unique_ptr x44_right; + std::unique_ptr x48_leaf; public: CNode() = default; + CNode(const CNode&)=default; + CNode(const zeus::CTransform&, const zeus::CVector3f&, const CNode*, const CNode*, const CLeafData*); CNode(CInputStream&); + + bool WasHit() const; + void SetWasHit(bool) const; + CNode* GetLeft() const; + CNode* GetRight() const; + CLeafData* GetLeafData() const; + const zeus::COBBox& GetOBB() const; }; private: @@ -46,10 +62,9 @@ private: u32 x8_memsize = 0; /* CSimpleAllocator xc_ We're not using this but lets keep track*/ SIndexData x18_indexData; - std::unique_ptr x88_root; + std::unique_ptr x88_root; public: - - + COBBTree()=default; COBBTree(const COBBTree::SIndexData&, const CNode*); COBBTree(CInputStream&); }; diff --git a/Runtime/Collision/CRayCastResult.cpp b/Runtime/Collision/CRayCastResult.cpp index 9f1387afe..4825a19e1 100644 --- a/Runtime/Collision/CRayCastResult.cpp +++ b/Runtime/Collision/CRayCastResult.cpp @@ -1,2 +1,10 @@ #include "CRayCastResult.hpp" + +namespace urde +{ +const CMaterialList& CRayCastResult::GetMaterial() const +{ + return x28_material; +} +} diff --git a/Runtime/Collision/CRayCastResult.hpp b/Runtime/Collision/CRayCastResult.hpp index d816ee7cd..f9f39ae8a 100644 --- a/Runtime/Collision/CRayCastResult.hpp +++ b/Runtime/Collision/CRayCastResult.hpp @@ -21,9 +21,18 @@ private: CMaterialList x28_material; public: CRayCastResult(); - CRayCastResult(float, const zeus::CVector3f&, const zeus::CPlane, const CMaterialList& matList) + CRayCastResult(const CRayCastResult& other, EInvalid) {} + CRayCastResult(float, const zeus::CVector3f&, const zeus::CPlane& plane, const CMaterialList& matList) : x28_material(matList) {} + + void MakeInvalid(); + bool IsInvalid() const; + float GetTime() const; + const zeus::CVector3f& GetPoint() const; + const zeus::CPlane& GetPlane() const; + const CMaterialList& GetMaterial() const; + void Transform(const zeus::CTransform&); }; } diff --git a/Runtime/World/CPhysicsActor.hpp b/Runtime/World/CPhysicsActor.hpp index def94dd27..8e6b1e54c 100644 --- a/Runtime/World/CPhysicsActor.hpp +++ b/Runtime/World/CPhysicsActor.hpp @@ -28,7 +28,7 @@ protected: float xf0_inertialTensor; float xf4_inertialTensorRecip; zeus::CAABox x1a4_baseBoundingBox; - CCollisionPrimitive x1c0_collisionPrimitive; + std::unique_ptr x1c0_collisionPrimitive; zeus::CVector3f x1e8_primitiveOffset; float x23c_stepUpHeight; float x240_stepDownHeight; @@ -114,8 +114,8 @@ public: return zeus::CTransform(); } - const CCollisionPrimitive& GetCollisionPrimitive() const - { return x1c0_collisionPrimitive; } + const CCollisionPrimitive* GetCollisionPrimitive() const + { return x1c0_collisionPrimitive.get(); } void SetInertiaTensorScalar(float tensor) { diff --git a/Runtime/World/CWorldLight.hpp b/Runtime/World/CWorldLight.hpp index e4034ecec..f01a4cc9d 100644 --- a/Runtime/World/CWorldLight.hpp +++ b/Runtime/World/CWorldLight.hpp @@ -1,5 +1,5 @@ -#ifndef CWORLDLIGHT_HPP -#define CWORLDLIGHT_HPP +#ifndef __URDE_CWORLDLIGHT_HPP__ +#define __URDE_CWORLDLIGHT_HPP__ #include "Graphics/CLight.hpp" @@ -31,4 +31,4 @@ public: } -#endif // CWORLDLIGHT_HPP +#endif // __URDE_CWORLDLIGHT_HPP__