Merge branch 'fix_still_actors' into 'master'
Make actor flee from a combat when cannot reach a target (#5851) See merge request OpenMW/openmw!601pull/593/head
commit
937549c99e
@ -0,0 +1,44 @@
|
||||
#include "raycast.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "findsmoothpath.hpp"
|
||||
|
||||
#include <DetourCommon.h>
|
||||
#include <DetourNavMesh.h>
|
||||
#include <DetourNavMeshQuery.h>
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace DetourNavigator
|
||||
{
|
||||
std::optional<osg::Vec3f> raycast(const dtNavMesh& navMesh, const osg::Vec3f& halfExtents,
|
||||
const osg::Vec3f& start, const osg::Vec3f& end, const Flags includeFlags, const Settings& settings)
|
||||
{
|
||||
dtNavMeshQuery navMeshQuery;
|
||||
if (!initNavMeshQuery(navMeshQuery, navMesh, settings.mMaxNavMeshQueryNodes))
|
||||
return {};
|
||||
|
||||
dtQueryFilter queryFilter;
|
||||
queryFilter.setIncludeFlags(includeFlags);
|
||||
|
||||
dtPolyRef ref = 0;
|
||||
if (dtStatus status = navMeshQuery.findNearestPoly(start.ptr(), halfExtents.ptr(), &queryFilter, &ref, nullptr);
|
||||
dtStatusFailed(status) || ref == 0)
|
||||
return {};
|
||||
|
||||
const unsigned options = 0;
|
||||
std::array<dtPolyRef, 16> path;
|
||||
dtRaycastHit hit;
|
||||
hit.path = path.data();
|
||||
hit.maxPath = path.size();
|
||||
if (dtStatus status = navMeshQuery.raycast(ref, start.ptr(), end.ptr(), &queryFilter, options, &hit);
|
||||
dtStatusFailed(status) || hit.pathCount == 0)
|
||||
return {};
|
||||
|
||||
osg::Vec3f hitPosition;
|
||||
if (dtStatus status = navMeshQuery.closestPointOnPoly(path[hit.pathCount - 1], end.ptr(), hitPosition.ptr(), nullptr);
|
||||
dtStatusFailed(status))
|
||||
return {};
|
||||
|
||||
return hitPosition;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_RAYCAST_H
|
||||
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_RAYCAST_H
|
||||
|
||||
#include "flags.hpp"
|
||||
|
||||
#include <optional>
|
||||
#include <osg/Vec3f>
|
||||
|
||||
class dtNavMesh;
|
||||
|
||||
namespace DetourNavigator
|
||||
{
|
||||
struct Settings;
|
||||
|
||||
std::optional<osg::Vec3f> raycast(const dtNavMesh& navMesh, const osg::Vec3f& halfExtents,
|
||||
const osg::Vec3f& start, const osg::Vec3f& end, const Flags includeFlags, const Settings& settings);
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue