9#include <unordered_map>
21 Octree(
float minX,
float minY,
float minZ,
float maxX,
float maxY,
float maxZ,
22 int maxDepth = 8,
int maxPerNode = 8);
32 bool insert(
int id,
float minX,
float minY,
float minZ,
float maxX,
float maxY,
float maxZ);
36 bool update(
int id,
float minX,
float minY,
float minZ,
float maxX,
float maxY,
float maxZ);
38 bool contains(
int id)
const;
40 int getCount()
const {
return static_cast<int>(items_.size()); }
43 int queryPoint(
float x,
float y,
float z);
45 int queryAABB(
float minX,
float minY,
float minZ,
float maxX,
float maxY,
float maxZ);
47 int querySphere(
float cx,
float cy,
float cz,
float radius);
55 float getMinX()
const {
return rootBounds_.minX; }
57 float getMinY()
const {
return rootBounds_.minY; }
59 float getMinZ()
const {
return rootBounds_.minZ; }
61 float getMaxX()
const {
return rootBounds_.maxX; }
63 float getMaxY()
const {
return rootBounds_.maxY; }
65 float getMaxZ()
const {
return rootBounds_.maxZ; }
75 std::vector<int> itemIds;
77 bool isLeaf()
const {
return children[0] ==
nullptr; }
81 bool insertInto(Node &
node,
int id,
const AABB3 &
bounds);
83 void collect(Node &
node,
const AABB3 *box,
float cx,
float cy,
float cz,
float radius,
90 std::unique_ptr<Node> root_;
91 std::unordered_map<int, AABB3> items_;
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Region octree for 3D AABB broad-phase / scene culling. Same storage rules as QuadTree (smallest fully...
Octree(const Octree &)=delete
float getMaxZ() const
Root/world maximum Z.
int getMaxPerNode() const
Item capacity before a node splits.
float getMinZ() const
Root/world minimum Z.
float getMinX() const
Root/world minimum X.
float getMaxY() const
Root/world maximum Y.
Octree & operator=(const Octree &)=delete
int getResultCount() const
Number of hits from the last query*.
int getMaxDepth() const
Maximum subdivision depth.
float getMaxX() const
Root/world maximum X.
int getResultId(int index) const
Hit id at dense index from the last query*, or -1.
float getMinY() const
Root/world minimum Y.
int getCount() const
Number of stored ids.
~Octree()=default
Releases tree nodes.
Axis-aligned 3D bounding box (min/max inclusive).