1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-19 19:53:53 +00:00
openmw/components/detournavigator/gettilespositions.cpp

59 lines
2.1 KiB
C++
Raw Normal View History

2022-01-25 14:06:53 +00:00
#include "gettilespositions.hpp"
#include "settings.hpp"
#include "settingsutils.hpp"
#include "tileposition.hpp"
2022-01-31 23:22:53 +00:00
#include "tilebounds.hpp"
2022-01-25 14:06:53 +00:00
#include <components/misc/convert.hpp>
#include <BulletCollision/CollisionShapes/btCollisionShape.h>
namespace DetourNavigator
{
2022-01-31 23:22:53 +00:00
TilesPositionsRange makeTilesPositionsRange(const osg::Vec2f& aabbMin, const osg::Vec2f& aabbMax,
2022-01-25 14:06:53 +00:00
const RecastSettings& settings)
{
2022-01-31 23:22:53 +00:00
osg::Vec2f min = toNavMeshCoordinates(settings, aabbMin);
osg::Vec2f max = toNavMeshCoordinates(settings, aabbMax);
2022-01-25 14:06:53 +00:00
const float border = getBorderSize(settings);
2022-01-31 23:22:53 +00:00
min -= osg::Vec2f(border, border);
max += osg::Vec2f(border, border);
2022-01-25 14:06:53 +00:00
TilePosition minTile = getTilePosition(settings, min);
TilePosition maxTile = getTilePosition(settings, max);
if (minTile.x() > maxTile.x())
std::swap(minTile.x(), maxTile.x());
if (minTile.y() > maxTile.y())
std::swap(minTile.y(), maxTile.y());
return {minTile, maxTile + osg::Vec2i(1, 1)};
2022-01-25 14:06:53 +00:00
}
TilesPositionsRange makeTilesPositionsRange(const btCollisionShape& shape, const btTransform& transform,
const RecastSettings& settings)
2022-01-25 14:06:53 +00:00
{
2022-01-31 23:22:53 +00:00
const TileBounds bounds = makeObjectTileBounds(shape, transform);
return makeTilesPositionsRange(bounds.mMin, bounds.mMax, settings);
2022-01-25 14:06:53 +00:00
}
TilesPositionsRange makeTilesPositionsRange(const int cellSize, const btVector3& shift,
const RecastSettings& settings)
{
const int halfCellSize = cellSize / 2;
const btTransform transform(btMatrix3x3::getIdentity(), shift);
btVector3 aabbMin = transform(btVector3(-halfCellSize, -halfCellSize, 0));
btVector3 aabbMax = transform(btVector3(halfCellSize, halfCellSize, 0));
aabbMin.setX(std::min(aabbMin.x(), aabbMax.x()));
aabbMin.setY(std::min(aabbMin.y(), aabbMax.y()));
aabbMax.setX(std::max(aabbMin.x(), aabbMax.x()));
aabbMax.setY(std::max(aabbMin.y(), aabbMax.y()));
2022-01-31 23:22:53 +00:00
return makeTilesPositionsRange(Misc::Convert::toOsgXY(aabbMin), Misc::Convert::toOsgXY(aabbMax), settings);
2022-01-25 14:06:53 +00:00
}
}