added forbidden zones
This commit is contained in:
1 parent
b633aa01f5
commit
77827af150
5 files changed
+84
-1
No files matched your search
@@ -246,6 +246,7 @@ void PathFinder::loadConfig(const std::string& configPath, const std::string& zi
|
||||
NavigationArea area;
|
||||
area.name = item.value("name", "");
|
||||
area.available = item.value("available", true);
|
||||
area.forbidden = item.value("forbidden", false);
|
||||
area.polygon = readPolygon(item);
|
||||
|
||||
if (area.name.empty()) {
|
||||
@@ -314,10 +315,44 @@ void PathFinder::resetGridBounds()
|
||||
gridDepth = static_cast<int>(std::ceil((maxZ - minZ) / cellSize));
|
||||
}
|
||||
|
||||
void PathFinder::rebuildWalkableGrid()
|
||||
/*void PathFinder::rebuildWalkableGrid()
|
||||
{
|
||||
walkable.assign(static_cast<size_t>(gridWidth * gridDepth), 0);
|
||||
markAvailableAreasWalkable();
|
||||
markObstacleMeshesBlocked();
|
||||
}*/
|
||||
void PathFinder::rebuildWalkableGrid()
|
||||
{
|
||||
walkable.assign(static_cast<size_t>(gridWidth * gridDepth), 0);
|
||||
|
||||
for (const NavigationArea& area : areas) {
|
||||
if (area.available && !area.forbidden) {
|
||||
for (int z = 0; z < gridDepth; ++z) {
|
||||
for (int x = 0; x < gridWidth; ++x) {
|
||||
const Cell cell{ x, z };
|
||||
const Eigen::Vector3f center = cellCenter(cell);
|
||||
if (pointInPolygon(center.x(), center.z(), area.polygon)) {
|
||||
walkable[static_cast<size_t>(indexOf(cell))] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const NavigationArea& area : areas) {
|
||||
if (area.forbidden) {
|
||||
for (int z = 0; z < gridDepth; ++z) {
|
||||
for (int x = 0; x < gridWidth; ++x) {
|
||||
const Cell cell{ x, z };
|
||||
const Eigen::Vector3f center = cellCenter(cell);
|
||||
if (pointInPolygon(center.x(), center.z(), area.polygon)) {
|
||||
walkable[static_cast<size_t>(indexOf(cell))] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
markObstacleMeshesBlocked();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ public:
|
||||
struct NavigationArea {
|
||||
std::string name;
|
||||
bool available = true;
|
||||
bool forbidden = false;
|
||||
std::vector<Eigen::Vector2f> polygon;
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user