mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2024-12-29 03:19:44 +00:00
Clamp tile position
This commit is contained in:
parent
783411fa1f
commit
1a52a2a029
@ -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…
Reference in New Issue
Block a user