mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-04 03:40:14 +00:00
Check is path completed by osg::Vec3f position
This commit is contained in:
parent
2c6daa74a9
commit
6d89241178
@ -171,7 +171,7 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, const osg::Vec3f&
|
||||
mTimer = 0;
|
||||
}
|
||||
|
||||
if (isDestReached || mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1])) // if path is finished
|
||||
if (isDestReached || mPathFinder.checkPathCompleted(pos.asVec3())) // if path is finished
|
||||
{
|
||||
// turn to destination point
|
||||
zTurn(actor, getZAngleToPoint(start, dest));
|
||||
|
@ -249,7 +249,9 @@ namespace MWMechanics
|
||||
setPathToAnAllowedNode(actor, storage, pos);
|
||||
}
|
||||
}
|
||||
} else if (storage.mIsWanderingManually && mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1], DESTINATION_TOLERANCE)) {
|
||||
}
|
||||
else if (storage.mIsWanderingManually && mPathFinder.checkPathCompleted(pos.asVec3(), DESTINATION_TOLERANCE))
|
||||
{
|
||||
completeManualWalking(actor, storage);
|
||||
}
|
||||
|
||||
|
@ -55,11 +55,14 @@ namespace
|
||||
(closestReachableIndex, closestReachableIndex == closestIndex);
|
||||
}
|
||||
|
||||
float sqrDistanceIgnoreZ(const osg::Vec3f& point, float x, float y)
|
||||
float sqrDistance(const osg::Vec2f& lhs, const osg::Vec2f& rhs)
|
||||
{
|
||||
x -= point.x();
|
||||
y -= point.y();
|
||||
return (x * x + y * y);
|
||||
return (lhs - rhs).length2();
|
||||
}
|
||||
|
||||
float sqrDistanceIgnoreZ(const osg::Vec3f& lhs, const osg::Vec3f& rhs)
|
||||
{
|
||||
return sqrDistance(osg::Vec2f(lhs.x(), lhs.y()), osg::Vec2f(rhs.x(), rhs.y()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,9 +266,9 @@ namespace MWMechanics
|
||||
return getXAngleToDir(dir);
|
||||
}
|
||||
|
||||
bool PathFinder::checkPathCompleted(float x, float y, float tolerance)
|
||||
bool PathFinder::checkPathCompleted(const osg::Vec3f& position, const float tolerance)
|
||||
{
|
||||
if (!mPath.empty() && sqrDistanceIgnoreZ(mPath.front(), x, y) < tolerance*tolerance)
|
||||
if (!mPath.empty() && sqrDistanceIgnoreZ(mPath.front(), position) < tolerance*tolerance)
|
||||
mPath.pop_front();
|
||||
|
||||
return mPath.empty();
|
||||
|
@ -63,7 +63,7 @@ namespace MWMechanics
|
||||
void buildPath(const osg::Vec3f& startPoint, const osg::Vec3f& endPoint,
|
||||
const MWWorld::CellStore* cell, const PathgridGraph& pathgridGraph);
|
||||
|
||||
bool checkPathCompleted(float x, float y, float tolerance = PathTolerance);
|
||||
bool checkPathCompleted(const osg::Vec3f& position, const float tolerance = PathTolerance);
|
||||
///< \Returns true if we are within \a tolerance units of the last path point.
|
||||
|
||||
/// In radians
|
||||
|
Loading…
x
Reference in New Issue
Block a user