载入中...
搜索中...
未找到
SpatialHash3D.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "spatial/Bounds.h"
6#include "spatial/QueryIds.h"
7
8#include <unordered_map>
9#include <unordered_set>
10#include <vector>
11
12namespace eve::spatial {
13
16public:
18 explicit SpatialHash3D(float cellSize = 64.f);
20 ~SpatialHash3D() = default;
21
22 SpatialHash3D(const SpatialHash3D &) = delete;
24
26 void clear();
28 void setCellSize(float cellSize);
30 float getCellSize() const { return cellSize_; }
31
33 bool insert(int id, float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
35 bool remove(int id);
37 bool update(int id, float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
39 bool contains(int id) const;
41 int getCount() const { return static_cast<int>(items_.size()); }
42
44 int queryPoint(float x, float y, float z);
46 int queryAABB(float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
48 int querySphere(float cx, float cy, float cz, float radius);
49
51 int getResultCount() const { return results_.getCount(); }
53 int getResultId(int index) const { return results_.getId(index); }
54
55private:
56 void cellRange(const AABB3 &b, int &minCX, int &minCY, int &minCZ, int &maxCX, int &maxCY,
57 int &maxCZ) const;
58 void insertCells(int id, const AABB3 &b);
59 void eraseCells(int id, const AABB3 &b);
60 void queryCells(int minCX, int minCY, int minCZ, int maxCX, int maxCY, int maxCZ,
61 const AABB3 *box, float cx, float cy, float cz, float radius, bool useSphere,
62 bool usePoint);
63
64 float cellSize_ = 64.f;
65 std::unordered_map<int, AABB3> items_;
66 std::unordered_map<uint64_t, std::vector<int>> cells_;
67 QueryIds results_;
68};
69
70} // namespace eve::spatial
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
float cx
Definition CardTypes.cpp:33
float cy
Definition CardTypes.cpp:34
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
MeleePoint3 b
Definition MeleeHit.cpp:41
float radius
uint32_t index
Last-query hit buffer shared by spatial indexes. Script pattern: call query* → getResultCount / getRe...
Definition QueryIds.h:11
Uniform-grid spatial hash for 3D AABB / sphere queries.
SpatialHash3D & operator=(const SpatialHash3D &)=delete
int getCount() const
Number of stored ids.
SpatialHash3D(const SpatialHash3D &)=delete
int getResultId(int index) const
Hit id at dense index from the last query*, or -1.
float getCellSize() const
Current uniform cell size.
~SpatialHash3D()=default
Releases hash buckets.
int getResultCount() const
Number of hits from the last query*.
Axis-aligned 3D bounding box (min/max inclusive).
Definition Bounds.h:54