Recast: fix missed XZY -> XYZ conversions in dtNavMeshQuery

ZY needs to be flipped for YZ, previously the function would never find a poly as the reservoir sampler always failed (polyArea was always a large negative number).
This commit is contained in:
Kawe Mazidjatari 2024-07-10 11:12:13 +02:00
parent df94ba0314
commit 11a827d548

View File

@ -235,7 +235,7 @@ dtStatus dtNavMeshQuery::findRandomPoint(const dtQueryFilter* filter, float (*fr
const dtMeshTile* t = m_nav->getTile(i);
if (!t || !t->header) continue;
// Choose random tile using reservoi sampling.
// Choose random tile using reservoir sampling.
const float area = 1.0f; // Could be tile area too.
tsum += area;
const float u = frand();
@ -267,12 +267,12 @@ dtStatus dtNavMeshQuery::findRandomPoint(const dtQueryFilter* filter, float (*fr
for (int j = 2; j < p->vertCount; ++j)
{
const float* va = &tile->verts[p->verts[0]*3];
const float* vb = &tile->verts[p->verts[j-1]*3];
const float* vc = &tile->verts[p->verts[j]*3];
const float* vb = &tile->verts[p->verts[j]*3];
const float* vc = &tile->verts[p->verts[j-1]*3];
polyArea += dtTriArea2D(va,vb,vc);
}
// Choose random polygon weighted by area, using reservoi sampling.
// Choose random polygon weighted by area, using reservoir sampling.
areaSum += polyArea;
const float u = frand();
if (u*areaSum <= polyArea)
@ -375,11 +375,11 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f
for (int j = 2; j < bestPoly->vertCount; ++j)
{
const float* va = &bestTile->verts[bestPoly->verts[0]*3];
const float* vb = &bestTile->verts[bestPoly->verts[j-1]*3];
const float* vc = &bestTile->verts[bestPoly->verts[j]*3];
const float* vb = &bestTile->verts[bestPoly->verts[j]*3];
const float* vc = &bestTile->verts[bestPoly->verts[j-1]*3];
polyArea += dtTriArea2D(va,vb,vc);
}
// Choose random polygon weighted by area, using reservoi sampling.
// Choose random polygon weighted by area, using reservoir sampling.
areaSum += polyArea;
const float u = frand();
if (u*areaSum <= polyArea)