This commit is contained in:
aozhiwei 2020-08-14 15:52:22 +08:00
parent ef0938fb26
commit 3fdf02a816
2 changed files with 40 additions and 36 deletions

View File

@ -107,3 +107,41 @@ void NavMeshHelper::OutputObjFile(MapInstance* map_instance)
fclose(fp);
}
}
static bool checkOverlapRect(const float amin[2], const float amax[2],
const float bmin[2], const float bmax[2])
{
bool overlap = true;
overlap = (amin[0] > bmax[0] || amax[0] < bmin[0]) ? false : overlap;
overlap = (amin[1] > bmax[1] || amax[1] < bmin[1]) ? false : overlap;
return overlap;
}
int rcGetChunksOverlappingRect(const rcChunkyTriMesh* cm,
float bmin[2], float bmax[2],
int* ids, const int maxIds)
{
// Traverse tree
int i = 0;
int n = 0;
while (i < cm->nnodes) {
const rcChunkyTriMeshNode* node = &cm->nodes[i];
const bool overlap = checkOverlapRect(bmin, bmax, node->bmin, node->bmax);
const bool isLeafNode = node->i >= 0;
if (isLeafNode && overlap) {
if (n < maxIds) {
ids[n] = i;
n++;
}
}
if (overlap || isLeafNode)
i++;
else {
const int escapeIndex = -node->i;
i += escapeIndex;
}
}
return n;
}

View File

@ -74,43 +74,9 @@ struct ConvexVolume
rcAreaModification areaMod;
};
inline bool checkOverlapRect(const float amin[2], const float amax[2],
const float bmin[2], const float bmax[2])
{
bool overlap = true;
overlap = (amin[0] > bmax[0] || amax[0] < bmin[0]) ? false : overlap;
overlap = (amin[1] > bmax[1] || amax[1] < bmin[1]) ? false : overlap;
return overlap;
}
inline int rcGetChunksOverlappingRect(const rcChunkyTriMesh* cm,
int rcGetChunksOverlappingRect(const rcChunkyTriMesh* cm,
float bmin[2], float bmax[2],
int* ids, const int maxIds)
{
// Traverse tree
int i = 0;
int n = 0;
while (i < cm->nnodes) {
const rcChunkyTriMeshNode* node = &cm->nodes[i];
const bool overlap = checkOverlapRect(bmin, bmax, node->bmin, node->bmax);
const bool isLeafNode = node->i >= 0;
if (isLeafNode && overlap) {
if (n < maxIds) {
ids[n] = i;
n++;
}
}
if (overlap || isLeafNode)
i++;
else {
const int escapeIndex = -node->i;
i += escapeIndex;
}
}
return n;
}
int* ids, const int maxIds);
struct RasterizationContext
{