Recast: move surface area quantization into its own function

Avoid potential mistakes in the future by using the wrong quant factor.
This commit is contained in:
Kawe Mazidjatari 2024-08-28 13:47:21 +02:00
parent 4f72c9aee8
commit f9fb1c6c64
3 changed files with 8 additions and 2 deletions

View File

@ -273,6 +273,7 @@ struct dtPoly
/// @param[in] verts The polygon vertices.
/// @return The total surface are of the polygon.
float dtCalcPolySurfaceArea(const dtPoly* poly, const float* verts);
unsigned short dtQuantPolySurfaceArea(const float area);
/// Defines the location of detail sub-mesh data within a dtMeshTile.
struct dtPolyDetail

View File

@ -1865,7 +1865,7 @@ float dtCalcLinkDistance(const float* spos, const float* epos)
unsigned char dtQuantLinkDistance(const float distance)
{
if (distance > DT_TRAVERSE_DIST_MAX) return (unsigned char)0;
return (unsigned char)(distance * DT_TRAVERSE_DIST_QUANT_FACTOR);
return (unsigned char)(rdMathRoundf(distance * DT_TRAVERSE_DIST_QUANT_FACTOR));
}
float dtCalcPolySurfaceArea(const dtPoly* poly, const float* verts)
@ -1885,6 +1885,11 @@ float dtCalcPolySurfaceArea(const dtPoly* poly, const float* verts)
return polyArea;
}
unsigned short dtQuantPolySurfaceArea(const float area)
{
return (unsigned short)rdMathRoundf(area * DT_POLY_AREA_QUANT_FACTOR);
}
float dtCalcOffMeshRefYaw(const float* spos, const float* epos)
{
const float dx = epos[0]-spos[0];

View File

@ -1050,7 +1050,7 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData,
p->vertCount++;
}
rdVscale(p->center, p->center, 1 / (float)(p->vertCount));
p->surfaceArea = (unsigned short)rdMathFloorf(dtCalcPolySurfaceArea(p,navVerts) * DT_POLY_AREA_QUANT_FACTOR);
p->surfaceArea = dtQuantPolySurfaceArea(dtCalcPolySurfaceArea(p,navVerts));
src += nvp*2;
}