added dijkstra support to navmesh
This commit is contained in:
@@ -29,6 +29,7 @@ namespace NM {
|
||||
K::GnuplotSplotElementColorPoints particles;
|
||||
K::GnuplotSplotElementLines pathEstimated;
|
||||
K::GnuplotSplotElementColorPoints distances;
|
||||
K::GnuplotSplotElementLines shortestPath;
|
||||
|
||||
private:
|
||||
|
||||
@@ -50,6 +51,7 @@ namespace NM {
|
||||
plot.add(&particles); particles.setPointType(7); particles.setPointSize(0.2);
|
||||
plot.add(&pathEstimated); pathEstimated.getStroke().setWidth(2); pathEstimated.setShowPoints(false); pathEstimated.getStroke().getColor().setHexStr("#00ff00");
|
||||
plot.add(&distances); distances.setPointSize(2); distances.setPointType(7);
|
||||
plot.add(&shortestPath); shortestPath.getStroke().setWidth(3);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
@@ -118,6 +120,8 @@ namespace NM {
|
||||
|
||||
template <typename Tria> void addDijkstra(NavMesh<Tria>& mesh) {
|
||||
|
||||
distances.clear();
|
||||
|
||||
// ensure Tria extends NavMeshTriangleDijkstra
|
||||
StaticAssert::AinheritsB<Tria, NavMeshTriangleDijkstra>();
|
||||
|
||||
@@ -125,7 +129,7 @@ namespace NM {
|
||||
|
||||
for (int i = 0; i < 900; ++i) {
|
||||
NavMeshLocation<Tria> loc = rnd.draw();
|
||||
float v = loc.tria->interpolate(loc.pos, loc.tria->distAtP1, loc.tria->distAtP2, loc.tria->distAtP3);
|
||||
float v = loc.tria->interpolate(loc.pos, loc.tria->spFromP1.distance, loc.tria->spFromP2.distance, loc.tria->spFromP3.distance);
|
||||
distances.add(K::GnuplotPoint3(loc.pos.x, loc.pos.y, loc.pos.z), v);
|
||||
}
|
||||
|
||||
@@ -144,6 +148,16 @@ namespace NM {
|
||||
|
||||
}
|
||||
|
||||
template <typename Tria> void addDijkstra(std::vector<NM::NavMeshLocation<Tria>>& path) {
|
||||
shortestPath.clear();
|
||||
for (auto& e : path) {
|
||||
K::GnuplotPoint3 gp(e.pos.x, e.pos.y, e.pos.z);
|
||||
shortestPath.add(gp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void setGT(const Point3 pt) {
|
||||
gp << "set arrow 31337 from " << pt.x << "," << pt.y << "," << (pt.z+1.4) << " to " << pt.x << "," << pt.y << "," << pt.z << " front \n";
|
||||
|
||||
Reference in New Issue
Block a user