1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-27 12:35:46 +00:00

68 lines
2.1 KiB
C++
Raw Normal View History

2018-03-14 01:49:08 +03:00
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_NAVIGATOR_H
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_NAVIGATOR_H
#include "findsmoothpath.hpp"
#include "navmeshmanager.hpp"
#include "settings.hpp"
#include "settingsutils.hpp"
namespace DetourNavigator
{
2018-07-12 11:44:11 +03:00
struct ObjectShapes
{
const btCollisionShape& mShape;
const btCollisionShape* mAvoid;
ObjectShapes(const btCollisionShape& shape, const btCollisionShape* avoid)
: mShape(shape), mAvoid(avoid)
2018-07-18 22:09:50 +03:00
{}
2018-07-12 11:44:11 +03:00
};
2018-03-14 01:49:08 +03:00
class Navigator
{
public:
Navigator(const Settings& settings);
void addAgent(const osg::Vec3f& agentHalfExtents);
void removeAgent(const osg::Vec3f& agentHalfExtents);
2018-04-03 00:04:19 +03:00
bool addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform);
2018-03-14 01:49:08 +03:00
2018-07-12 11:44:11 +03:00
bool addObject(std::size_t id, const ObjectShapes& shapes, const btTransform& transform);
2018-05-26 17:44:25 +03:00
bool updateObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform);
2018-07-12 11:44:11 +03:00
bool updateObject(std::size_t id, const ObjectShapes& shapes, const btTransform& transform);
2018-03-14 01:49:08 +03:00
bool removeObject(std::size_t id);
void update(const osg::Vec3f& playerPosition);
2018-03-14 01:49:08 +03:00
void wait();
template <class OutputIterator>
OutputIterator findPath(const osg::Vec3f& agentHalfExtents, const osg::Vec3f& start,
const osg::Vec3f& end, OutputIterator out) const
{
const auto navMesh = mNavMeshManager.getNavMesh(agentHalfExtents);
return findSmoothPath(*navMesh.lock(), toNavMeshCoordinates(mSettings, agentHalfExtents),
2018-03-14 01:49:08 +03:00
toNavMeshCoordinates(mSettings, start), toNavMeshCoordinates(mSettings, end), mSettings, out);
}
std::map<osg::Vec3f, std::shared_ptr<NavMeshCacheItem>> getNavMeshes() const;
const Settings& getSettings() const;
2018-03-14 01:49:08 +03:00
private:
Settings mSettings;
NavMeshManager mNavMeshManager;
std::map<osg::Vec3f, std::size_t> mAgents;
2018-07-12 11:44:11 +03:00
std::unordered_map<std::size_t, std::size_t> mAvoidIds;
void updateAvoidShapeId(std::size_t id, std::size_t avoidId);
2018-03-14 01:49:08 +03:00
};
}
#endif