diff --git a/config/GM8E01_00/symbols.txt b/config/GM8E01_00/symbols.txt index 5691fc48..d82e525e 100644 --- a/config/GM8E01_00/symbols.txt +++ b/config/GM8E01_00/symbols.txt @@ -7660,7 +7660,7 @@ __ct__22CCameraShakerComponentFiRC17SCameraShakePointRC17SCameraShakePoint = .te GetSomething__17SCameraShakePointFv = .text:0x8015D2CC; // type:function size:0x1C scope:global fn_8015D2E8 = .text:0x8015D2E8; // type:function size:0xDC __ct__17SCameraShakePointFv = .text:0x8015D3C4; // type:function size:0x34 scope:global -LoadCameraShakePoint__R12CInputStream = .text:0x8015D3F8; // type:function size:0xAC scope:global +LoadCameraShakePoint__FR12CInputStream = .text:0x8015D3F8; // type:function size:0xAC scope:global __ct__17SCameraShakePointFiffff = .text:0x8015D4A4; // type:function size:0x20 scope:global BuildMissileShakeData__16CCameraShakeDataFfffRC9CVector3f = .text:0x8015D4C4; // type:function size:0x100 scope:global BuildPatternedExplodeShakeData__16CCameraShakeDataFRC9CVector3ffff = .text:0x8015D5C4; // type:function size:0x100 scope:global @@ -18742,7 +18742,7 @@ __vt__17CPoisonProjectile = .data:0x803EC390; // type:object size:0x74 scope:glo jumptable_803EC408 = .data:0x803EC408; // type:object size:0x20 scope:local lbl_803EC428 = .data:0x803EC428; // type:object size:0x10 lbl_803EC438 = .data:0x803EC438; // type:object size:0x10 -lbl_803EC448 = .data:0x803EC448; // type:object size:0x28 +__vt__18CCollidableOBBTree = .data:0x803EC448; // type:object size:0x28 __vt__23CCollidableOBBTreeGroup = .data:0x803EC470; // type:object size:0x28 scope:global __vt__60TObjOwnerDerivedFromIObj<32CCollidableOBBTreeGroupContainer> = .data:0x803EC498; // type:object size:0x10 jumptable_803EC4A8 = .data:0x803EC4A8; // type:object size:0x20 scope:local @@ -21277,7 +21277,7 @@ lbl_805A8620 = .sdata:0x805A8620; // type:object size:0x4 data:4byte lbl_805A8624 = .sdata:0x805A8624; // type:object size:0x4 data:4byte lbl_805A8628 = .sdata:0x805A8628; // type:object size:0x4 data:4byte lbl_805A862C = .sdata:0x805A862C; // type:object size:0x1 data:byte -lbl_805A8630 = .sdata:0x805A8630; // type:object size:0x8 data:4byte +sTableIndex__18CCollidableOBBTree = .sdata:0x805A8630; // type:object size:0x8 data:4byte lbl_805A8638 = .sdata:0x805A8638; // type:object size:0x8 data:4byte lbl_805A8640 = .sdata:0x805A8640; // type:object size:0x8 skGlobalSeed__17CProjectileWeapon = .sdata:0x805A8648; // type:object size:0x4 data:4byte diff --git a/config/GM8E01_01/symbols.txt b/config/GM8E01_01/symbols.txt index f2d4d415..8e122170 100644 --- a/config/GM8E01_01/symbols.txt +++ b/config/GM8E01_01/symbols.txt @@ -7660,7 +7660,7 @@ __ct__22CCameraShakerComponentFiRC17SCameraShakePointRC17SCameraShakePoint = .te GetSomething__17SCameraShakePointFv = .text:0x8015D348; // type:function size:0x1C scope:global fn_8015D2E8 = .text:0x8015D364; // type:function size:0xDC scope:global __ct__17SCameraShakePointFv = .text:0x8015D440; // type:function size:0x34 scope:global -LoadCameraShakePoint__R12CInputStream = .text:0x8015D474; // type:function size:0xAC scope:global +LoadCameraShakePoint__FR12CInputStream = .text:0x8015D474; // type:function size:0xAC scope:global __ct__17SCameraShakePointFiffff = .text:0x8015D520; // type:function size:0x20 scope:global BuildMissileShakeData__16CCameraShakeDataFfffRC9CVector3f = .text:0x8015D540; // type:function size:0x100 scope:global BuildPatternedExplodeShakeData__16CCameraShakeDataFRC9CVector3ffff = .text:0x8015D640; // type:function size:0x100 scope:global diff --git a/include/WorldFormat/CCollidableOBBTree.hpp b/include/WorldFormat/CCollidableOBBTree.hpp index 0592a158..c028de32 100644 --- a/include/WorldFormat/CCollidableOBBTree.hpp +++ b/include/WorldFormat/CCollidableOBBTree.hpp @@ -3,17 +3,39 @@ #include -class COBBTree; -class CCollidableOBBTree : public CCollisionPrimitive { +#include "WorldFormat/COBBTree.hpp" +class COBBTree; +class COBBox; +class CCollidableOBBTree : public CCollisionPrimitive { public: - CCollidableOBBTree(const COBBTree& tree, const CMaterialList& list); + CCollidableOBBTree(COBBTree* tree, const CMaterialList& list); uint GetTableIndex() const override; CAABox CalculateAABox(const CTransform4f& xf) const override; - const CAABox CalculateLocalAABox() const override; + CAABox CalculateLocalAABox() const override; FourCC GetPrimType() const override; CRayCastResult CastRayInternal(const CInternalRayCastStructure& intRayCast) const override; + + bool AABoxCollision(const COBBTree::CNode& node, const CTransform4f& xf, const CAABox& abb, + const COBBox& obb, const CMaterialList& matList, + const CMaterialFilter& matFilter, const CPlane plane[6], + CCollisionInfoList& outList) const; + bool AABoxCollideWithLeaf(const COBBTree::CLeafData&, const CTransform4f&, const CAABox&, + const CMaterialList&, const CMaterialFilter&, const CPlane*, + CCollisionInfoList&) const; + + void ResetTestStats() const {} + + void ResetTestStatsRecurse(const COBBTree::CNode& node) const {} + +private: + COBBTree* x10_tree; + mutable uint x14_tries; + mutable uint x18_misses; + mutable uint x1c_hits; + + static uint sTableIndex; }; #endif // _CCOLLIDABLEOBBTREE diff --git a/include/WorldFormat/COBBTree.hpp b/include/WorldFormat/COBBTree.hpp index e85a49da..239895a8 100644 --- a/include/WorldFormat/COBBTree.hpp +++ b/include/WorldFormat/COBBTree.hpp @@ -38,7 +38,7 @@ public: private: rstl::vector< ushort > x0_surface; }; - + class CNode { public: CNode(const CTransform4f& xf, const CVector3f& point, const CNode* left, const CNode* right, @@ -53,7 +53,8 @@ public: const CNode* GetLeftNode() const { return x40_left; } const CNode* GetRightNode() const { return x44_right; } bool WasHit() const { return x4c_hit; } - void SetHit(bool hit) { x4c_hit = hit; } + void SetHit(const bool hit) const { x4c_hit = hit; } + const CLeafData* GetLeafData() const { return x48_leaf; } static void* operator new(size_t size, const char* file, int line); static void operator delete(void* ptr, size_t size); @@ -64,11 +65,11 @@ public: const CNode* x40_left; const CNode* x44_right; const CLeafData* x48_leaf; - bool x4c_hit; + mutable bool x4c_hit; static CSimpleAllocator* spAllocator; }; - + struct SIndexData { rstl::vector< uint > x0_materials; rstl::vector< uchar > x10_vertMaterials; @@ -85,9 +86,9 @@ public: COBBTree(const SIndexData& indexData, const CNode* root); ~COBBTree(); - - static rstl::auto_ptr< COBBTree > BuildOrientedBoundingBoxTree(const CVector3f& extent, const CVector3f& center); - + static rstl::auto_ptr< COBBTree > BuildOrientedBoundingBoxTree(const CVector3f& extent, + const CVector3f& center); + CAABox CalculateLocalAABox() const; void GetTriangleVertexIndices(const ushort index, ushort out[2]) const; diff --git a/src/WorldFormat/CCollidableOBBTree.cpp b/src/WorldFormat/CCollidableOBBTree.cpp new file mode 100644 index 00000000..78e956ee --- /dev/null +++ b/src/WorldFormat/CCollidableOBBTree.cpp @@ -0,0 +1,55 @@ +#include "WorldFormat/CCollidableOBBTree.hpp" + +#include "WorldFormat/COBBTree.hpp" + +uint CCollidableOBBTree::sTableIndex = -1; + +CCollidableOBBTree::CCollidableOBBTree(COBBTree* tree, const CMaterialList& material) +: CCollisionPrimitive(material), x10_tree(tree), x14_tries(0), x18_misses(0), x1c_hits(0) {} + +CAABox CCollidableOBBTree::CalculateAABox(const CTransform4f& xf) const { + const COBBox obbox = COBBox::FromAABox(x10_tree->CalculateLocalAABox(), xf); + return obbox.CalculateAABox(CTransform4f::Identity()); +} + +CAABox CCollidableOBBTree::CalculateLocalAABox() const { return x10_tree->CalculateLocalAABox(); } + +FourCC CCollidableOBBTree::GetPrimType() const { return 'OBBT'; } + +bool CCollidableOBBTree::AABoxCollision(const COBBTree::CNode& node, const CTransform4f& xf, + const CAABox& abb, const COBBox& obb, + const CMaterialList& matList, + const CMaterialFilter& matFilter, const CPlane planes[6], + CCollisionInfoList& outList) const { + + bool ret = false; + + x14_tries++; + + if (obb.OBBIntersectsBox(node.GetOBB())) { + node.SetHit(true); + if (node.IsLeaf()) { + if (AABoxCollideWithLeaf(*node.GetLeafData(), xf, abb, matList, matFilter, planes, outList)) { + ret = true; + } + } else { + if (AABoxCollision(*node.GetLeftNode(), xf, abb, obb, matList, matFilter, planes, outList)) { + ret = true; + } + if (AABoxCollision(*node.GetRightNode(), xf, abb, obb, matList, matFilter, planes, outList)) { + ret = true; + } + } + } else { + x18_misses++; + } + return ret; +} + +CPlane TransformPlane(const CPlane& plane, const CTransform4f& xf) { + const CVector3f dVec = xf * (plane.GetNormal() * plane.GetConstant()); + const CVector3f normal = xf.Rotate(plane.GetNormal()); + return CPlane(dVec, CUnitVector3f(normal.GetX(), normal.GetY(), normal.GetZ())); +} + +uint CCollidableOBBTree::GetTableIndex() const { return sTableIndex; } \ No newline at end of file