2015-05-29 16:45:33 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-29 16:45:33 +08:00
|
|
|
http://www.cocos2d-x.org
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-29 16:45:33 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-29 16:45:33 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-29 16:45:33 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CCNAV_MESH_OBSTACLE_H__
|
|
|
|
#define __CCNAV_MESH_OBSTACLE_H__
|
|
|
|
|
|
|
|
#include "base/ccConfig.h"
|
|
|
|
#if CC_USE_NAVMESH
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
# include "2d/CCComponent.h"
|
2015-05-29 16:45:33 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
# include "base/CCRef.h"
|
|
|
|
# include "math/Vec3.h"
|
|
|
|
# include "recast/DetourNavMesh.h"
|
|
|
|
# include "recast/DetourTileCache.h"
|
2015-05-29 16:45:33 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup 3d
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @brief NavMeshObstacle: The code wrapping of dtTileCacheObstacle, use component mode. */
|
|
|
|
class CC_DLL NavMeshObstacle : public Component
|
|
|
|
{
|
|
|
|
friend class NavMesh;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
public:
|
2015-05-29 16:45:33 +08:00
|
|
|
enum NavMeshObstacleSyncFlag
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
NONE = 0,
|
2015-05-29 16:45:33 +08:00
|
|
|
NODE_TO_OBSTACLE = 1,
|
|
|
|
OBSTACLE_TO_NODE = 2,
|
2021-12-25 10:04:45 +08:00
|
|
|
NODE_AND_NODE = NODE_TO_OBSTACLE | OBSTACLE_TO_NODE,
|
2015-05-29 16:45:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
Create obstacle, shape is cylinder
|
|
|
|
|
|
|
|
@param radius The radius of obstacle.
|
|
|
|
@param height The height of obstacle.
|
|
|
|
*/
|
|
|
|
static NavMeshObstacle* create(float radius, float height);
|
2021-12-26 23:26:34 +08:00
|
|
|
static std::string_view getNavMeshObstacleComponentName();
|
2015-05-29 16:45:33 +08:00
|
|
|
|
|
|
|
virtual void onEnter() override;
|
|
|
|
virtual void onExit() override;
|
|
|
|
|
|
|
|
/** Set radius of obstacle */
|
|
|
|
void setRadius(float radius);
|
|
|
|
|
|
|
|
/** Get radius of obstacle */
|
|
|
|
float getRadius() const { return _radius; }
|
|
|
|
|
|
|
|
/** Set height of obstacle */
|
|
|
|
void setHeight(float height);
|
|
|
|
|
|
|
|
/** Get height of obstacle */
|
|
|
|
float getHeight() const { return _height; }
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* synchronization between node and obstacle is time consuming, you can skip some synchronization using this
|
|
|
|
* function
|
|
|
|
*/
|
|
|
|
void setSyncFlag(const NavMeshObstacleSyncFlag& flag) { _syncFlag = flag; }
|
2015-05-29 16:45:33 +08:00
|
|
|
NavMeshObstacleSyncFlag getSyncFlag() const { return _syncFlag; }
|
|
|
|
|
|
|
|
/** synchronize parameter to obstacle. */
|
|
|
|
void syncToObstacle();
|
|
|
|
|
|
|
|
/** synchronize parameter to node. */
|
|
|
|
void syncToNode();
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS : NavMeshObstacle();
|
2015-05-29 16:45:33 +08:00
|
|
|
virtual ~NavMeshObstacle();
|
|
|
|
|
|
|
|
bool initWith(float radius, float height);
|
|
|
|
|
|
|
|
private:
|
2021-12-25 10:04:45 +08:00
|
|
|
void addTo(dtTileCache* tileCache);
|
|
|
|
void removeFrom(dtTileCache* tileCache);
|
2015-05-29 16:45:33 +08:00
|
|
|
void preUpdate(float delta);
|
|
|
|
void postUpdate(float delta);
|
|
|
|
|
|
|
|
private:
|
|
|
|
float _radius;
|
|
|
|
float _height;
|
|
|
|
NavMeshObstacleSyncFlag _syncFlag;
|
|
|
|
dtObstacleRef _obstacleID;
|
2021-12-25 10:04:45 +08:00
|
|
|
dtTileCache* _tileCache;
|
2015-05-29 16:45:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // CC_USE_NAVMESH
|
2015-05-29 16:45:33 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // __CCNAV_MESH_OBSTACLE_H__
|