2020-01-20 22:06:47 +00:00
|
|
|
#include "findrandompointaroundcircle.hpp"
|
|
|
|
#include "findsmoothpath.hpp"
|
|
|
|
|
|
|
|
#include <DetourNavMesh.h>
|
|
|
|
#include <DetourNavMeshQuery.h>
|
|
|
|
|
|
|
|
namespace DetourNavigator
|
|
|
|
{
|
2023-02-17 13:55:05 +00:00
|
|
|
std::optional<osg::Vec3f> findRandomPointAroundCircle(const dtNavMeshQuery& navMeshQuery,
|
|
|
|
const osg::Vec3f& halfExtents, const osg::Vec3f& start, const float maxRadius, const Flags includeFlags,
|
2022-05-17 15:04:11 +00:00
|
|
|
float (*prng)())
|
2020-01-20 22:06:47 +00:00
|
|
|
{
|
|
|
|
dtQueryFilter queryFilter;
|
|
|
|
queryFilter.setIncludeFlags(includeFlags);
|
|
|
|
|
2021-08-18 20:46:14 +00:00
|
|
|
dtPolyRef startRef = findNearestPoly(navMeshQuery, queryFilter, start, halfExtents * 4);
|
2020-01-20 22:06:47 +00:00
|
|
|
if (startRef == 0)
|
2020-10-24 22:33:41 +00:00
|
|
|
return std::optional<osg::Vec3f>();
|
2020-01-20 22:06:47 +00:00
|
|
|
|
|
|
|
dtPolyRef resultRef = 0;
|
|
|
|
osg::Vec3f resultPosition;
|
2022-05-17 15:04:11 +00:00
|
|
|
|
2020-01-20 22:06:47 +00:00
|
|
|
navMeshQuery.findRandomPointAroundCircle(
|
|
|
|
startRef, start.ptr(), maxRadius, &queryFilter, prng, &resultRef, resultPosition.ptr());
|
|
|
|
|
|
|
|
if (resultRef == 0)
|
2020-10-24 22:33:41 +00:00
|
|
|
return std::optional<osg::Vec3f>();
|
2020-01-20 22:06:47 +00:00
|
|
|
|
2020-10-24 22:33:41 +00:00
|
|
|
return std::optional<osg::Vec3f>(resultPosition);
|
2020-01-20 22:06:47 +00:00
|
|
|
}
|
|
|
|
}
|