1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-24 09:39:51 +00:00

Remove a squareroot in pathfinding

This commit is contained in:
scrawl 2014-06-14 20:05:23 +02:00
parent afbd5162ee
commit 8d8015ce18

View File

@ -90,12 +90,12 @@ namespace
namespace MWMechanics namespace MWMechanics
{ {
float distanceZCorrected(ESM::Pathgrid::Point point, float x, float y, float z) float sqrDistanceZCorrected(ESM::Pathgrid::Point point, float x, float y, float z)
{ {
x -= point.mX; x -= point.mX;
y -= point.mY; y -= point.mY;
z -= point.mZ; z -= point.mZ;
return sqrt(x * x + y * y + 0.1 * z * z); return (x * x + y * y + 0.1 * z * z);
} }
float distance(ESM::Pathgrid::Point point, float x, float y, float z) float distance(ESM::Pathgrid::Point point, float x, float y, float z)
@ -296,7 +296,7 @@ namespace MWMechanics
return true; return true;
ESM::Pathgrid::Point nextPoint = *mPath.begin(); ESM::Pathgrid::Point nextPoint = *mPath.begin();
if(distanceZCorrected(nextPoint, x, y, z) < 64) if(sqrDistanceZCorrected(nextPoint, x, y, z) < 64*64)
{ {
mPath.pop_front(); mPath.pop_front();
if(mPath.empty()) mIsPathConstructed = false; if(mPath.empty()) mIsPathConstructed = false;
@ -311,7 +311,7 @@ namespace MWMechanics
return true; return true;
ESM::Pathgrid::Point nextPoint = *mPath.begin(); ESM::Pathgrid::Point nextPoint = *mPath.begin();
if(distanceZCorrected(nextPoint, x, y, z) < 64) if(sqrDistanceZCorrected(nextPoint, x, y, z) < 64*64)
{ {
mPath.pop_front(); mPath.pop_front();
if(mPath.empty()) if(mPath.empty())