worked on grid-generation added helper library for nav-meshes started working on nav meshes
76 lines
2.7 KiB
C++
76 lines
2.7 KiB
C++
#ifndef NAVMESHDEBUG_H
|
|
#define NAVMESHDEBUG_H
|
|
|
|
#include "NavMesh.h"
|
|
|
|
#include <KLib/misc/gnuplot/Gnuplot.h>
|
|
#include <KLib/misc/gnuplot/GnuplotSplot.h>
|
|
#include <KLib/misc/gnuplot/GnuplotSplotElementLines.h>
|
|
#include <KLib/misc/gnuplot/GnuplotSplotElementPoints.h>
|
|
#include <KLib/misc/gnuplot/objects/GnuplotObjectPolygon.h>
|
|
|
|
class NavMeshDebug {
|
|
|
|
public:
|
|
|
|
template <typename Tria> static void show(NavMesh<Tria>& 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) {
|
|
uint8_t type = tria.type;
|
|
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.p1.x, tria.p1.y, tria.p1.z, K::GnuplotCoordinateSystem::FIRST));
|
|
pol->add(K::GnuplotCoordinate3(tria.p2.x, tria.p2.y, tria.p2.z, K::GnuplotCoordinateSystem::FIRST));
|
|
pol->add(K::GnuplotCoordinate3(tria.p3.x, tria.p3.y, tria.p3.z, K::GnuplotCoordinateSystem::FIRST));
|
|
pol->close();
|
|
pol->setZIndex(tria.p3.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));
|
|
}
|
|
|
|
}
|
|
|
|
plot.getObjects().reOrderByZIndex();
|
|
|
|
gp.draw(plot);
|
|
gp.flush();
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif // NAVMESHDEBUG_H
|