Recast: fix several bugs related to off-mesh connections

- Off-mesh connections should always be linked to target poly's first. Also set the linked flag on titanfall navmeshes as this is necessary during the pruning stage.
- When connecting off-mesh links, we need to iterate over tiles using m_maxTiles, not m_tileCount as m_tileCount counts the number of added tiles, while m_maxTiles contains the maximum tiles in the lookup array, there can be empties in between.
- Radians to degrees and visa versa has been moved to a simple inline function, but during this, a regression was made where it was accidentally inverted in dtCalcOffMeshRefYaw and dtCalcOffMeshRefPos.
This commit is contained in:
Kawe Mazidjatari 2024-10-19 11:51:24 +02:00
parent 49907272fb
commit e62051eff3

View File

@ -620,8 +620,12 @@ dtStatus dtNavMesh::connectOffMeshLinks(const dtTileRef tileRef)
con->setTraverseType(traverseType, 0);
#endif
// Link off-mesh connection to target poly.
if (!connectOffMeshLink(tile, conPoly, basePolyRef, 0xff, 0, DT_NULL_TRAVERSE_TYPE, 0))
return DT_FAILURE | DT_OUT_OF_MEMORY;
// Start end-point is always connect back to off-mesh connection.
const unsigned short basePolyIdx = (unsigned short)decodePolyIdPoly(basePolyRef);
const unsigned int basePolyIdx = decodePolyIdPoly(basePolyRef);
dtPoly* basePoly = &tile->polys[basePolyIdx];
const dtPolyRef conPolyRef = base | (dtPolyRef)(con->poly);
@ -630,10 +634,6 @@ dtStatus dtNavMesh::connectOffMeshLinks(const dtTileRef tileRef)
invertVertLookup ? DT_OFFMESH_CON_TRAVERSE_ON_VERT : DT_OFFMESH_CON_TRAVERSE_ON_POLY))
return DT_FAILURE | DT_OUT_OF_MEMORY;
// Link off-mesh connection to target poly.
if (!connectOffMeshLink(tile, conPoly, basePolyRef, 0xff, 0, DT_NULL_TRAVERSE_TYPE, 0))
return DT_FAILURE | DT_OUT_OF_MEMORY;
// connect to land points.
const float halfExtents[3] = { con->rad, con->rad, header->walkableClimb };
float bmin[3], bmax[3];
@ -679,10 +679,9 @@ dtStatus dtNavMesh::connectOffMeshLinks(const dtTileRef tileRef)
return DT_FAILURE | DT_OUT_OF_MEMORY;
}
#if DT_NAVMESH_SET_VERSION >= 7
// Off-mesh link is fully linked, mark it.
conPoly->flags |= DT_POLYFLAGS_JUMP_LINKED;
#endif
// All links have been established, break out entirely.
break;
}
@ -1743,7 +1742,7 @@ dtStatus dtNavMesh::removeTile(dtTileRef ref, unsigned char** data, int* dataSiz
}
// Disconnect from off-mesh links originating from other tiles.
for (int i = 0; i < m_tileCount; ++i)
for (int i = 0; i < m_maxTiles; ++i)
{
dtMeshTile* offTile = &m_tiles[i];
@ -2182,16 +2181,16 @@ float dtCalcOffMeshRefYaw(const float* spos, const float* epos)
const float dx = epos[0]-spos[0];
const float dy = epos[1]-spos[1];
const float yawDeg = rdMathAtan2f(dy, dx);
return rdDegToRad(yawDeg);
const float yawRad = rdMathAtan2f(dy, dx);
return rdRadToDeg(yawRad);
}
void dtCalcOffMeshRefPos(const float* spos, float yawRad, float offset, float* res)
void dtCalcOffMeshRefPos(const float* spos, float yawDeg, float offset, float* res)
{
const float yawDeg = rdRadToDeg(yawRad);
const float yawRad = rdDegToRad(yawDeg);
const float dx = offset*rdMathCosf(yawDeg);
const float dy = offset*rdMathSinf(yawDeg);
const float dx = offset*rdMathCosf(yawRad);
const float dy = offset*rdMathSinf(yawRad);
res[0] = spos[0]+dx;
res[1] = spos[1]+dy;