1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-28 20:36:42 +00:00

Check is path completed by osg::Vec3f position

This commit is contained in:
elsid 2018-08-18 14:01:02 +03:00
parent 2c6daa74a9
commit 6d89241178
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
4 changed files with 14 additions and 9 deletions

View file

@ -171,7 +171,7 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, const osg::Vec3f&
mTimer = 0; 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 // turn to destination point
zTurn(actor, getZAngleToPoint(start, dest)); zTurn(actor, getZAngleToPoint(start, dest));

View file

@ -249,7 +249,9 @@ namespace MWMechanics
setPathToAnAllowedNode(actor, storage, pos); 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); completeManualWalking(actor, storage);
} }

View file

@ -55,11 +55,14 @@ namespace
(closestReachableIndex, closestReachableIndex == closestIndex); (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(); return (lhs - rhs).length2();
y -= point.y(); }
return (x * x + y * y);
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); 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(); mPath.pop_front();
return mPath.empty(); return mPath.empty();

View file

@ -63,7 +63,7 @@ namespace MWMechanics
void buildPath(const osg::Vec3f& startPoint, const osg::Vec3f& endPoint, void buildPath(const osg::Vec3f& startPoint, const osg::Vec3f& endPoint,
const MWWorld::CellStore* cell, const PathgridGraph& pathgridGraph); 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. ///< \Returns true if we are within \a tolerance units of the last path point.
/// In radians /// In radians