Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions config/GM8E01_00/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -11683,8 +11683,8 @@ __ct__Q28COBBTree5CNodeFRC12CTransform4fRC9CVector3fPCQ28COBBTree5CNodePCQ28COBB
GetTriangleEdgeIndices__8COBBTreeCFUs = .text:0x802A7F4C; // type:function size:0x14 scope:global
GetTriangleVertexIndices__8COBBTreeCFUsPUs = .text:0x802A7F60; // type:function size:0xB0 scope:global
BuildOrientedBoundingBoxTree__8COBBTreeFRC9CVector3fRC9CVector3f = .text:0x802A8010; // type:function size:0x6A4 scope:global
fn_802A86B4 = .text:0x802A86B4; // type:function size:0xF8
fn_802A87AC = .text:0x802A87AC; // type:function size:0x238
__as__Q24rstl37vector<Uc,Q24rstl17rmemory_allocator>FRCQ24rstl37vector<Uc,Q24rstl17rmemory_allocator> = .text:0x802A86B4; // type:function size:0xF8
__dt__Q28COBBTree10SIndexDataFv = .text:0x802A87AC; // type:function size:0x238
__ct__Q28COBBTree10SIndexDataFv = .text:0x802A89E4; // type:function size:0x5C scope:global
GetTransformedSurface__8COBBTreeCFUsRC12CTransform4f = .text:0x802A8A40; // type:function size:0x17C scope:global
GetSurface__8COBBTreeCFUs = .text:0x802A8BBC; // type:function size:0xF4 scope:global
Expand Down Expand Up @@ -17679,8 +17679,11 @@ lbl_803D6008 = .rodata:0x803D6008; // type:object size:0x10 data:4byte
@stringBase0 = .rodata:0x803D6018; // type:object size:0x7 scope:local data:string_table
lbl_803D6020 = .rodata:0x803D6020; // type:object size:0x7 data:string
lbl_803D6028 = .rodata:0x803D6028; // type:object size:0x10 data:4byte
lbl_803D6038 = .rodata:0x803D6038; // type:object size:0xB0 data:byte
lbl_803D60E8 = .rodata:0x803D60E8; // type:object size:0x7 data:string
kEdgeMaterials$594 = .rodata:0x803D6038; // type:object size:0x12 scope:local data:byte
kTriangleMaterials$600 = .rodata:0x803D604C; // type:object size:0xC scope:local data:byte
kEdges$606 = .rodata:0x803D6058; // type:object size:0x48 scope:local data:2byte
kTriangleEdgeMaterials$612 = .rodata:0x803D60A0; // type:object size:0x48 scope:local data:2byte
@stringBase0 = .rodata:0x803D60E8; // type:object size:0x7 scope:local data:string
lbl_803D60F0 = .rodata:0x803D60F0; // type:object size:0x20
lbl_803D6110 = .rodata:0x803D6110; // type:object size:0x7 data:string
lbl_803D6118 = .rodata:0x803D6118; // type:object size:0x20
Expand Down Expand Up @@ -18739,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
Expand Down Expand Up @@ -21274,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
Expand Down Expand Up @@ -21923,7 +21926,7 @@ gRejectedByClip = .sbss:0x805A9184; // type:object size:0x4 scope:global data:4b
gTrianglesProcessed = .sbss:0x805A9188; // type:object size:0x4 scope:global data:4byte
gDupTrianglesProcessed = .sbss:0x805A918C; // type:object size:0x4 scope:global data:4byte
sDupPrimitiveCheckCount__20CMetroidAreaCollider = .sbss:0x805A9190; // type:object size:0x8 scope:global data:2byte
lbl_805A9198 = .sbss:0x805A9198; // type:object size:0x8 data:4byte
spAllocator__Q28COBBTree5CNode = .sbss:0x805A9198; // type:object size:0x8 data:4byte
sDefaultRenderer = .sbss:0x805A91A0; // type:object size:0x4 scope:local data:4byte
sDecalRandom__6CDecal = .sbss:0x805A91A8; // type:object size:0x4 scope:global
sMoveRedToAlphaBuffer__6CDecal = .sbss:0x805A91AC; // type:object size:0x1 scope:global data:byte
Expand Down
4 changes: 2 additions & 2 deletions config/GM8E01_01/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -11684,7 +11684,7 @@ GetTriangleEdgeIndices__8COBBTreeCFUs = .text:0x802A7FF8; // type:function size:
GetTriangleVertexIndices__8COBBTreeCFUsPUs = .text:0x802A800C; // type:function size:0xB0 scope:global
BuildOrientedBoundingBoxTree__8COBBTreeFRC9CVector3fRC9CVector3f = .text:0x802A80BC; // type:function size:0x6A4 scope:global
fn_802A86B4 = .text:0x802A8760; // type:function size:0xF8 scope:global
fn_802A87AC = .text:0x802A8858; // type:function size:0x238 scope:global
__dt__Q28COBBTree10SIndexDataFv = .text:0x802A8858; // type:function size:0x238 scope:global
__ct__Q28COBBTree10SIndexDataFv = .text:0x802A8A90; // type:function size:0x5C scope:global
GetTransformedSurface__8COBBTreeCFUsRC12CTransform4f = .text:0x802A8AEC; // type:function size:0x17C scope:global
GetSurface__8COBBTreeCFUs = .text:0x802A8C68; // type:function size:0xF4 scope:global
Expand Down
28 changes: 25 additions & 3 deletions include/WorldFormat/CCollidableOBBTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,39 @@

