mirror of
https://github.com/TES3MP/TES3MP.git
synced 2025-09-30 08:35:52 -04:00
Pathfinding Overhaul - More cleanup.
This commit is contained in:
parent
4838678944
commit
96fdaf7410
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
//helpers functions
|
// helpers functions
|
||||||
float distanceZCorrected(ESM::Pathgrid::Point point,float x,float y,float z)
|
float distanceZCorrected(ESM::Pathgrid::Point point,float x,float y,float z)
|
||||||
{
|
{
|
||||||
return sqrt((point.mX - x) * (point.mX - x) + (point.mY - y) * (point.mY - y) + 0.1 * (point.mZ - z) * (point.mZ - z));
|
return sqrt((point.mX - x) * (point.mX - x) + (point.mY - y) * (point.mY - y) + 0.1 * (point.mZ - z) * (point.mZ - z));
|
||||||
@ -28,8 +28,10 @@ namespace
|
|||||||
|
|
||||||
static float sgn(float a)
|
static float sgn(float a)
|
||||||
{
|
{
|
||||||
if(a > 0) return 1.0;
|
if(a > 0)
|
||||||
else return -1.0;
|
return 1.0;
|
||||||
|
else
|
||||||
|
return -1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getClosestPoint(const ESM::Pathgrid* grid,float x,float y,float z)
|
int getClosestPoint(const ESM::Pathgrid* grid,float x,float y,float z)
|
||||||
@ -95,19 +97,20 @@ const PathGridGraph & mGraph;
|
|||||||
PointID mGoal;
|
PointID mGoal;
|
||||||
};*/
|
};*/
|
||||||
|
|
||||||
class goalVisited : public boost::default_dijkstra_visitor
|
class goalVisited : public boost::default_dijkstra_visitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
goalVisited(PointID goal) : mGoal(goal) {}
|
goalVisited(PointID goal) : mGoal(goal) {}
|
||||||
|
|
||||||
void examine_vertex(PointID u, const PathGridGraph g)
|
void examine_vertex(PointID u, const PathGridGraph g)
|
||||||
{
|
{
|
||||||
if(u == mGoal)
|
if(u == mGoal)
|
||||||
throw found_path();
|
throw found_path();
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
PointID mGoal;
|
private:
|
||||||
};
|
PointID mGoal;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
PathGridGraph buildGraph(const ESM::Pathgrid* pathgrid,float xCell = 0,float yCell = 0)
|
PathGridGraph buildGraph(const ESM::Pathgrid* pathgrid,float xCell = 0,float yCell = 0)
|
||||||
@ -206,8 +209,8 @@ namespace MWMechanics
|
|||||||
ESM::Pathgrid::Point nextPoint = *mPath.begin();
|
ESM::Pathgrid::Point nextPoint = *mPath.begin();
|
||||||
float dX = nextPoint.mX - x;
|
float dX = nextPoint.mX - x;
|
||||||
float dY = nextPoint.mY - y;
|
float dY = nextPoint.mY - y;
|
||||||
float h = sqrt(dX*dX+dY*dY);
|
float h = sqrt(dX * dX + dY * dY);
|
||||||
return Ogre::Radian(acos(dY/h)*sgn(asin(dX/h))).valueDegrees();
|
return Ogre::Radian(acos(dY / h) * sgn(asin(dX / h))).valueDegrees();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PathFinder::checkIfNextPointReached(float x,float y,float z)
|
bool PathFinder::checkIfNextPointReached(float x,float y,float z)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user