123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- #ifndef __CCNAV_MESH_OBSTACLE_H__
- #define __CCNAV_MESH_OBSTACLE_H__
- #include "base/ccConfig.h"
- #if CC_USE_NAVMESH
- #include "2d/CCComponent.h"
- #include "base/CCRef.h"
- #include "math/Vec3.h"
- #include "recast/Detour/DetourNavMesh.h"
- #include "recast/DetourTileCache/DetourTileCache.h"
- NS_CC_BEGIN
- class CC_DLL NavMeshObstacle : public Component
- {
- friend class NavMesh;
- public:
- enum NavMeshObstacleSyncFlag
- {
- NONE = 0,
- NODE_TO_OBSTACLE = 1,
- OBSTACLE_TO_NODE = 2,
- NODE_AND_NODE = NODE_TO_OBSTACLE | OBSTACLE_TO_NODE,
- };
-
- static NavMeshObstacle* create(float radius, float height);
- static const std::string& getNavMeshObstacleComponentName();
- virtual void onEnter() override;
- virtual void onExit() override;
-
- void setRadius(float radius);
-
- float getRadius() const { return _radius; }
-
- void setHeight(float height);
-
- float getHeight() const { return _height; }
-
- void setSyncFlag(const NavMeshObstacleSyncFlag &flag) { _syncFlag = flag; }
- NavMeshObstacleSyncFlag getSyncFlag() const { return _syncFlag; }
-
- void syncToObstacle();
-
- void syncToNode();
- CC_CONSTRUCTOR_ACCESS:
- NavMeshObstacle();
- virtual ~NavMeshObstacle();
- bool initWith(float radius, float height);
- private:
- void addTo(dtTileCache *tileCache);
- void removeFrom(dtTileCache *tileCache);
- void preUpdate(float delta);
- void postUpdate(float delta);
- private:
- float _radius;
- float _height;
- NavMeshObstacleSyncFlag _syncFlag;
- dtObstacleRef _obstacleID;
- dtTileCache *_tileCache;
- };
- NS_CC_END
- #endif
- #endif
|