added dijkstra support to navmesh
This commit is contained in:
@@ -90,7 +90,6 @@ TEST(NavMeshDijkstra, build2) {
|
||||
|
||||
|
||||
|
||||
|
||||
NavMeshFactory<MyNMT1231902345> fac(&nm, set);
|
||||
fac.build(map);
|
||||
|
||||
@@ -107,5 +106,76 @@ TEST(NavMeshDijkstra, build2) {
|
||||
|
||||
}
|
||||
|
||||
TEST(NavMeshDijkstra, path) {
|
||||
|
||||
NavMeshSettings set;
|
||||
NavMesh<MyNMT1231902345> nm;
|
||||
|
||||
// Floorplan::IndoorMap map;
|
||||
// Floorplan::Floor floor; map.floors.push_back(&floor); floor.atHeight = 0; floor.height = 3;
|
||||
// Floorplan::FloorOutlinePolygon outline; floor.outline.push_back(&outline);
|
||||
|
||||
// // circle (many triangles)
|
||||
// int i = 0;
|
||||
// for (float f = 0; f < M_PI*2; f += 0.8) {
|
||||
// const float x = std::cos(f) * 10;
|
||||
// const float y = std::sin(f) * 10;
|
||||
// outline.poly.points.push_back(Point2(x,y));
|
||||
// ++i;
|
||||
// }
|
||||
|
||||
// outline.outdoor = false;
|
||||
// outline.method = Floorplan::OutlineMethod::ADD;
|
||||
|
||||
// Floorplan::FloorOutlinePolygon remove; floor.outline.push_back(&remove);
|
||||
// remove.outdoor = false;
|
||||
// remove.method = Floorplan::OutlineMethod::REMOVE;
|
||||
// remove.poly.points.push_back(Point2(+4,-3));
|
||||
// remove.poly.points.push_back(Point2(+11,-3));
|
||||
// remove.poly.points.push_back(Point2(+11,+1));
|
||||
// remove.poly.points.push_back(Point2(+4,+1));
|
||||
|
||||
// Floorplan::FloorOutlinePolygon remove2; floor.outline.push_back(&remove2);
|
||||
// remove2.outdoor = false;
|
||||
// remove2.method = Floorplan::OutlineMethod::REMOVE;
|
||||
// remove2.poly.points.push_back(Point2(-11,-2));
|
||||
// remove2.poly.points.push_back(Point2(-2,-2));
|
||||
// remove2.poly.points.push_back(Point2(-2,+2));
|
||||
// remove2.poly.points.push_back(Point2(-11,+2));
|
||||
|
||||
Floorplan::IndoorMap* map = Floorplan::Reader::readFromFile("/mnt/vm/paper/diss/data/maps/map_stair1.xml");
|
||||
|
||||
|
||||
NavMeshFactory<MyNMT1231902345> fac(&nm, set);
|
||||
fac.build(map);
|
||||
|
||||
|
||||
NavMeshDebug dbg;
|
||||
dbg.addMesh(nm);
|
||||
dbg.draw();
|
||||
|
||||
NM::NavMeshRandom<MyNMT1231902345> rnd = nm.getRandom();
|
||||
const Point3 dst = rnd.draw().pos;
|
||||
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
|
||||
|
||||
NM::NavMeshLocation<MyNMT1231902345> start = rnd.draw();
|
||||
|
||||
NM::NavMeshDijkstra::stamp(nm, dst);
|
||||
|
||||
//NM::NavMeshLocation<MyNMT1231902345> start = start;//nm.getLocation(Point3(0,-6,0));
|
||||
std::vector<NM::NavMeshLocation<MyNMT1231902345>> path = start.tria->getPathToDestination<MyNMT1231902345>(start.pos);
|
||||
std::cout << path.size() << std::endl;
|
||||
|
||||
dbg.addDijkstra(nm);
|
||||
dbg.addDijkstra(path);
|
||||
dbg.draw();
|
||||
|
||||
sleep(1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user