2018-03-13 22:49:08 +00:00
|
|
|
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_SETTINGSUTILS_H
|
|
|
|
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_SETTINGSUTILS_H
|
|
|
|
|
|
|
|
#include "settings.hpp"
|
2018-04-15 22:07:18 +00:00
|
|
|
#include "tilebounds.hpp"
|
2018-03-13 22:49:08 +00:00
|
|
|
#include "tileposition.hpp"
|
|
|
|
#include "tilebounds.hpp"
|
|
|
|
|
2018-07-20 19:11:34 +00:00
|
|
|
#include <LinearMath/btTransform.h>
|
|
|
|
|
2018-04-20 23:57:01 +00:00
|
|
|
#include <osg/Vec2f>
|
|
|
|
#include <osg/Vec2i>
|
2018-03-13 22:49:08 +00:00
|
|
|
#include <osg/Vec3f>
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace DetourNavigator
|
|
|
|
{
|
|
|
|
inline float getHeight(const Settings& settings,const osg::Vec3f& agentHalfExtents)
|
|
|
|
{
|
|
|
|
return 2.0f * agentHalfExtents.z() * settings.mRecastScaleFactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline float getMaxClimb(const Settings& settings)
|
|
|
|
{
|
|
|
|
return settings.mMaxClimb * settings.mRecastScaleFactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline float getRadius(const Settings& settings, const osg::Vec3f& agentHalfExtents)
|
|
|
|
{
|
|
|
|
return agentHalfExtents.x() * settings.mRecastScaleFactor;
|
|
|
|
}
|
|
|
|
|
2019-03-08 16:53:37 +00:00
|
|
|
inline float toNavMeshCoordinates(const Settings& settings, float value)
|
|
|
|
{
|
|
|
|
return value * settings.mRecastScaleFactor;
|
|
|
|
}
|
|
|
|
|
2018-03-13 22:49:08 +00:00
|
|
|
inline osg::Vec3f toNavMeshCoordinates(const Settings& settings, osg::Vec3f position)
|
|
|
|
{
|
|
|
|
std::swap(position.y(), position.z());
|
|
|
|
return position * settings.mRecastScaleFactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline osg::Vec3f fromNavMeshCoordinates(const Settings& settings, osg::Vec3f position)
|
|
|
|
{
|
|
|
|
const auto factor = 1.0f / settings.mRecastScaleFactor;
|
|
|
|
position *= factor;
|
|
|
|
std::swap(position.y(), position.z());
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline float getTileSize(const Settings& settings)
|
|
|
|
{
|
|
|
|
return settings.mTileSize * settings.mCellSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline TilePosition getTilePosition(const Settings& 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)))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline TileBounds makeTileBounds(const Settings& settings, const TilePosition& tilePosition)
|
|
|
|
{
|
|
|
|
return TileBounds {
|
|
|
|
osg::Vec2f(tilePosition.x(), tilePosition.y()) * getTileSize(settings),
|
|
|
|
osg::Vec2f(tilePosition.x() + 1, tilePosition.y() + 1) * getTileSize(settings),
|
|
|
|
};
|
|
|
|
}
|
2018-04-15 19:54:45 +00:00
|
|
|
|
|
|
|
inline float getBorderSize(const Settings& settings)
|
|
|
|
{
|
|
|
|
return settings.mBorderSize * settings.mCellSize;
|
|
|
|
}
|
2018-07-20 19:11:34 +00:00
|
|
|
|
|
|
|
inline float getSwimLevel(const Settings& settings, const float agentHalfExtentsZ)
|
|
|
|
{
|
|
|
|
return - settings.mSwimHeightScale * agentHalfExtentsZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline btTransform getSwimLevelTransform(const Settings& settings, const btTransform& transform,
|
|
|
|
const float agentHalfExtentsZ)
|
|
|
|
{
|
|
|
|
return btTransform(
|
|
|
|
transform.getBasis(),
|
|
|
|
transform.getOrigin() + btVector3(0, 0, getSwimLevel(settings, agentHalfExtentsZ) - agentHalfExtentsZ)
|
|
|
|
);
|
|
|
|
}
|
2018-03-13 22:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|