123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- #ifndef __CCNAV_MESH_H__
- #define __CCNAV_MESH_H__
- #include "base/ccConfig.h"
- #if CC_USE_NAVMESH
- #include "base/CCRef.h"
- #include "math/Vec3.h"
- #include "recast/Detour/DetourNavMesh.h"
- #include "recast/Detour/DetourNavMeshQuery.h"
- #include "recast/DetourCrowd/DetourCrowd.h"
- #include "recast/DetourTileCache/DetourTileCache.h"
- #include <string>
- #include <vector>
- #include "navmesh/CCNavMeshAgent.h"
- #include "navmesh/CCNavMeshDebugDraw.h"
- #include "navmesh/CCNavMeshObstacle.h"
- #include "navmesh/CCNavMeshUtils.h"
- NS_CC_BEGIN
- class Renderer;
- class CC_DLL NavMesh : public Ref
- {
- public:
-
- static NavMesh* create(const std::string &navFilePath, const std::string &geomFilePath);
-
- void update(float dt);
-
- void debugDraw(Renderer* renderer);
-
- void setDebugDrawEnable(bool enable);
-
- bool isDebugDrawEnabled() const;
-
- void addNavMeshAgent(NavMeshAgent *agent);
-
- void removeNavMeshAgent(NavMeshAgent *agent);
-
- void addNavMeshObstacle(NavMeshObstacle *obstacle);
-
- void removeNavMeshObstacle(NavMeshObstacle *obstacle);
-
- void findPath(const Vec3 &start, const Vec3 &end, std::vector<Vec3> &pathPoints);
- CC_CONSTRUCTOR_ACCESS:
- NavMesh();
- virtual ~NavMesh();
- protected:
- bool initWithFilePath(const std::string &navFilePath, const std::string &geomFilePath);
- bool read();
- bool loadNavMeshFile();
- bool loadGeomFile();
- void dtDraw();
- void drawAgents();
- void drawObstacles();
- void drawOffMeshConnections();
- protected:
- dtNavMesh *_navMesh;
- dtNavMeshQuery *_navMeshQuery;
- dtCrowd *_crowed;
- dtTileCache *_tileCache;
- LinearAllocator *_allocator;
- FastLZCompressor *_compressor;
- MeshProcess *_meshProcess;
- GeomData *_geomData;
- std::vector<NavMeshAgent*> _agentList;
- std::vector<NavMeshObstacle*> _obstacleList;
- NavMeshDebugDraw _debugDraw;
- std::string _navFilePath;
- std::string _geomFilePath;
- bool _isDebugDrawEnabled;
- };
- NS_CC_END
- #endif
- #endif
|