findWallDistance uses bitangent to the poly edge itself, rather than vector to the agent, for returned normal

This commit is contained in:
Richard Fine
2017-10-14 20:35:33 +02:00
committed by Jakob Botsch Nielsen
parent a07fbdca25
commit a89774ae84
+15 -2
View File
@@ -3473,6 +3473,8 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
float radiusSqr = dtSqr(maxRadius);
dtStatus status = DT_SUCCESS;
const float *bestvj = 0, *bestvi = 0;
while (!m_openList->empty())
{
@@ -3547,6 +3549,8 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
hitPos[0] = vj[0] + (vi[0] - vj[0])*tseg;
hitPos[1] = vj[1] + (vi[1] - vj[1])*tseg;
hitPos[2] = vj[2] + (vi[2] - vj[2])*tseg;
bestvj = vj;
bestvi = vi;
}
for (unsigned int i = bestPoly->firstLink; i != DT_NULL_LINK; i = bestTile->links[i].next)
@@ -3620,8 +3624,17 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
}
// Calc hit normal.
dtVsub(hitNormal, centerPos, hitPos);
dtVnormalize(hitNormal);
if(bestvj && bestvi)
{
float tangent[3];
dtVsub(tangent, bestvi, bestvj);
hitNormal[0] = tangent[2];
hitNormal[1] = 0;
hitNormal[2] = -tangent[0];
dtVnormalize(hitNormal);
}
*hitDist = dtMathSqrtf(radiusSqr);