mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-20 17:11:33 +00:00
Make OutputTransformIterator more generic
This commit is contained in:
parent
de3a6ca6e6
commit
3dfea1dc1b
2 changed files with 13 additions and 6 deletions
|
@ -49,13 +49,13 @@ namespace DetourNavigator
|
||||||
std::optional<SteerTarget> getSteerTarget(const dtNavMeshQuery& navQuery, const osg::Vec3f& startPos,
|
std::optional<SteerTarget> getSteerTarget(const dtNavMeshQuery& navQuery, const osg::Vec3f& startPos,
|
||||||
const osg::Vec3f& endPos, const float minTargetDist, const dtPolyRef* path, const std::size_t pathSize);
|
const osg::Vec3f& endPos, const float minTargetDist, const dtPolyRef* path, const std::size_t pathSize);
|
||||||
|
|
||||||
template <class OutputIterator>
|
template <class OutputIterator, class Function>
|
||||||
class OutputTransformIterator
|
class OutputTransformIterator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit OutputTransformIterator(OutputIterator& impl, const RecastSettings& settings)
|
explicit OutputTransformIterator(OutputIterator& impl, Function&& function)
|
||||||
: mImpl(impl)
|
: mImpl(impl)
|
||||||
, mSettings(settings)
|
, mFunction(std::forward<Function>(function))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,15 +76,22 @@ namespace DetourNavigator
|
||||||
|
|
||||||
OutputTransformIterator& operator=(const osg::Vec3f& value)
|
OutputTransformIterator& operator=(const osg::Vec3f& value)
|
||||||
{
|
{
|
||||||
*mImpl.get() = fromNavMeshCoordinates(mSettings, value);
|
*mImpl.get() = mFunction(value);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::reference_wrapper<OutputIterator> mImpl;
|
std::reference_wrapper<OutputIterator> mImpl;
|
||||||
std::reference_wrapper<const RecastSettings> mSettings;
|
Function mFunction;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class OutputIterator>
|
||||||
|
auto withFromNavMeshCoordinates(OutputIterator& impl, const RecastSettings& settings)
|
||||||
|
{
|
||||||
|
return OutputTransformIterator(
|
||||||
|
impl, [&settings](const osg::Vec3f& value) { return fromNavMeshCoordinates(settings, value); });
|
||||||
|
}
|
||||||
|
|
||||||
dtPolyRef findNearestPoly(const dtNavMeshQuery& query, const dtQueryFilter& filter, const osg::Vec3f& center,
|
dtPolyRef findNearestPoly(const dtNavMeshQuery& query, const dtQueryFilter& filter, const osg::Vec3f& center,
|
||||||
const osg::Vec3f& halfExtents);
|
const osg::Vec3f& halfExtents);
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ namespace DetourNavigator
|
||||||
if (navMesh == nullptr)
|
if (navMesh == nullptr)
|
||||||
return Status::NavMeshNotFound;
|
return Status::NavMeshNotFound;
|
||||||
const Settings& settings = navigator.getSettings();
|
const Settings& settings = navigator.getSettings();
|
||||||
auto outTransform = OutputTransformIterator<OutputIterator>(out, settings.mRecast);
|
auto outTransform = withFromNavMeshCoordinates(out, settings.mRecast);
|
||||||
const auto locked = navMesh->lock();
|
const auto locked = navMesh->lock();
|
||||||
return findSmoothPath(locked->getQuery(), toNavMeshCoordinates(settings.mRecast, agentBounds.mHalfExtents),
|
return findSmoothPath(locked->getQuery(), toNavMeshCoordinates(settings.mRecast, agentBounds.mHalfExtents),
|
||||||
toNavMeshCoordinates(settings.mRecast, stepSize), toNavMeshCoordinates(settings.mRecast, start),
|
toNavMeshCoordinates(settings.mRecast, stepSize), toNavMeshCoordinates(settings.mRecast, start),
|
||||||
|
|
Loading…
Reference in a new issue