From 5bf09a676e4426533b541633bd5ad95afcd7056d Mon Sep 17 00:00:00 2001 From: yangxiao Date: Mon, 1 Jun 2015 17:38:35 +0800 Subject: [PATCH] setRadius and setGeight implementation --- cocos/navmesh/CCNavMeshObstacle.cpp | 36 +++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/cocos/navmesh/CCNavMeshObstacle.cpp b/cocos/navmesh/CCNavMeshObstacle.cpp index e17986504b..faae166922 100644 --- a/cocos/navmesh/CCNavMeshObstacle.cpp +++ b/cocos/navmesh/CCNavMeshObstacle.cpp @@ -123,22 +123,40 @@ void NavMeshObstacle::syncToNode() { if (_tileCache){ auto obstacle = _tileCache->getObstacleByRef(_obstacleID); - Vec3 localPos = Vec3(obstacle->pos[0], obstacle->pos[1], obstacle->pos[2]); - if (_owner->getParent()) - _owner->getParent()->getWorldToNodeTransform().transformPoint(localPos, &localPos); - _owner->setPosition3D(localPos); + if (obstacle){ + Vec3 localPos = Vec3(obstacle->pos[0], obstacle->pos[1], obstacle->pos[2]); + if (_owner->getParent()) + _owner->getParent()->getWorldToNodeTransform().transformPoint(localPos, &localPos); + _owner->setPosition3D(localPos); + _radius = obstacle->radius; + _height = obstacle->height; + } } } +void cocos2d::NavMeshObstacle::setRadius(float radius) +{ + _radius = radius; +} + +void cocos2d::NavMeshObstacle::setHeight(float height) +{ + _height = height; +} + void NavMeshObstacle::syncToObstacle() { if (_tileCache){ auto obstacle = _tileCache->getObstacleByRef(_obstacleID); - Vec3 worldPos = Vec3(obstacle->pos[0], obstacle->pos[1], obstacle->pos[2]); - Mat4 mat = _owner->getNodeToWorldTransform(); - if (mat.m[12] != obstacle->pos[0] && mat.m[13] != obstacle->pos[1] && mat.m[14] != obstacle->pos[2]){ - _tileCache->removeObstacle(_obstacleID); - _tileCache->addObstacle(&mat.m[12], _radius, _height, &_obstacleID); + if (obstacle){ + Vec3 worldPos = Vec3(obstacle->pos[0], obstacle->pos[1], obstacle->pos[2]); + Mat4 mat = _owner->getNodeToWorldTransform(); + if ((mat.m[12] != obstacle->pos[0] && mat.m[13] != obstacle->pos[1] && mat.m[14] != obstacle->pos[2]) + || obstacle->radius != _radius + || obstacle->height != _height){ + _tileCache->removeObstacle(_obstacleID); + _tileCache->addObstacle(&mat.m[12], _radius, _height, &_obstacleID); + } } } }