mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-04 02:41:19 +00:00
fea4fb6e69
Even when target is not reachable actor will try to run there either because target navmesh polygon is selected within extended area or because partial path is built to the closest possible polygon.
37 lines
1.3 KiB
C++
37 lines
1.3 KiB
C++
#include "findrandompointaroundcircle.hpp"
|
|
#include "settings.hpp"
|
|
#include "findsmoothpath.hpp"
|
|
|
|
#include <components/misc/rng.hpp>
|
|
|
|
#include <DetourNavMesh.h>
|
|
#include <DetourNavMeshQuery.h>
|
|
|
|
namespace DetourNavigator
|
|
{
|
|
std::optional<osg::Vec3f> findRandomPointAroundCircle(const dtNavMesh& navMesh, const osg::Vec3f& halfExtents,
|
|
const osg::Vec3f& start, const float maxRadius, const Flags includeFlags, const Settings& settings)
|
|
{
|
|
dtNavMeshQuery navMeshQuery;
|
|
if (!initNavMeshQuery(navMeshQuery, navMesh, settings.mMaxNavMeshQueryNodes))
|
|
return std::optional<osg::Vec3f>();
|
|
|
|
dtQueryFilter queryFilter;
|
|
queryFilter.setIncludeFlags(includeFlags);
|
|
|
|
dtPolyRef startRef = findNearestPoly(navMeshQuery, queryFilter, start, halfExtents * 4);
|
|
if (startRef == 0)
|
|
return std::optional<osg::Vec3f>();
|
|
|
|
dtPolyRef resultRef = 0;
|
|
osg::Vec3f resultPosition;
|
|
navMeshQuery.findRandomPointAroundCircle(startRef, start.ptr(), maxRadius, &queryFilter,
|
|
[]() { return Misc::Rng::rollProbability(); }, &resultRef, resultPosition.ptr());
|
|
|
|
if (resultRef == 0)
|
|
return std::optional<osg::Vec3f>();
|
|
|
|
return std::optional<osg::Vec3f>(resultPosition);
|
|
}
|
|
}
|