mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-03 17:37:18 +00:00
1a12c453d6
Actors may have different collision shapes. Currently there are axis-aligned bounding boxes and rotating bounding boxes. With AABB it's required to use bounding cylinder for navmesh agent to avoid providing paths where actor can't pass. But for rotating bounding boxes cylinder with diameter equal to the front face width should be used to not reduce of available paths. For example rats have rotating bounding box as collision shape because of the difference between front and side faces width. * Add agent bounds to navmesh tile db cache key. This is required to distinguish tiles for agents with different bounds. * Increase navmesh version because navmesh tile db cache key and data has changed. * Move navmesh version to the code to avoid misconfiguration by users. * Fix all places where wrong half extents were used for pathfinding.
38 lines
1.8 KiB
C++
38 lines
1.8 KiB
C++
#include "navigatorutils.hpp"
|
|
#include "findrandompointaroundcircle.hpp"
|
|
#include "navigator.hpp"
|
|
#include "raycast.hpp"
|
|
|
|
namespace DetourNavigator
|
|
{
|
|
std::optional<osg::Vec3f> findRandomPointAroundCircle(const Navigator& navigator, const AgentBounds& agentBounds,
|
|
const osg::Vec3f& start, const float maxRadius, const Flags includeFlags, float(*prng)())
|
|
{
|
|
const auto navMesh = navigator.getNavMesh(agentBounds);
|
|
if (!navMesh)
|
|
return std::nullopt;
|
|
const auto& settings = navigator.getSettings();
|
|
const auto result = DetourNavigator::findRandomPointAroundCircle(navMesh->lockConst()->getImpl(),
|
|
toNavMeshCoordinates(settings.mRecast, agentBounds.mHalfExtents), toNavMeshCoordinates(settings.mRecast, start),
|
|
toNavMeshCoordinates(settings.mRecast, maxRadius), includeFlags, settings.mDetour, prng);
|
|
if (!result)
|
|
return std::nullopt;
|
|
return std::optional<osg::Vec3f>(fromNavMeshCoordinates(settings.mRecast, *result));
|
|
}
|
|
|
|
std::optional<osg::Vec3f> raycast(const Navigator& navigator, const AgentBounds& agentBounds, const osg::Vec3f& start,
|
|
const osg::Vec3f& end, const Flags includeFlags)
|
|
{
|
|
const auto navMesh = navigator.getNavMesh(agentBounds);
|
|
if (navMesh == nullptr)
|
|
return std::nullopt;
|
|
const auto& settings = navigator.getSettings();
|
|
const auto result = DetourNavigator::raycast(navMesh->lockConst()->getImpl(),
|
|
toNavMeshCoordinates(settings.mRecast, agentBounds.mHalfExtents), toNavMeshCoordinates(settings.mRecast, start),
|
|
toNavMeshCoordinates(settings.mRecast, end), includeFlags, settings.mDetour);
|
|
if (!result)
|
|
return std::nullopt;
|
|
return fromNavMeshCoordinates(settings.mRecast, *result);
|
|
}
|
|
}
|