#ifndef NAVMESHDEBUG_H #define NAVMESHDEBUG_H #include "NavMesh.h" #include #include #include #include #include namespace NM { /** * debug plot NavMeshes */ class NavMeshDebug { public: template static void show(NavMesh& nm) { K::GnuplotFill gFill[3] = { K::GnuplotFill(K::GnuplotFillStyle::SOLID, K::GnuplotColor::fromHexStr("#111111"), 1), K::GnuplotFill(K::GnuplotFillStyle::SOLID, K::GnuplotColor::fromHexStr("#aaaaaa"), 1), K::GnuplotFill(K::GnuplotFillStyle::SOLID, K::GnuplotColor::fromHexStr("#aaaaff"), 1) }; K::GnuplotStroke gStroke = K::GnuplotStroke(K::GnuplotDashtype::SOLID, 1, K::GnuplotColor::fromHexStr("#666600")); K::Gnuplot gp; gp << "set view equal xy\n"; K::GnuplotSplot plot; K::GnuplotSplotElementLines lines; plot.add(&lines); lines.setShowPoints(true); K::GnuplotSplotElementPoints points; plot.add(&points); const BBox3 bbox = nm.getBBox(); points.add(K::GnuplotPoint3(bbox.getMin().x,bbox.getMin().y,bbox.getMin().z)); points.add(K::GnuplotPoint3(bbox.getMax().x,bbox.getMax().y,bbox.getMax().z)); // lines.add(K::GnuplotPoint3(bbox.getMin().x,bbox.getMin().y,bbox.getMin().z), K::GnuplotPoint3(bbox.getMax().x, 0, 0)); // lines.add(K::GnuplotPoint3(bbox.getMin().x,bbox.getMin().y,bbox.getMin().z), K::GnuplotPoint3(0,bbox.getMax().y,0)); // lines.addSegment(K::GnuplotPoint3(bbox.getMin().x,bbox.getMin().y,bbox.getMin().z), K::GnuplotPoint3(0,0,bbox.getMax().z)); //stairs in eigene group? vlt gehen dann auch die dellen weg? for (const Tria* tria : nm) { const uint8_t type = tria->getType(); if (type < 0 || type > 2) { throw std::runtime_error("out of type-bounds"); } K::GnuplotObjectPolygon* pol = new K::GnuplotObjectPolygon(gFill[type], gStroke); pol->add(K::GnuplotCoordinate3(tria->getP1().x, tria->getP1().y, tria->getP1().z, K::GnuplotCoordinateSystem::FIRST)); pol->add(K::GnuplotCoordinate3(tria->getP2().x, tria->getP2().y, tria->getP2().z, K::GnuplotCoordinateSystem::FIRST)); pol->add(K::GnuplotCoordinate3(tria->getP3().x, tria->getP3().y, tria->getP3().z, K::GnuplotCoordinateSystem::FIRST)); pol->close(); pol->setZIndex(tria->getP3().z); plot.getObjects().add(pol); //for (int i = 0; i < nm.getNumNeighbors(tria); ++i) { // const Tria* o = nm.getNeighbor(tria, i); // const Point3 p1 = tria->getCenter(); // const Point3 p2 = o.getCenter(); // //lines.addSegment(K::GnuplotPoint3(p1.x,p1.y,p1.z+0.1), K::GnuplotPoint3(p2.x,p2.y,p2.z+0.1)); //} for (const NavMeshTriangle* o : *tria) { const Point3 p1 = tria->getCenter(); const Point3 p2 = o->getCenter(); // lines.addSegment(K::GnuplotPoint3(p1.x,p1.y,p1.z+0.1), K::GnuplotPoint3(p2.x,p2.y,p2.z+0.1)); } } plot.getObjects().reOrderByZIndex(); gp.draw(plot); gp.flush(); sleep(1); } }; } #endif // NAVMESHDEBUG_H