2018-10-07 03:42:33 +00:00
|
|
|
#pragma once
|
2019-09-28 02:53:03 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Runtime/RetroTypes.hpp"
|
|
|
|
#include "Runtime/Collision/CCollisionEdge.hpp"
|
|
|
|
#include "Runtime/Collision/CCollisionSurface.hpp"
|
|
|
|
|
|
|
|
#include <zeus/COBBox.hpp>
|
|
|
|
#include <zeus/CVector3f.hpp>
|
2016-04-26 10:40:56 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2017-07-03 03:34:19 +00:00
|
|
|
class CCollidableOBBTreeGroupContainer;
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
class COBBTree {
|
2016-04-26 10:40:56 +00:00
|
|
|
public:
|
2018-12-08 05:30:43 +00:00
|
|
|
struct SIndexData {
|
|
|
|
std::vector<u32> x0_materials;
|
|
|
|
std::vector<u8> x10_vertMaterials;
|
|
|
|
std::vector<u8> x20_edgeMaterials;
|
|
|
|
std::vector<u8> x30_surfaceMaterials;
|
|
|
|
std::vector<CCollisionEdge> x40_edges;
|
|
|
|
std::vector<u16> x50_surfaceIndices;
|
|
|
|
std::vector<zeus::CVector3f> x60_vertices;
|
|
|
|
SIndexData() = default;
|
|
|
|
SIndexData(CInputStream&);
|
|
|
|
};
|
2016-04-26 10:40:56 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
class CLeafData {
|
|
|
|
std::vector<u16> x0_surface;
|
2016-04-27 00:26:02 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
public:
|
|
|
|
CLeafData() = default;
|
2019-01-05 03:28:02 +00:00
|
|
|
CLeafData(std::vector<u16>&& surface);
|
2018-12-08 05:30:43 +00:00
|
|
|
CLeafData(CInputStream&);
|
2016-04-26 10:40:56 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const std::vector<u16>& GetSurfaceVector() const;
|
|
|
|
size_t GetMemoryUsage() const;
|
|
|
|
};
|
2016-04-27 00:26:02 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
class CNode {
|
|
|
|
zeus::COBBox x0_obb;
|
|
|
|
bool x3c_isLeaf = false;
|
|
|
|
std::unique_ptr<CNode> x40_left;
|
|
|
|
std::unique_ptr<CNode> x44_right;
|
|
|
|
std::unique_ptr<CLeafData> x48_leaf;
|
|
|
|
bool x4c_hit;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CNode() = default;
|
2019-01-05 03:28:02 +00:00
|
|
|
CNode(const zeus::CTransform&, const zeus::CVector3f&, std::unique_ptr<CNode>&&, std::unique_ptr<CNode>&&,
|
|
|
|
std::unique_ptr<CLeafData>&&);
|
2018-12-08 05:30:43 +00:00
|
|
|
CNode(CInputStream&);
|
|
|
|
|
|
|
|
bool WasHit() const { return x4c_hit; }
|
|
|
|
void SetHit(bool h) { x4c_hit = h; }
|
|
|
|
const CNode& GetLeft() const { return *x40_left; }
|
|
|
|
const CNode& GetRight() const { return *x44_right; }
|
|
|
|
const CLeafData& GetLeafData() const { return *x48_leaf; }
|
|
|
|
const zeus::COBBox& GetOBB() const { return x0_obb; }
|
|
|
|
size_t GetMemoryUsage() const;
|
|
|
|
bool IsLeaf() const { return x3c_isLeaf; }
|
|
|
|
};
|
2016-04-26 10:40:56 +00:00
|
|
|
|
|
|
|
private:
|
2018-12-08 05:30:43 +00:00
|
|
|
u32 x0_magic = 0;
|
|
|
|
u32 x4_version = 0;
|
|
|
|
u32 x8_memsize = 0;
|
|
|
|
/* CSimpleAllocator xc_ We're not using this but lets keep track*/
|
|
|
|
SIndexData x18_indexData;
|
|
|
|
std::unique_ptr<CNode> x88_root;
|
2016-04-26 10:40:56 +00:00
|
|
|
|
|
|
|
public:
|
2018-12-08 05:30:43 +00:00
|
|
|
COBBTree() = default;
|
|
|
|
COBBTree(CInputStream&);
|
2016-04-27 02:41:00 +00:00
|
|
|
|
2019-01-05 03:28:02 +00:00
|
|
|
static std::unique_ptr<COBBTree> BuildOrientedBoundingBoxTree(const zeus::CVector3f&,
|
|
|
|
const zeus::CVector3f&);
|
2018-12-08 05:30:43 +00:00
|
|
|
CCollisionSurface GetSurface(u16 idx) const;
|
|
|
|
const u16* GetTriangleEdgeIndices(u16 idx) const { return &x18_indexData.x50_surfaceIndices[idx * 3]; }
|
|
|
|
void GetTriangleVertexIndices(u16 idx, u16 indicesOut[3]) const;
|
|
|
|
const CCollisionEdge& GetEdge(int idx) const { return x18_indexData.x40_edges[idx]; }
|
|
|
|
const zeus::CVector3f& GetVert(int idx) const { return x18_indexData.x60_vertices[idx]; }
|
|
|
|
u32 GetVertMaterial(u16 idx) const { return x18_indexData.x0_materials[x18_indexData.x10_vertMaterials[idx]]; }
|
|
|
|
u32 GetEdgeMaterial(u16 idx) const { return x18_indexData.x0_materials[x18_indexData.x20_edgeMaterials[idx]]; }
|
|
|
|
CCollisionSurface GetTransformedSurface(u16 idx, const zeus::CTransform& xf) const;
|
|
|
|
zeus::CAABox CalculateLocalAABox() const;
|
|
|
|
zeus::CAABox CalculateAABox(const zeus::CTransform&) const;
|
|
|
|
const CNode& GetRoot() const { return *x88_root; }
|
2016-04-26 10:40:56 +00:00
|
|
|
};
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|