mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-01 03:21:41 +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;
|
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)
|
inline TilePosition getTilePosition(const RecastSettings& settings, const osg::Vec3f& position)
|
||||||
{
|
{
|
||||||
return TilePosition(
|
return getTilePosition(settings, osg::Vec2f(position.x(), position.z()));
|
||||||
static_cast<int>(std::floor(position.x() / getTileSize(settings))),
|
|
||||||
static_cast<int>(std::floor(position.z() / getTileSize(settings)))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline TileBounds makeTileBounds(const RecastSettings& settings, const TilePosition& tilePosition)
|
inline TileBounds makeTileBounds(const RecastSettings& settings, const TilePosition& tilePosition)
|
||||||
|
Loading…
Reference in New Issue
Block a user