diff --git a/Runtime/Collision/COBBTree.cpp b/Runtime/Collision/COBBTree.cpp index 89d8bf84e..74fa030dc 100644 --- a/Runtime/Collision/COBBTree.cpp +++ b/Runtime/Collision/COBBTree.cpp @@ -1,13 +1,52 @@ #include "Runtime/Collision/COBBTree.hpp" +#include + #include "Runtime/Collision/CCollidableOBBTreeGroup.hpp" namespace urde { +namespace { +constexpr std::array DefaultEdgeMaterials{ + 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 2, 0, 0, 2, 2, +}; + +constexpr std::array DefaultSurfaceMaterials{ + 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, +}; + +const std::array DefaultEdges{{ + {4, 1}, + {1, 5}, + {5, 4}, + {4, 0}, + {0, 1}, + {7, 2}, + {2, 6}, + {6, 7}, + {7, 3}, + {3, 2}, + {6, 0}, + {4, 6}, + {2, 0}, + {5, 3}, + {7, 5}, + {1, 3}, + {6, 5}, + {0, 3}, +}}; + +constexpr std::array DefaultSurfaceIndices{ + 0, 1, 2, 0, 3, 4, 5, 6, 7, 5, 8, 9, 10, 3, 11, 10, 6, 12, + 13, 8, 14, 13, 1, 15, 16, 14, 7, 16, 11, 2, 17, 15, 4, 17, 12, 9, +}; + + /* This is exactly what retro did >.< */ u32 verify_deaf_babe(CInputStream& in) { return in.readUint32Big(); } /* This is exactly what retro did >.< */ u32 verify_version(CInputStream& in) { return in.readUint32Big(); } +} // Anonymous namespace COBBTree::COBBTree(CInputStream& in) : x0_magic(verify_deaf_babe(in)) @@ -16,24 +55,6 @@ COBBTree::COBBTree(CInputStream& in) , x18_indexData(in) , x88_root(std::make_unique(in)) {} -static const u8 DefaultEdgeMaterials[] = { - 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 2, 0, 0, 2, 2 -}; - -static const u8 DefaultSurfaceMaterials[] = { - 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 -}; - -static const CCollisionEdge DefaultEdges[] = { - {4, 1}, {1, 5}, {5, 4}, {4, 0}, {0, 1}, {7, 2}, {2, 6}, {6, 7}, {7, 3}, - {3, 2}, {6, 0}, {4, 6}, {2, 0}, {5, 3}, {7, 5}, {1, 3}, {6, 5}, {0, 3} -}; - -static const u16 DefaultSurfaceIndices[] = { - 0, 1, 2, 0, 3, 4, 5, 6, 7, 5, 8, 9, 10, 3, 11, 10, 6, 12, 13, - 8, 14, 13, 1, 15, 16, 14, 7, 16, 11, 2, 17, 15, 4, 17, 12, 9 -}; - std::unique_ptr COBBTree::BuildOrientedBoundingBoxTree(const zeus::CVector3f& extent, const zeus::CVector3f& center) { zeus::CAABox aabb(extent * -0.5f + center, extent * 0.5f + center); @@ -44,10 +65,10 @@ std::unique_ptr COBBTree::BuildOrientedBoundingBoxTree(const zeus::CVe idxData.x0_materials.push_back(0x42180000); idxData.x0_materials.push_back(0x41180000); idxData.x10_vertMaterials = std::vector(8, u8(0)); - idxData.x20_edgeMaterials = std::vector(std::begin(DefaultEdgeMaterials), std::end(DefaultEdgeMaterials)); - idxData.x30_surfaceMaterials = std::vector(std::begin(DefaultSurfaceMaterials), std::end(DefaultSurfaceMaterials)); - idxData.x40_edges = std::vector(std::begin(DefaultEdges), std::end(DefaultEdges)); - idxData.x50_surfaceIndices = std::vector(std::begin(DefaultSurfaceIndices), std::end(DefaultSurfaceIndices)); + idxData.x20_edgeMaterials = std::vector(DefaultEdgeMaterials.cbegin(), DefaultEdgeMaterials.cend()); + idxData.x30_surfaceMaterials = std::vector(DefaultSurfaceMaterials.cbegin(), DefaultSurfaceMaterials.cend()); + idxData.x40_edges = std::vector(DefaultEdges.cbegin(), DefaultEdges.cend()); + idxData.x50_surfaceIndices = std::vector(DefaultSurfaceIndices.cbegin(), DefaultSurfaceIndices.cend()); idxData.x60_vertices.reserve(8); for (int i = 0; i < 8; ++i) idxData.x60_vertices.push_back(aabb.getPoint(i));