Files

106 lines
3.5 KiB
C++
Raw Permalink Normal View History

#ifndef _CAREAOCTTREE
#define _CAREAOCTTREE
2022-09-29 19:55:38 -04:00
#include "types.h"
#include "WorldFormat/CCollisionSurface.hpp"
#include "Kyoto/Math/CAABox.hpp"
#include "Kyoto/Math/CPlane.hpp"
#include "rstl/optional_object.hpp"
class CCollisionEdge;
class CLine;
class CMaterialFilter;
class CAreaOctTree {
public:
struct SRayResult {
CPlane x0_plane;
rstl::optional_object< CCollisionSurface > x10_surface;
2022-10-09 01:37:23 -04:00
float x3c_t;
2026-03-13 01:27:42 -06:00
SRayResult() : x0_plane(0.f, CUnitVector3f(1.f, 0.f, 0.f)), x3c_t(0.f) {}
2022-09-29 19:55:38 -04:00
};
class TriListReference {
public:
2022-10-09 01:37:23 -04:00
explicit TriListReference(const ushort* ptr) : m_ptr(ptr) {}
ushort GetAt(int idx) const { return m_ptr[idx + 1]; }
ushort GetSize() const { return m_ptr[0]; }
2022-09-29 19:55:38 -04:00
private:
2022-10-09 01:37:23 -04:00
const ushort* m_ptr;
2022-09-29 19:55:38 -04:00
};
class Node {
public:
enum ETreeType { kTT_Invalid, kTT_Branch, kTT_Leaf };
Node(const void* ptr, const CAABox& aabb, const CAreaOctTree& owner, ETreeType type)
: x0_aabb(aabb)
2022-10-09 01:37:23 -04:00
, x18_ptr(reinterpret_cast< const uchar* >(ptr))
2022-09-29 19:55:38 -04:00
, x1c_owner(owner)
, x20_nodeType(type) {}
2022-10-09 01:37:23 -04:00
bool LineTest(const CLine& line, const CMaterialFilter& filter, float length) const;
2022-09-29 19:55:38 -04:00
void LineTestEx(const CLine& line, const CMaterialFilter& filter, SRayResult& res,
2022-10-09 01:37:23 -04:00
float length) const;
2022-09-29 19:55:38 -04:00
const CAreaOctTree& GetOwner() const { return x1c_owner; }
const CAABox& GetBoundingBox() const { return x0_aabb; }
2022-10-09 01:37:23 -04:00
ushort GetChildFlags() const { return *reinterpret_cast< const ushort* >(x18_ptr); }
2022-09-29 19:55:38 -04:00
Node GetChild(int idx) const;
TriListReference GetTriangleArray() const;
ETreeType GetChildType(int idx) const {
2022-10-09 01:37:23 -04:00
ushort flags = *reinterpret_cast< const ushort* >(x18_ptr);
2022-09-29 19:55:38 -04:00
return ETreeType((flags >> (2 * idx)) & 0x3);
}
ETreeType GetTreeType() const { return x20_nodeType; }
private:
CAABox x0_aabb;
2022-10-09 01:37:23 -04:00
const uchar* x18_ptr;
2022-09-29 19:55:38 -04:00
const CAreaOctTree& x1c_owner;
ETreeType x20_nodeType;
2022-10-09 01:37:23 -04:00
bool LineTestInternal(const CLine& line, const CMaterialFilter& filter, float lT, float hT,
float maxT, const CVector3f& vec) const;
2022-09-29 19:55:38 -04:00
void LineTestExInternal(const CLine& line, const CMaterialFilter& filter, SRayResult& res,
2022-10-09 01:37:23 -04:00
float lT, float hT, float maxT, const CVector3f& dirRecip) const;
2022-09-29 19:55:38 -04:00
};
2025-05-21 08:42:32 -07:00
CAreaOctTree(const CAABox& bounds, Node::ETreeType treeType, uchar* buf, void* treeBuf,
uint materialCount, uint* materials, uchar* vertexMaterials, uchar* edgeMaterials,
uchar* triMaterials, uint edgeCount, CCollisionEdge* edges, uint triCount,
ushort* triangles, uint vertexCount, CVector3f* vertices);
void MakeFromMemory(void* buf, uint bufLen, CAreaOctTree** treeOut, bool*);
2022-10-20 20:26:38 -04:00
CCollisionSurface GetMasterListTriangle(ushort idx) const;
2026-03-13 01:27:42 -06:00
Node GetRootNode() const { return Node(x20_treeBuf, x0_aabb, *this, x18_treeType); }
const void* GetTreeMemory() const { return x20_treeBuf; }
const CAABox& GetBoundingBox() const { return x0_aabb; }
Node::ETreeType GetTreeType() const { return x18_treeType; }
2022-09-29 19:55:38 -04:00
// TODO
private:
CAABox x0_aabb;
Node::ETreeType x18_treeType;
2022-10-09 01:37:23 -04:00
const uchar* x1c_buf;
2025-05-21 08:42:32 -07:00
const void* x20_treeBuf;
2022-09-29 19:55:38 -04:00
uint x24_matCount;
const uint* x28_materials;
2022-10-09 01:37:23 -04:00
const uchar* x2c_vertMats;
const uchar* x30_edgeMats;
const uchar* x34_polyMats;
2022-09-29 19:55:38 -04:00
uint x38_edgeCount;
const CCollisionEdge* x3c_edges;
uint x40_polyCount;
2022-10-09 01:37:23 -04:00
const ushort* x44_polyEdges;
2022-09-29 19:55:38 -04:00
uint x48_vertCount;
2025-05-21 08:42:32 -07:00
const CVector3f* x4c_verts;
2022-09-29 19:55:38 -04:00
};
CHECK_SIZEOF(CAreaOctTree, 0x50)
#endif // _CAREAOCTTREE