Recast: implement function for calculation sub edge area's

This commit is contained in:
Kawe Mazidjatari 2024-08-29 16:11:55 +02:00
parent 0b64e3bea1
commit 75ff8adfac
2 changed files with 31 additions and 0 deletions

View File

@ -488,6 +488,15 @@ void rdCalcEdgeNormal2D(const float* dir, const bool inner, float* out);
/// @param[out] out The resulting normal. [(x, y)]
void rdCalcEdgeNormalPt2D(const float* v1, const float* v2, const bool inner, float* out);
/// @param[in] edgeStart First vert of the polygon edge. [(x, y, z)]
/// @param[in] edgeEnd Second vert of the polygon edge. [(x, y, z)]
/// @param[in] subEdgeStart First vert of the detail edge. [(x, y, z)]
/// @param[in] subEdgeEnd Second vert of the detail edge. [(x, y, z)]
/// @param[out] tmin The normalized distance ratio from polygon edge start to detail edge start.
/// @param[out] tmax The normalized distance ratio from polygon edge start to detail edge end.
bool rdCalcSubEdgeArea2D(const float* edgeStart, const float* edgeEnd, const float* subEdgeStart,
const float* subEdgeEnd, float& tmin, float& tmax);
/// Derives the maximum angle in which an object on an elevated surface can be seen from below.
/// @param[in] ledgeSpan The distance between the edge of the object and the edge of the ledge.
/// @param[in] objectHeight The height of the object.

View File

@ -432,6 +432,28 @@ void rdCalcEdgeNormalPt2D(const float* v1, const float* v2, const bool invert, f
rdCalcEdgeNormal2D(dir, invert, out);
}
bool rdCalcSubEdgeArea2D(const float* edgeStart, const float* edgeEnd, const float* subEdgeStart,
const float* subEdgeEnd, float& tmin, float& tmax)
{
const float edgeLen = rdVdist2D(edgeStart, edgeEnd);
const float subEdgeStartDist = rdVdist2D(edgeStart, subEdgeStart);
const float subEdgeEndDist = rdVdist2D(edgeStart, subEdgeEnd);
tmin = subEdgeStartDist / edgeLen;
tmax = subEdgeEndDist / edgeLen;
// note(amos): If the min is larger than the max, we most likely have a
// malformed detail polygon, e.g. a triangle that is flipped causing its
// boundary edge's start vert to be closer to the end vert of the polygon
// when comparing the distances in the same winding order. This can happen
// on more complex geometry or when the error tollerance is raised. Either
// way return false to notify caller that the calculation has failed.
if (tmin > tmax)
return false;
return true;
}
float rdCalcMaxLOSAngle(const float ledgeSpan, const float objectHeight)
{
const float angleRad = rdMathAtan2f(objectHeight, ledgeSpan);