载入中...
搜索中...
未找到
SpatialHash3D.h
浏览该文件的文档.
1#pragma once
2
3#include "spatial/Bounds.h"
4#include "spatial/QueryIds.h"
5
6#include <unordered_map>
7#include <unordered_set>
8#include <vector>
9
10namespace eve::spatial {
11
14public:
15 explicit SpatialHash3D(float cellSize = 64.f);
16 ~SpatialHash3D() = default;
17
18 SpatialHash3D(const SpatialHash3D &) = delete;
20
21 void clear();
22 void setCellSize(float cellSize);
23 float getCellSize() const { return cellSize_; }
24
25 bool insert(int id, float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
26 bool remove(int id);
27 bool update(int id, float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
28 bool contains(int id) const;
29 int getCount() const { return static_cast<int>(items_.size()); }
30
31 int queryPoint(float x, float y, float z);
32 int queryAABB(float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
33 int querySphere(float cx, float cy, float cz, float radius);
34
35 int getResultCount() const { return results_.getCount(); }
36 int getResultId(int index) const { return results_.getId(index); }
37
38private:
39 void cellRange(const AABB3 &b, int &minCX, int &minCY, int &minCZ, int &maxCX, int &maxCY,
40 int &maxCZ) const;
41 void insertCells(int id, const AABB3 &b);
42 void eraseCells(int id, const AABB3 &b);
43 void queryCells(int minCX, int minCY, int minCZ, int maxCX, int maxCY, int maxCZ,
44 const AABB3 *box, float cx, float cy, float cz, float radius, bool useSphere,
45 bool usePoint);
46
47 float cellSize_ = 64.f;
48 std::unordered_map<int, AABB3> items_;
49 std::unordered_map<uint64_t, std::vector<int>> cells_;
50 QueryIds results_;
51};
52
53} // namespace eve::spatial
float cx
Definition CardTypes.cpp:31
float cy
Definition CardTypes.cpp:32
int y
Definition Grass.cpp:135
int z
Definition Grass.cpp:135
int x
Definition Grass.cpp:135
uint32_t b
Last-query hit buffer shared by spatial indexes. Script pattern: call query* → getResultCount / getRe...
Definition QueryIds.h:11
int getId(int index) const
Definition QueryIds.h:26
int getCount() const
Definition QueryIds.h:24
Uniform-grid spatial hash for 3D AABB / sphere queries.
SpatialHash3D & operator=(const SpatialHash3D &)=delete
bool insert(int id, float minX, float minY, float minZ, float maxX, float maxY, float maxZ)
int querySphere(float cx, float cy, float cz, float radius)
SpatialHash3D(const SpatialHash3D &)=delete
void setCellSize(float cellSize)
bool update(int id, float minX, float minY, float minZ, float maxX, float maxY, float maxZ)
int getResultId(int index) const
bool contains(int id) const
int queryAABB(float minX, float minY, float minZ, float maxX, float maxY, float maxZ)
int queryPoint(float x, float y, float z)