Make smooth triangle normal computation more robust

This commit is contained in:
Daniel Chappuis 2020-05-26 18:22:17 +02:00
parent 5c736565a7
commit 4351081189

View File

@ -210,7 +210,16 @@ Vector3 TriangleShape::computeSmoothLocalContactNormalForTriangle(const Vector3&
}
// We compute the contact normal as the barycentric interpolation of the three vertices normals
return (u * mVerticesNormals[0] + v * mVerticesNormals[1] + w * mVerticesNormals[2]).getUnit();
Vector3 interpolatedNormal = u * mVerticesNormals[0] + v * mVerticesNormals[1] + w * mVerticesNormals[2];
// If the interpolated normal is degenerated
if (interpolatedNormal.lengthSquare() < MACHINE_EPSILON) {
// Return the original normal
return mNormal;
}
return interpolatedNormal.getUnit();
}
// Update the AABB of a body using its collision shape