#include <Collision/CCollisionPrimitive.hpp>

#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
16 changes: 9 additions & 7 deletions include/WorldFormat/CCollisionEdge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@

class CCollisionEdge {
public:
CCollisionEdge(CInputStream& in){
x0_index1 = in.Get<u16>();
x2_index2 = in.Get<u16>();
CCollisionEdge(const ushort x0, const ushort x1) : x0_index1(x0), x2_index2(x1) {}
CCollisionEdge(CInputStream& in) {
x0_index1 = in.Get< u16 >();
x2_index2 = in.Get< u16 >();
}

u16 GetVertIndex1() const { return x0_index1; }
u16 GetVertIndex2() const { return x2_index2; }
const ushort GetVertIndex1() const { return x0_index1; }
const ushort GetVertIndex2() const { return x2_index2; }

private:
u16 x0_index1;
u16 x2_index2;
ushort x0_index1;
ushort x2_index2;
};

#endif // _CCOLLISIONEDGE
80 changes: 77 additions & 3 deletions include/WorldFormat/COBBTree.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,75 @@
#ifndef _COBBTREE
#define _COBBTREE

#include "Collision/COBBox.hpp"
#include "Kyoto/Math/CVector3f.hpp"

#include "WorldFormat/CCollisionEdge.hpp"
#include "rstl/auto_ptr.hpp"
#include "rstl/single_ptr.hpp"

#include "rstl/vector.hpp"

class COBBTree {
class CNode {};
public:
class CSimpleAllocator {
public:
CSimpleAllocator(uint size);
~CSimpleAllocator();

void* Alloc(size_t size);
uint GetPoolMemSize() const { return mPoolSize; }

private:
char* mPool;
uint mPoolSize;
uint mPoolOffset;
};

class CLeafData {
public:
CLeafData(const rstl::vector< ushort >& surface);
CLeafData(CInputStream& in);

uint GetMemoryUsage() const;

const rstl::vector< ushort >& GetSurfaceVector() const { return x0_surface; }

private:
rstl::vector< ushort > x0_surface;
};

class CNode {
public:
CNode(const CTransform4f& xf, const CVector3f& point, const CNode* left, const CNode* right,
const CLeafData* leaf);
CNode(CInputStream& in);
~CNode();
static void SetAllocator(CSimpleAllocator* allocator);
uint GetMemoryUsage() const;

const COBBox& GetOBB() const { return x0_obb; }
bool IsLeaf() const { return x3c_isLeaf; }
const CNode* GetLeftNode() const { return x40_left; }
const CNode* GetRightNode() const { return x44_right; }
bool WasHit() const { return x4c_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);

private:
COBBox x0_obb;
bool x3c_isLeaf;
const CNode* x40_left;
const CNode* x44_right;
const CLeafData* x48_leaf;
mutable bool x4c_hit;

static CSimpleAllocator* spAllocator;
};

struct SIndexData {
rstl::vector< uint > x0_materials;
rstl::vector< uchar > x10_vertMaterials;
Expand All @@ -17,16 +78,29 @@ class COBBTree {
rstl::vector< CCollisionEdge > x40_edges;
rstl::vector< ushort > x50_surfaceIndices;
rstl::vector< CVector3f > x60_vertices;
SIndexData() {}
SIndexData(CInputStream& in);
};

public:
COBBTree(CInputStream& in);
COBBTree(const SIndexData& indexData, const CNode* root);
~COBBTree();

static rstl::auto_ptr< COBBTree > BuildOrientedBoundingBoxTree(const CVector3f& extent,
const CVector3f& center);

CAABox CalculateLocalAABox() const;

void GetTriangleVertexIndices(const ushort index, ushort out[2]) const;
const ushort* GetTriangleEdgeIndices(ushort index) const;

private:
char data[0x8c];
uint x0_;
uint x4_;
uint x8_memoryUsage;
CSimpleAllocator xc_allocator;
SIndexData x18_indexData;
const CNode* x88_root;
};

#endif // _COBBTREE
55 changes: 55 additions & 0 deletions src/WorldFormat/CCollidableOBBTree.cpp
Original file line number Diff line number Diff line change
@@ -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; }
Loading
Loading