Clamp tile position

C++20
elsid 3 years ago
parent 783411fa1f
commit 1a52a2a029
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -50,12 +50,24 @@ namespace DetourNavigator
return static_cast<float>(settings.mTileSize) * settings.mCellSize;
}
inline int getTilePosition(const RecastSettings& settings, float position)
{
const float v = std::floor(position / getTileSize(settings));
if (v < static_cast<float>(std::numeric_limits<int>::min()))
return std::numeric_limits<int>::min();
if (v > static_cast<float>(std::numeric_limits<int>::max() - 1))
return std::numeric_limits<int>::max() - 1;
return static_cast<int>(v);
}
inline TilePosition getTilePosition(const RecastSettings& settings, const osg::Vec2f& position)
{
return TilePosition(getTilePosition(settings, position.x()), getTilePosition(settings, position.y()));
}
inline TilePosition getTilePosition(const RecastSettings& settings, const osg::Vec3f& position)
{
return TilePosition(
static_cast<int>(std::floor(position.x() / getTileSize(settings))),
static_cast<int>(std::floor(position.z() / getTileSize(settings)))
);
return getTilePosition(settings, osg::Vec2f(position.x(), position.z()));
}
inline TileBounds makeTileBounds(const RecastSettings& settings, const TilePosition& tilePosition)

Loading…
Cancel
Save