Skip to content

Commit 4f7763c

Browse files
committed
WIP CMetroidAreaCollider
1 parent 484417b commit 4f7763c

File tree

7 files changed

+998
-36
lines changed

7 files changed

+998
-36
lines changed

config/GM8E01_00/symbols.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11627,19 +11627,19 @@ GetTriangleArray__Q212CAreaOctTree4NodeCFv = .text:0x802A2D3C; // type:function
1162711627
GetChild__Q212CAreaOctTree4NodeCFi = .text:0x802A2D60; // type:function size:0x150 scope:global
1162811628
BoxFromIndex__FiRC9CVector3fRC9CVector3fRC9CVector3f = .text:0x802A2EB0; // type:function size:0x1EC scope:local
1162911629
__ct__Q220CMetroidAreaCollider22CMovingAABoxComponentsFRC6CAABoxRC9CVector3f = .text:0x802A309C; // type:function size:0x2E8 scope:global
11630-
fn_802A3384 = .text:0x802A3384; // type:function size:0x48
11631-
fn_802A33CC = .text:0x802A33CC; // type:function size:0x28
11632-
fn_802A33F4 = .text:0x802A33F4; // type:function size:0xB4
11630+
push_back__Q24rstl53reserved_vector<Q220CMetroidAreaCollider8SBoxEdge,12>FRCQ220CMetroidAreaCollider8SBoxEdge = .text:0x802A3384; // type:function size:0x48 scope:weak
11631+
construct<Q220CMetroidAreaCollider8SBoxEdge>__4rstlFPvRCQ220CMetroidAreaCollider8SBoxEdge = .text:0x802A33CC; // type:function size:0x28 scope:local
11632+
__ct__Q220CMetroidAreaCollider8SBoxEdgeFRCQ220CMetroidAreaCollider8SBoxEdge = .text:0x802A33F4; // type:function size:0xB4 scope:weak
1163311633
__ct__Q220CMetroidAreaCollider8SBoxEdgeFRC6CAABoxiRC9CVector3f = .text:0x802A34A8; // type:function size:0x118 scope:global
1163411634
FlagVertexIndicesForFace__FUiPb = .text:0x802A35C0; // type:function size:0xC4 scope:global
1163511635
FlagEdgeIndicesForFace__FUiPb = .text:0x802A3684; // type:function size:0xC4 scope:global
1163611636
BuildOctreeLeafCache__20CMetroidAreaColliderFRCQ212CAreaOctTree4NodeRC6CAABoxRQ220CMetroidAreaCollider16COctreeLeafCache = .text:0x802A3748; // type:function size:0xF0 scope:global
1163711637
ClearCache__19CAreaCollisionCacheFv = .text:0x802A3838; // type:function size:0xAC scope:global
1163811638
SetCacheBounds__19CAreaCollisionCacheFRC6CAABox = .text:0x802A38E4; // type:function size:0x34 scope:global
1163911639
AddOctreeLeafCache__19CAreaCollisionCacheFRCQ220CMetroidAreaCollider16COctreeLeafCache = .text:0x802A3918; // type:function size:0x78 scope:global
11640-
fn_802A3990 = .text:0x802A3990; // type:function size:0x48
11641-
fn_802A39D8 = .text:0x802A39D8; // type:function size:0x28
11642-
fn_802A3A00 = .text:0x802A3A00; // type:function size:0x90
11640+
push_back__Q24rstl61reserved_vector<Q220CMetroidAreaCollider16COctreeLeafCache,3>FRCQ220CMetroidAreaCollider16COctreeLeafCache = .text:0x802A3990; // type:function size:0x48 scope:global
11641+
construct<Q220CMetroidAreaCollider16COctreeLeafCache>__4rstlFPvRCQ220CMetroidAreaCollider16COctreeLeafCache = .text:0x802A39D8; // type:function size:0x28 scope:local
11642+
__ct__Q220CMetroidAreaCollider16COctreeLeafCacheFRCQ220CMetroidAreaCollider16COctreeLeafCache = .text:0x802A3A00; // type:function size:0x90 scope:global
1164311643
__ct__19CAreaCollisionCacheFRC6CAABox = .text:0x802A3A90; // type:function size:0x54 scope:global
1164411644
AddLeaf__Q220CMetroidAreaCollider16COctreeLeafCacheFRCQ212CAreaOctTree4Node = .text:0x802A3AE4; // type:function size:0x88 scope:global
1164511645
__ct__Q220CMetroidAreaCollider16COctreeLeafCacheFRC12CAreaOctTree = .text:0x802A3B6C; // type:function size:0x1C scope:global

include/Kyoto/Math/CUnitVector3f.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class CUnitVector3f : public CVector3f {
1313
};
1414

