setRadius and setGeight implementation

This commit is contained in:
yangxiao 2015-06-01 17:38:35 +08:00
parent a0adf507c0
commit 5bf09a676e
1 changed files with 27 additions and 9 deletions

View File

@ -123,24 +123,42 @@ void NavMeshObstacle::syncToNode()
{
if (_tileCache){
auto obstacle = _tileCache->getObstacleByRef(_obstacleID);
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);
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]){
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);
}
}
}
}
NS_CC_END