mirror of
https://github.com/recastnavigation/recastnavigation.git
synced 2026-10-06 00:45:35 +00:00
Add support for AABB shaped obstacles to dtTileCache (#215)
This commit is contained in:
@@ -370,9 +370,44 @@ dtStatus dtTileCache::addObstacle(const float* pos, const float radius, const fl
|
||||
memset(ob, 0, sizeof(dtTileCacheObstacle));
|
||||
ob->salt = salt;
|
||||
ob->state = DT_OBSTACLE_PROCESSING;
|
||||
dtVcopy(ob->pos, pos);
|
||||
ob->radius = radius;
|
||||
ob->height = height;
|
||||
ob->type = DT_OBSTACLE_CYLINDER;
|
||||
dtVcopy(ob->cylinder.pos, pos);
|
||||
ob->cylinder.radius = radius;
|
||||
ob->cylinder.height = height;
|
||||
|
||||
ObstacleRequest* req = &m_reqs[m_nreqs++];
|
||||
memset(req, 0, sizeof(ObstacleRequest));
|
||||
req->action = REQUEST_ADD;
|
||||
req->ref = getObstacleRef(ob);
|
||||
|
||||
if (result)
|
||||
*result = req->ref;
|
||||
|
||||
return DT_SUCCESS;
|
||||
}
|
||||
|
||||
dtStatus dtTileCache::addBoxObstacle(const float* bmin, const float* bmax, dtObstacleRef* result)
|
||||
{
|
||||
if (m_nreqs >= MAX_REQUESTS)
|
||||
return DT_FAILURE | DT_BUFFER_TOO_SMALL;
|
||||
|
||||
dtTileCacheObstacle* ob = 0;
|
||||
if (m_nextFreeObstacle)
|
||||
{
|
||||
ob = m_nextFreeObstacle;
|
||||
m_nextFreeObstacle = ob->next;
|
||||
ob->next = 0;
|
||||
}
|
||||
if (!ob)
|
||||
return DT_FAILURE | DT_OUT_OF_MEMORY;
|
||||
|
||||
unsigned short salt = ob->salt;
|
||||
memset(ob, 0, sizeof(dtTileCacheObstacle));
|
||||
ob->salt = salt;
|
||||
ob->state = DT_OBSTACLE_PROCESSING;
|
||||
ob->type = DT_OBSTACLE_BOX;
|
||||
dtVcopy(ob->box.bmin, bmin);
|
||||
dtVcopy(ob->box.bmax, bmax);
|
||||
|
||||
ObstacleRequest* req = &m_reqs[m_nreqs++];
|
||||
memset(req, 0, sizeof(ObstacleRequest));
|
||||
@@ -607,8 +642,16 @@ dtStatus dtTileCache::buildNavMeshTile(const dtCompressedTileRef ref, dtNavMesh*
|
||||
continue;
|
||||
if (contains(ob->touched, ob->ntouched, ref))
|
||||
{
|
||||
dtMarkCylinderArea(*bc.layer, tile->header->bmin, m_params.cs, m_params.ch,
|
||||
ob->pos, ob->radius, ob->height, 0);
|
||||
if (ob->type == DT_OBSTACLE_CYLINDER)
|
||||
{
|
||||
dtMarkCylinderArea(*bc.layer, tile->header->bmin, m_params.cs, m_params.ch,
|
||||
ob->cylinder.pos, ob->cylinder.radius, ob->cylinder.height, 0);
|
||||
}
|
||||
else if (ob->type == DT_OBSTACLE_BOX)
|
||||
{
|
||||
dtMarkBoxArea(*bc.layer, tile->header->bmin, m_params.cs, m_params.ch,
|
||||
ob->box.bmin, ob->box.bmax, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -702,10 +745,20 @@ void dtTileCache::calcTightTileBounds(const dtTileCacheLayerHeader* header, floa
|
||||
|
||||
void dtTileCache::getObstacleBounds(const struct dtTileCacheObstacle* ob, float* bmin, float* bmax) const
|
||||
{
|
||||
bmin[0] = ob->pos[0] - ob->radius;
|
||||
bmin[1] = ob->pos[1];
|
||||
bmin[2] = ob->pos[2] - ob->radius;
|
||||
bmax[0] = ob->pos[0] + ob->radius;
|
||||
bmax[1] = ob->pos[1] + ob->height;
|
||||
bmax[2] = ob->pos[2] + ob->radius;
|
||||
if (ob->type == DT_OBSTACLE_CYLINDER)
|
||||
{
|
||||
const dtObstacleCylinder &cl = ob->cylinder;
|
||||
|
||||
bmin[0] = cl.pos[0] - cl.radius;
|
||||
bmin[1] = cl.pos[1];
|
||||
bmin[2] = cl.pos[2] - cl.radius;
|
||||
bmax[0] = cl.pos[0] + cl.radius;
|
||||
bmax[1] = cl.pos[1] + cl.height;
|
||||
bmax[2] = cl.pos[2] + cl.radius;
|
||||
}
|
||||
else if (ob->type == DT_OBSTACLE_BOX)
|
||||
{
|
||||
dtVcopy(bmin, ob->box.bmin);
|
||||
dtVcopy(bmax, ob->box.bmax);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user