1515
CUnitVector3f(const float x, const float y, const float z) : CVector3f(x, y, z) {}
16+
CUnitVector3f(const float x, const float y, const float z, ENormalize)
17+
: CVector3f(x, y, z) {}
1618
CUnitVector3f(const CVector3f& vec, const ENormalize normalize) : CVector3f(vec) {
1719
if (normalize == kN_Yes) {
1820
Normalize();

include/Kyoto/Math/CVector3d.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class CVector3d {
1717
double GetY() const { return mY; }
1818
double GetZ() const { return mZ; }
1919

20-
double& operator[](int i) { return (&mX)[i]; }
21-
const double operator[](int i) const { return (&mX)[i]; }
20+
double& operator[](int i) { return reinterpret_cast<double*>(this)[i]; }
21+
const double& operator[](int i) const { return reinterpret_cast<const double*>(this)[i]; }
2222

2323
static double Dot(const CVector3d& a, const CVector3d& b);
2424
static CVector3d Cross(const CVector3d& a, const CVector3d& b);

include/WorldFormat/CAreaOctTree.hpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
#include "rstl/optional_object.hpp"
1212

13-
class CCollisionEdge;
13+
#include "WorldFormat/CCollisionEdge.hpp"
14+
1415
class CLine;
1516
class CMaterialFilter;
1617

@@ -27,8 +28,8 @@ class CAreaOctTree {
2728
class TriListReference {
2829
public:
2930
explicit TriListReference(const ushort* ptr) : m_ptr(ptr) {}
30-
ushort GetAt(int idx) const { return m_ptr[idx + 1]; }
31-
ushort GetSize() const { return m_ptr[0]; }
31+
ushort GetAt(int idx) const { return m_ptr[idx + 13]; }
32+
ushort GetSize() const { return m_ptr[12]; }
3233

3334
private:
3435
const ushort* m_ptr;
@@ -81,7 +82,14 @@ class CAreaOctTree {
8182
const void* GetTreeMemory() const { return x20_treeBuf; }
8283
const CAABox& GetBoundingBox() const { return x0_aabb; }
8384
Node::ETreeType GetTreeType() const { return x18_treeType; }
84-
// TODO
85+
86+
const CVector3f& GetVert(int idx) const { return x4c_verts[idx]; }
87+
const CCollisionEdge& GetEdge(int idx) const { return x3c_edges[idx]; }
88+
uint GetVertMaterial(int idx) const { return x28_materials[x2c_vertMats[idx]]; }
89+
uint GetEdgeMaterial(int idx) const { return x28_materials[x30_edgeMats[idx]]; }
90+
uint GetTriangleMaterial(int idx) const { return x28_materials[x34_polyMats[idx]]; }
91+
void GetTriangleVertexIndices(ushort idx, ushort indicesOut[3]) const;
92+
const ushort* GetTriangleEdgeIndices(ushort idx) const;
8593

8694
private:
8795
CAABox x0_aabb;

include/WorldFormat/CMetroidAreaCollider.hpp

Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
#include "Collision/CMaterialList.hpp"
1111

1212
#include "Kyoto/Math/CAABox.hpp"
13+
#include "Kyoto/Math/CLineSeg.hpp"
1314
#include "Kyoto/Math/CPlane.hpp"
1415
#include "Kyoto/Math/CSphere.hpp"
16+
#include "Kyoto/Math/CVector3d.hpp"
1517
#include "Kyoto/Math/CVector3f.hpp"
1618

1719
#include "rstl/reserved_vector.hpp"
@@ -21,14 +23,7 @@ class CAABoxAreaCache {
2123
friend class CMetroidAreaCollider;
2224

2325
CAABoxAreaCache(const CAABox& aabb, const CPlane* pl, const CMaterialFilter& filter,
24-
const CMaterialList& material, CCollisionInfoList& collisionList)
25-
: x0_aabb(aabb)
26-
, x4_planes(pl)
27-
, x8_filter(filter)
28-
, xc_material(material)
29-
, x10_collisionList(collisionList)
30-
, x14_center(aabb.GetCenterPoint())
31-
, x20_halfExtent(aabb.GetHalfExtent()) {}
26+
const CMaterialList& material, CCollisionInfoList& collisionList);
3227

3328
private:
3429
const CAABox& x0_aabb;
@@ -40,8 +35,76 @@ class CAABoxAreaCache {
4035
CVector3f x20_halfExtent;
4136
};
4237

38+
class CBooleanAABoxAreaCache {
39+
public:
40+
friend class CMetroidAreaCollider;
41+
42+
CBooleanAABoxAreaCache(const CAABox& aabb, const CMaterialFilter& filter);
43+
44+
private:
45+
const CAABox& x0_aabb;
46+
const CMaterialFilter& x4_filter;
47+
CVector3f x8_center;
48+
CVector3f x14_halfExtent;
49+
};
50+
51+
class CSphereAreaCache {
52+
public:
53+
friend class CMetroidAreaCollider;
54+
55+
CSphereAreaCache(const CAABox& aabb, const CSphere& sphere, const CMaterialFilter& filter,
56+
const CMaterialList& material, CCollisionInfoList& collisionList)
57+
: x0_aabb(aabb)
58+
, x4_sphere(sphere)
59+
, x8_filter(filter)
60+
, xc_material(material)
61+
, x10_collisionList(collisionList) {}
62+
63+
private:
64+
const CAABox& x0_aabb;
65+
const CSphere& x4_sphere;
66+
const CMaterialFilter& x8_filter;
67+
const CMaterialList& xc_material;
68+
CCollisionInfoList& x10_collisionList;
69+
};
70+
71+
class CBooleanSphereAreaCache {
72+
public:
73+
friend class CMetroidAreaCollider;
74+
75+
CBooleanSphereAreaCache(const CAABox& aabb, const CSphere& sphere, const CMaterialFilter& filter)
76+
: x0_aabb(aabb), x4_sphere(sphere), x8_filter(filter) {}
77+
78+
private:
79+
const CAABox& x0_aabb;
80+
const CSphere& x4_sphere;
81+
const CMaterialFilter& x8_filter;
82+
};
83+
4384
class CMetroidAreaCollider {
4485
public:
86+
struct SBoxEdge {
87+
CLineSeg x0_seg;
88+
CVector3d x28_start;
89+
CVector3d x40_end;
90+
CVector3d x58_delta;
91+
CVector3d x70_coDir;
92+
double x88_dirCoDirDot;
93+
SBoxEdge(const CAABox& aabb, int idx, const CVector3f& dir);
94+
};
95+
96+
class CMovingAABoxComponents {
97+
public:
98+
CMovingAABoxComponents(const CAABox& aabb, const CVector3f& dir);
99+
100+
private:
101+
friend class CMetroidAreaCollider;
102+
friend class CCollidableOBBTree;
103+
rstl::reserved_vector< SBoxEdge, 12 > x0_edges;
104+
rstl::reserved_vector< uint, 8 > x6c4_vertIdxs;
105+
CAABox x6e8_aabb;
106+
};
107+
45108
class COctreeLeafCache {
46109
public:
47110
COctreeLeafCache(const CAreaOctTree& octTree);
@@ -58,6 +121,7 @@ class CMetroidAreaCollider {
58121
}
59122

60123
private:
124+
friend class CMetroidAreaCollider;
61125
const CAreaOctTree& x0_octTree;
62126
rstl::reserved_vector< CAreaOctTree::Node, 64 > x4_nodeCache;
63127
bool x908_24_overflow : 1;
@@ -106,13 +170,29 @@ class CMetroidAreaCollider {
106170
float d, CCollisionInfo& infoOut,
107171
double& dOut);
108172

173+
static ushort GetPrimitiveCheckCount() { return sDupPrimitiveCheckCount; }
174+
static ushort* GetTriangleList() { return sDupTriangleList; }
175+
109176
private:
110177
static ushort sDupPrimitiveCheckCount;
111178
static ushort sDupVertexList[0x2800];
112179
static ushort sDupEdgeList[0x6000];
113180
static ushort sDupTriangleList[0x4000];
114181
static void ResetInternalCounters();
115182
static bool AABoxCollisionCheck_Internal(const CAreaOctTree::Node&, CAABoxAreaCache&);
183+
static bool AABoxCollisionCheckBoolean_Internal(const CAreaOctTree::Node&,
184+
const CBooleanAABoxAreaCache&);
185+
static bool SphereCollisionCheck_Internal(const CAreaOctTree::Node&, CSphereAreaCache&);
186+
static bool SphereCollisionCheckBoolean_Internal(const CAreaOctTree::Node&,
187+
const CBooleanSphereAreaCache&);
188+
static bool MovingAABoxCollisionCheck_BoxVertexTri(const CCollisionSurface&, const CAABox&,
189+
const rstl::reserved_vector< uint, 8 >&,
190+
CVector3f, double&, CVector3f&, CVector3f&);
191+
static bool MovingAABoxCollisionCheck_TriVertexBox(const CVector3f&, const CAABox&,
192+
CVector3f, double&, CVector3f&, CVector3f&);
193+
static bool MovingAABoxCollisionCheck_Edge(const CVector3f&, const CVector3f&,
194+
const rstl::reserved_vector< SBoxEdge, 12 >&,
195+
CVector3f, double&, CVector3f&, CVector3f&);
116196
};
117197

118198
class CAreaCollisionCache {

src/WorldFormat/CAreaOctTree.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include "Kyoto/Math/CAABox.hpp"
44
#include "Kyoto/Streams/CMemoryInStream.hpp"
55

6+
const ushort* CAreaOctTree::GetTriangleEdgeIndices(ushort idx) const {
7+
return &x44_polyEdges[idx * 3];
8+
}
9+
610
static CAABox BoxFromIndex(int index, const CVector3f& a, const CVector3f& b, const CVector3f& c) {
711
switch (index) {
812
case 0:

0 commit comments

Comments
 (0)