added forbidden zones
This commit is contained in:
parent
b633aa01f5
commit
77827af150
@ -113,6 +113,17 @@
|
||||
[1, -5.5],
|
||||
[-0.2, -5.5]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "main_corridor",
|
||||
"available": true,
|
||||
"forbidden": true,
|
||||
"polygon": [
|
||||
[-15, 15],
|
||||
[15, 15],
|
||||
[15, 2.2],
|
||||
[-15, 2.2]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -400,6 +400,7 @@ void Location::setup()
|
||||
}
|
||||
//#ifdef SHOW_PATH
|
||||
buildDebugNavMeshes();
|
||||
buildDebugForbiddenMeshes();
|
||||
//#endif
|
||||
|
||||
auto planner = [this](const Eigen::Vector3f& start, const Eigen::Vector3f& end) {
|
||||
@ -444,6 +445,35 @@ void Location::setup()
|
||||
renderer.shaderManager.PopShader();
|
||||
renderer.SetMatrix();
|
||||
}
|
||||
|
||||
void Location::buildDebugForbiddenMeshes()
|
||||
{
|
||||
debugForbiddenMeshes.clear();
|
||||
const auto& areas = navigation.getAreas();
|
||||
float y = navigation.getFloorY() + 0.2f;
|
||||
Eigen::Vector3f blue(0.0f, 0.0f, 1.0f);
|
||||
|
||||
for (const auto& area : areas) {
|
||||
if (area.forbidden && area.polygon.size() >= 3) {
|
||||
VertexRenderStruct mesh;
|
||||
mesh.data = CreatePolygonFloor(area.polygon, y, blue);
|
||||
mesh.RefreshVBO();
|
||||
debugForbiddenMeshes.push_back(std::move(mesh));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Location::drawDebugForbidden()
|
||||
{
|
||||
if (debugForbiddenMeshes.empty()) return;
|
||||
renderer.shaderManager.PushShader("defaultColor");
|
||||
renderer.SetMatrix();
|
||||
for (const auto& mesh : debugForbiddenMeshes) {
|
||||
renderer.DrawVertexRenderStruct(mesh);
|
||||
}
|
||||
renderer.shaderManager.PopShader();
|
||||
renderer.SetMatrix();
|
||||
}
|
||||
//#endif
|
||||
|
||||
|
||||
@ -609,6 +639,7 @@ void Location::setup()
|
||||
|
||||
//#ifdef SHOW_PATH
|
||||
drawDebugNavigation();
|
||||
drawDebugForbidden();
|
||||
//#endif
|
||||
|
||||
renderer.PopMatrix();
|
||||
@ -785,6 +816,7 @@ void Location::setup()
|
||||
CheckGlError(__FILE__, __LINE__);
|
||||
|
||||
drawDebugNavigation();
|
||||
drawDebugForbidden();
|
||||
|
||||
renderer.PopMatrix();
|
||||
renderer.PopProjectionMatrix();
|
||||
|
||||
@ -72,6 +72,10 @@ namespace ZL
|
||||
std::vector<VertexRenderStruct> debugNavMeshes;
|
||||
void buildDebugNavMeshes();
|
||||
void drawDebugNavigation();
|
||||
|
||||
std::vector<VertexRenderStruct> debugForbiddenMeshes;
|
||||
void buildDebugForbiddenMeshes();
|
||||
void drawDebugForbidden();
|
||||
//#endif
|
||||
bool rightMouseDown = false;
|
||||
int lastMouseX = 0;
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user