Renamed all instances of 'extents' to 'halfExtents' (#279)

This commit is contained in:
aymarfisherman 2017-08-20 12:05:51 -03:00 committed by Jakob Botsch Nielsen
parent 840c100639
commit 7cca61dc41
16 changed files with 66 additions and 61 deletions

View File

@ -635,7 +635,7 @@ private:
dtPolyRef* polys, const int maxPolys) const;
/// Find nearest polygon within a tile.
dtPolyRef findNearestPolyInTile(const dtMeshTile* tile, const float* center,
const float* extents, float* nearestPt) const;
const float* halfExtents, float* nearestPt) const;
/// Returns closest point on polygon.
void closestPointOnPoly(dtPolyRef ref, const float* pos, float* closest, bool* posOverPoly) const;

View File

@ -316,33 +316,33 @@ public:
/// Finds the polygon nearest to the specified center point.
/// @param[in] center The center of the search box. [(x, y, z)]
/// @param[in] extents The search distance along each axis. [(x, y, z)]
/// @param[in] halfExtents The search distance along each axis. [(x, y, z)]
/// @param[in] filter The polygon filter to apply to the query.
/// @param[out] nearestRef The reference id of the nearest polygon.
/// @param[out] nearestPt The nearest point on the polygon. [opt] [(x, y, z)]
/// @returns The status flags for the query.
dtStatus findNearestPoly(const float* center, const float* extents,
dtStatus findNearestPoly(const float* center, const float* halfExtents,
const dtQueryFilter* filter,
dtPolyRef* nearestRef, float* nearestPt) const;
/// Finds polygons that overlap the search box.
/// @param[in] center The center of the search box. [(x, y, z)]
/// @param[in] extents The search distance along each axis. [(x, y, z)]
/// @param[in] halfExtents The search distance along each axis. [(x, y, z)]
/// @param[in] filter The polygon filter to apply to the query.
/// @param[out] polys The reference ids of the polygons that overlap the query box.
/// @param[out] polyCount The number of polygons in the search result.
/// @param[in] maxPolys The maximum number of polygons the search result can hold.
/// @returns The status flags for the query.
dtStatus queryPolygons(const float* center, const float* extents,
dtStatus queryPolygons(const float* center, const float* halfExtents,
const dtQueryFilter* filter,
dtPolyRef* polys, int* polyCount, const int maxPolys) const;
/// Finds polygons that overlap the search box.
/// @param[in] center The center of the search box. [(x, y, z)]
/// @param[in] extents The search distance along each axis. [(x, y, z)]
/// @param[in] halfExtents The search distance along each axis. [(x, y, z)]
/// @param[in] filter The polygon filter to apply to the query.
/// @param[in] query The query. Polygons found will be batched together and passed to this query.
dtStatus queryPolygons(const float* center, const float* extents,
dtStatus queryPolygons(const float* center, const float* halfExtents,
const dtQueryFilter* filter, dtPolyQuery* query) const;
/// Finds the non-overlapping navigation polygons in the local neighbourhood around the center position.

View File

@ -470,12 +470,12 @@ void dtNavMesh::connectExtOffMeshLinks(dtMeshTile* tile, dtMeshTile* target, int
if (targetPoly->firstLink == DT_NULL_LINK)
continue;
const float ext[3] = { targetCon->rad, target->header->walkableClimb, targetCon->rad };
const float halfExtents[3] = { targetCon->rad, target->header->walkableClimb, targetCon->rad };
// Find polygon to connect to.
const float* p = &targetCon->pos[3];
float nearestPt[3];
dtPolyRef ref = findNearestPolyInTile(tile, p, ext, nearestPt);
dtPolyRef ref = findNearestPolyInTile(tile, p, halfExtents, nearestPt);
if (!ref)
continue;
// findNearestPoly may return too optimistic results, further check to make sure.
@ -570,12 +570,12 @@ void dtNavMesh::baseOffMeshLinks(dtMeshTile* tile)
dtOffMeshConnection* con = &tile->offMeshCons[i];
dtPoly* poly = &tile->polys[con->poly];
const float ext[3] = { con->rad, tile->header->walkableClimb, con->rad };
const float halfExtents[3] = { con->rad, tile->header->walkableClimb, con->rad };
// Find polygon to connect to.
const float* p = &con->pos[0]; // First vertex
float nearestPt[3];
dtPolyRef ref = findNearestPolyInTile(tile, p, ext, nearestPt);
dtPolyRef ref = findNearestPolyInTile(tile, p, halfExtents, nearestPt);
if (!ref) continue;
// findNearestPoly may return too optimistic results, further check to make sure.
if (dtSqr(nearestPt[0]-p[0])+dtSqr(nearestPt[2]-p[2]) > dtSqr(con->rad))
@ -696,12 +696,12 @@ void dtNavMesh::closestPointOnPoly(dtPolyRef ref, const float* pos, float* close
}
dtPolyRef dtNavMesh::findNearestPolyInTile(const dtMeshTile* tile,
const float* center, const float* extents,
const float* center, const float* halfExtents,
float* nearestPt) const
{
float bmin[3], bmax[3];
dtVsub(bmin, center, extents);
dtVadd(bmax, center, extents);
dtVsub(bmin, center, halfExtents);
dtVadd(bmax, center, halfExtents);
// Get nearby polygons from proximity grid.
dtPolyRef polys[128];

View File

@ -759,7 +759,7 @@ public:
/// return #DT_SUCCESS, but @p nearestRef will be zero. So if in doubt, check
/// @p nearestRef before using @p nearestPt.
///
dtStatus dtNavMeshQuery::findNearestPoly(const float* center, const float* extents,
dtStatus dtNavMeshQuery::findNearestPoly(const float* center, const float* halfExtents,
const dtQueryFilter* filter,
dtPolyRef* nearestRef, float* nearestPt) const
{
@ -770,7 +770,7 @@ dtStatus dtNavMeshQuery::findNearestPoly(const float* center, const float* exten
dtFindNearestPolyQuery query(this, center);
dtStatus status = queryPolygons(center, extents, filter, &query);
dtStatus status = queryPolygons(center, halfExtents, filter, &query);
if (dtStatusFailed(status))
return status;
@ -943,7 +943,7 @@ public:
/// be filled to capacity. The method of choosing which polygons from the
/// full set are included in the partial result set is undefined.
///
dtStatus dtNavMeshQuery::queryPolygons(const float* center, const float* extents,
dtStatus dtNavMeshQuery::queryPolygons(const float* center, const float* halfExtents,
const dtQueryFilter* filter,
dtPolyRef* polys, int* polyCount, const int maxPolys) const
{
@ -952,7 +952,7 @@ dtStatus dtNavMeshQuery::queryPolygons(const float* center, const float* extents
dtCollectPolysQuery collector(polys, maxPolys);
dtStatus status = queryPolygons(center, extents, filter, &collector);
dtStatus status = queryPolygons(center, halfExtents, filter, &collector);
if (dtStatusFailed(status))
return status;
@ -963,21 +963,21 @@ dtStatus dtNavMeshQuery::queryPolygons(const float* center, const float* extents
/// @par
///
/// The query will be invoked with batches of polygons. Polygons passed
/// to the query have bounding boxes that overlap with the center and extents
/// to the query have bounding boxes that overlap with the center and halfExtents
/// passed to this function. The dtPolyQuery::process function is invoked multiple
/// times until all overlapping polygons have been processed.
///
dtStatus dtNavMeshQuery::queryPolygons(const float* center, const float* extents,
dtStatus dtNavMeshQuery::queryPolygons(const float* center, const float* halfExtents,
const dtQueryFilter* filter, dtPolyQuery* query) const
{
dtAssert(m_nav);
if (!center || !extents || !filter || !query)
if (!center || !halfExtents || !filter || !query)
return DT_FAILURE | DT_INVALID_PARAM;
float bmin[3], bmax[3];
dtVsub(bmin, center, extents);
dtVadd(bmax, center, extents);
dtVsub(bmin, center, halfExtents);
dtVadd(bmax, center, halfExtents);
// Find tiles the query touches.
int minx, miny, maxx, maxy;

View File

@ -217,7 +217,7 @@ class dtCrowd
dtPolyRef* m_pathResult;
int m_maxPathResult;
float m_ext[3];
float m_agentPlacementHalfExtents[3];
dtQueryFilter m_filters[DT_CROWD_MAX_QUERY_FILTER_TYPE];
@ -325,9 +325,13 @@ public:
/// @return The filter used by the crowd.
inline dtQueryFilter* getEditableFilter(const int i) { return (i >= 0 && i < DT_CROWD_MAX_QUERY_FILTER_TYPE) ? &m_filters[i] : 0; }
/// Gets the search extents [(x, y, z)] used by the crowd for query operations.
/// @return The search extents used by the crowd. [(x, y, z)]
const float* getQueryExtents() const { return m_ext; }
/// Gets the search halfExtents [(x, y, z)] used by the crowd for query operations.
/// @return The search halfExtents used by the crowd. [(x, y, z)]
const float* getQueryHalfExtents() const { return m_agentPlacementHalfExtents; }
/// Same as getQueryHalfExtents. Left to maintain backwards compatibility.
/// @return The search halfExtents used by the crowd. [(x, y, z)]
const float* getQueryExtents() const { return m_agentPlacementHalfExtents; }
/// Gets the velocity sample count.
/// @return The velocity sample count.

View File

@ -386,7 +386,8 @@ bool dtCrowd::init(const int maxAgents, const float maxAgentRadius, dtNavMesh* n
m_maxAgents = maxAgents;
m_maxAgentRadius = maxAgentRadius;
dtVset(m_ext, m_maxAgentRadius*2.0f,m_maxAgentRadius*1.5f,m_maxAgentRadius*2.0f);
// Larger than agent radius because it is also used for agent recovery.
dtVset(m_agentPlacementHalfExtents, m_maxAgentRadius*2.0f, m_maxAgentRadius*1.5f, m_maxAgentRadius*2.0f);
m_grid = dtAllocProximityGrid();
if (!m_grid)
@ -531,7 +532,7 @@ int dtCrowd::addAgent(const float* pos, const dtCrowdAgentParams* params)
float nearest[3];
dtPolyRef ref = 0;
dtVcopy(nearest, pos);
dtStatus status = m_navquery->findNearestPoly(pos, m_ext, &m_filters[ag->params.queryFilterType], &ref, nearest);
dtStatus status = m_navquery->findNearestPoly(pos, m_agentPlacementHalfExtents, &m_filters[ag->params.queryFilterType], &ref, nearest);
if (dtStatusFailed(status))
{
dtVcopy(nearest, pos);
@ -965,7 +966,7 @@ void dtCrowd::checkPathValidity(dtCrowdAgent** agents, const int nagents, const
float nearest[3];
dtVcopy(nearest, agentPos);
agentRef = 0;
m_navquery->findNearestPoly(ag->npos, m_ext, &m_filters[ag->params.queryFilterType], &agentRef, nearest);
m_navquery->findNearestPoly(ag->npos, m_agentPlacementHalfExtents, &m_filters[ag->params.queryFilterType], &agentRef, nearest);
dtVcopy(agentPos, nearest);
if (!agentRef)
@ -1001,7 +1002,7 @@ void dtCrowd::checkPathValidity(dtCrowdAgent** agents, const int nagents, const
float nearest[3];
dtVcopy(nearest, ag->targetPos);
ag->targetRef = 0;
m_navquery->findNearestPoly(ag->targetPos, m_ext, &m_filters[ag->params.queryFilterType], &ag->targetRef, nearest);
m_navquery->findNearestPoly(ag->targetPos, m_agentPlacementHalfExtents, &m_filters[ag->params.queryFilterType], &ag->targetRef, nearest);
dtVcopy(ag->targetPos, nearest);
replan = true;
}

View File

@ -431,7 +431,7 @@ Behavior:
- The new position will be located in the adjusted corridor's first polygon.
The expected use case is that the desired position will be 'near' the current corridor. What is considered 'near'
depends on local polygon density, query search extents, etc.
depends on local polygon density, query search half extents, etc.
The resulting position will differ from the desired position if the desired position is not on the navigation mesh,
or it can't be reached using a local search.
@ -470,7 +470,7 @@ Behavior:
- The corridor is automatically adjusted (shorted or lengthened) in order to remain valid.
- The new target will be located in the adjusted corridor's last polygon.
The expected use case is that the desired target will be 'near' the current corridor. What is considered 'near' depends on local polygon density, query search extents, etc.
The expected use case is that the desired target will be 'near' the current corridor. What is considered 'near' depends on local polygon density, query search half extents, etc.
The resulting target will differ from the desired target if the desired target is not on the navigation mesh, or it can't be reached using a local search.
*/

View File

@ -58,7 +58,7 @@ struct dtObstacleBox
struct dtObstacleOrientedBox
{
float center[ 3 ];
float extents[ 3 ];
float halfExtents[ 3 ];
float rotAux[ 2 ]; //{ cos(0.5f*angle)*sin(-0.5f*angle); cos(0.5f*angle)*cos(0.5f*angle) - 0.5 }
};
@ -146,7 +146,7 @@ public:
dtStatus addBoxObstacle(const float* bmin, const float* bmax, dtObstacleRef* result);
// Box obstacle: can be rotated in Y.
dtStatus addBoxObstacle(const float* center, const float* extents, const float yRadians, dtObstacleRef* result);
dtStatus addBoxObstacle(const float* center, const float* halfExtents, const float yRadians, dtObstacleRef* result);
dtStatus removeObstacle(const dtObstacleRef ref);

View File

@ -131,7 +131,7 @@ dtStatus dtMarkBoxArea(dtTileCacheLayer& layer, const float* orig, const float c
const float* bmin, const float* bmax, const unsigned char areaId);
dtStatus dtMarkBoxArea(dtTileCacheLayer& layer, const float* orig, const float cs, const float ch,
const float* center, const float* extents, const float* rotAux, const unsigned char areaId);
const float* center, const float* halfExtents, const float* rotAux, const unsigned char areaId);
dtStatus dtBuildTileCacheRegions(dtTileCacheAlloc* alloc,
dtTileCacheLayer& layer,

View File

@ -420,7 +420,7 @@ dtStatus dtTileCache::addBoxObstacle(const float* bmin, const float* bmax, dtObs
return DT_SUCCESS;
}
dtStatus dtTileCache::addBoxObstacle(const float* center, const float* extents, const float yRadians, dtObstacleRef* result)
dtStatus dtTileCache::addBoxObstacle(const float* center, const float* halfExtents, const float yRadians, dtObstacleRef* result)
{
if (m_nreqs >= MAX_REQUESTS)
return DT_FAILURE | DT_BUFFER_TOO_SMALL;
@ -441,7 +441,7 @@ dtStatus dtTileCache::addBoxObstacle(const float* center, const float* extents,
ob->state = DT_OBSTACLE_PROCESSING;
ob->type = DT_OBSTACLE_ORIENTED_BOX;
dtVcopy(ob->orientedBox.center, center);
dtVcopy(ob->orientedBox.extents, extents);
dtVcopy(ob->orientedBox.halfExtents, halfExtents);
float coshalf= cosf(0.5f*yRadians);
float sinhalf = sinf(-0.5f*yRadians);
@ -694,7 +694,7 @@ dtStatus dtTileCache::buildNavMeshTile(const dtCompressedTileRef ref, dtNavMesh*
else if (ob->type == DT_OBSTACLE_ORIENTED_BOX)
{
dtMarkBoxArea(*bc.layer, tile->header->bmin, m_params.cs, m_params.ch,
ob->orientedBox.center, ob->orientedBox.extents, ob->orientedBox.rotAux, 0);
ob->orientedBox.center, ob->orientedBox.halfExtents, ob->orientedBox.rotAux, 0);
}
}
}
@ -809,11 +809,11 @@ void dtTileCache::getObstacleBounds(const struct dtTileCacheObstacle* ob, float*
{
const dtObstacleOrientedBox &orientedBox = ob->orientedBox;
float maxr = 1.41f*dtMax(orientedBox.extents[0], orientedBox.extents[2]);
float maxr = 1.41f*dtMax(orientedBox.halfExtents[0], orientedBox.halfExtents[2]);
bmin[0] = orientedBox.center[0] - maxr;
bmax[0] = orientedBox.center[0] + maxr;
bmin[1] = orientedBox.center[1] - orientedBox.extents[1];
bmax[1] = orientedBox.center[1] + orientedBox.extents[1];
bmin[1] = orientedBox.center[1] - orientedBox.halfExtents[1];
bmax[1] = orientedBox.center[1] + orientedBox.halfExtents[1];
bmin[2] = orientedBox.center[2] - maxr;
bmax[2] = orientedBox.center[2] + maxr;
}

View File

@ -2042,7 +2042,7 @@ dtStatus dtMarkBoxArea(dtTileCacheLayer& layer, const float* orig, const float c
}
dtStatus dtMarkBoxArea(dtTileCacheLayer& layer, const float* orig, const float cs, const float ch,
const float* center, const float* extents, const float* rotAux, const unsigned char areaId)
const float* center, const float* halfExtents, const float* rotAux, const unsigned char areaId)
{
const int w = (int)layer.header->width;
const int h = (int)layer.header->height;
@ -2052,13 +2052,13 @@ dtStatus dtMarkBoxArea(dtTileCacheLayer& layer, const float* orig, const float c
float cx = (center[0] - orig[0])*ics;
float cz = (center[2] - orig[2])*ics;
float maxr = 1.41f*dtMax(extents[0], extents[2]);
float maxr = 1.41f*dtMax(halfExtents[0], halfExtents[2]);
int minx = (int)floorf(cx - maxr*ics);
int maxx = (int)floorf(cx + maxr*ics);
int minz = (int)floorf(cz - maxr*ics);
int maxz = (int)floorf(cz + maxr*ics);
int miny = (int)floorf((center[1]-extents[1]-orig[1])*ich);
int maxy = (int)floorf((center[1]+extents[1]-orig[1])*ich);
int miny = (int)floorf((center[1]-halfExtents[1]-orig[1])*ich);
int maxy = (int)floorf((center[1]+halfExtents[1]-orig[1])*ich);
if (maxx < 0) return DT_SUCCESS;
if (minx >= w) return DT_SUCCESS;
@ -2070,8 +2070,8 @@ dtStatus dtMarkBoxArea(dtTileCacheLayer& layer, const float* orig, const float c
if (minz < 0) minz = 0;
if (maxz >= h) maxz = h-1;
float xhalf = extents[0]*ics + 0.5f;
float zhalf = extents[2]*ics + 0.5f;
float xhalf = halfExtents[0]*ics + 0.5f;
float zhalf = halfExtents[2]*ics + 0.5f;
for (int z = minz; z <= maxz; ++z)
{

View File

@ -31,7 +31,7 @@ protected:
rcContourSet* m_cset;
rcPolyMesh* m_pmesh;
float m_ext[3];
float m_halfExtents[3];
float m_center[3];
float m_bmin[3], m_bmax[3];
dtPolyRef m_ref;

View File

@ -248,7 +248,7 @@ void ConvexVolumeTool::handleRender()
{
duDebugDraw& dd = m_sample->getDebugDraw();
// Find height extents of the shape.
// Find height extent of the shape.
float minh = FLT_MAX, maxh = 0;
for (int i = 0; i < m_npts; ++i)
minh = rcMin(minh, m_pts[i*3+1]);

View File

@ -712,7 +712,7 @@ void CrowdToolState::setMoveTarget(const float* p, bool adjust)
dtNavMeshQuery* navquery = m_sample->getNavMeshQuery();
dtCrowd* crowd = m_sample->getCrowd();
const dtQueryFilter* filter = crowd->getFilter(0);
const float* ext = crowd->getQueryExtents();
const float* halfExtents = crowd->getQueryExtents();
if (adjust)
{
@ -740,7 +740,7 @@ void CrowdToolState::setMoveTarget(const float* p, bool adjust)
}
else
{
navquery->findNearestPoly(p, ext, filter, &m_targetRef, m_targetPos);
navquery->findNearestPoly(p, halfExtents, filter, &m_targetRef, m_targetPos);
if (m_agentDebug.idx != -1)
{
@ -1032,10 +1032,10 @@ void CrowdTool::handleClick(const float* s, const float* p, bool shift)
if (nav && navquery)
{
dtQueryFilter filter;
const float* ext = crowd->getQueryExtents();
const float* halfExtents = crowd->getQueryExtents();
float tgt[3];
dtPolyRef ref;
navquery->findNearestPoly(p, ext, &filter, &ref, tgt);
navquery->findNearestPoly(p, halfExtents, &filter, &ref, tgt);
if (ref)
{
unsigned short flags = 0;

View File

@ -252,10 +252,10 @@ void NavMeshPruneTool::handleClick(const float* s, const float* p, bool shift)
m_flags->init(nav);
}
const float ext[3] = {2,4,2};
const float halfExtents[3] = { 2, 4, 2 };
dtQueryFilter filter;
dtPolyRef ref = 0;
query->findNearestPoly(p, ext, &filter, &ref, 0);
query->findNearestPoly(p, halfExtents, &filter, &ref, 0);
floodNavmesh(nav, m_flags, ref, 1);
}

View File

@ -124,12 +124,12 @@ Sample_Debug::Sample_Debug() :
m_navMesh->addTileAt(-14,-14, data, dataSize, true);
}
const float ext[3] = {40,100,40};
const float halfExtents[3] = {40,100,40};
const float center[3] = { -1667.9491f, 135.52649f, -1680.6149f };
dtQueryFilter filter;
m_ref = m_navMesh->findNearestPoly(center, ext, &filter, 0);
m_ref = m_navMesh->findNearestPoly(center, halfExtents, &filter, 0);
vcopy(m_ext, ext);
vcopy(m_halfExtents, halfExtents);
vcopy(m_center, center);*/
@ -204,8 +204,8 @@ void Sample_Debug::handleRender()
duDebugDrawNavMeshPoly(&m_dd, *m_navMesh, m_ref, duRGBA(255,0,0,128));
/* float bmin[3], bmax[3];
rcVsub(bmin, m_center, m_ext);
rcVadd(bmax, m_center, m_ext);
rcVsub(bmin, m_center, m_halfExtents);
rcVadd(bmax, m_center, m_halfExtents);
duDebugDrawBoxWire(&dd, bmin[0],bmin[1],bmin[2], bmax[0],bmax[1],bmax[2], duRGBA(255,255,255,128), 1.0f);
duDebugDrawCross(&dd, m_center[0], m_center[1], m_center[2], 1.0f, duRGBA(255,255,255,128), 2.0f);*/