mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-14 15:33:26 +00:00
changed stuff
This commit is contained in:
@@ -15,7 +15,7 @@ namespace omath::pathfinding
|
|||||||
struct NavigationVertex
|
struct NavigationVertex
|
||||||
{
|
{
|
||||||
Vector3 origin;
|
Vector3 origin;
|
||||||
std::vector<Vector3*> connections;
|
std::vector<NavigationVertex*> connections;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,15 +3,15 @@
|
|||||||
//
|
//
|
||||||
#include "omath/pathfinding/Astar.h"
|
#include "omath/pathfinding/Astar.h"
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
|
||||||
namespace omath::pathfinding
|
namespace omath::pathfinding
|
||||||
{
|
{
|
||||||
struct PathNode final
|
struct PathNode final
|
||||||
{
|
{
|
||||||
PathNode* cameFrom;
|
Vector3 cameFrom;
|
||||||
const NavigationVertex* navVertex;
|
NavigationVertex const* navVertex;
|
||||||
float gCost = 0.f;
|
float gCost = 0.f;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -24,11 +24,23 @@ namespace omath::pathfinding
|
|||||||
const auto& startVertex = navMesh.GetClossestVertex(start).value();
|
const auto& startVertex = navMesh.GetClossestVertex(start).value();
|
||||||
const auto& endVertex = navMesh.GetClossestVertex(end).value();
|
const auto& endVertex = navMesh.GetClossestVertex(end).value();
|
||||||
|
|
||||||
openList.emplace(startVertex.origin, PathNode{nullptr, &startVertex, 0.f});
|
openList.emplace(startVertex.origin, PathNode{startVertex.origin, &startVertex, 0.f});
|
||||||
|
|
||||||
while (!openList.empty())
|
while (!openList.empty())
|
||||||
{
|
{
|
||||||
|
const auto [cord, node] = *std::ranges::min_element(openList,
|
||||||
|
[&endVertex](const auto& a, const auto& b) -> bool
|
||||||
|
{
|
||||||
|
const auto aCost = a.second.gCost + a.second.navVertex->origin.DistTo(endVertex.origin);
|
||||||
|
const auto bCost = b.second.gCost + b.second.navVertex->origin.DistTo(endVertex.origin);
|
||||||
|
return aCost < bCost;
|
||||||
|
});
|
||||||
|
|
||||||
|
openList.erase(cord);
|
||||||
|
|
||||||
|
for (const auto& neighbor : node.navVertex->connections)
|
||||||
|
if (!closedList.contains(neighbor->origin))
|
||||||
|
closedList.emplace(neighbor->origin, PathNode{cord, neighbor, neighbor->origin.DistTo(cord) + node.gCost});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
|||||||
Reference in New Issue
Block a user