Use faster plane distance calculation

This commit is contained in:
Jarrod Doyle 2025-01-27 18:07:59 +00:00
parent e48393b856
commit 54655254b9
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
2 changed files with 7 additions and 2 deletions

View File

@ -163,7 +163,7 @@ public class PotentiallyVisibleSet
var validTarget = false; var validTarget = false;
foreach (var v in target.Poly.Vertices) foreach (var v in target.Poly.Vertices)
{ {
if (MathUtils.DistanceFromPlane(sourcePlane, v) < -MathUtils.Epsilon) if (MathUtils.DistanceFromNormalizedPlane(sourcePlane, v) < -MathUtils.Epsilon)
{ {
validTarget = true; validTarget = true;
break; break;
@ -178,7 +178,7 @@ public class PotentiallyVisibleSet
validTarget = false; validTarget = false;
foreach (var v in source.Poly.Vertices) foreach (var v in source.Poly.Vertices)
{ {
if (MathUtils.DistanceFromPlane(targetPlane, v) > MathUtils.Epsilon) if (MathUtils.DistanceFromNormalizedPlane(targetPlane, v) > MathUtils.Epsilon)
{ {
validTarget = true; validTarget = true;
break; break;

View File

@ -93,6 +93,11 @@ public static class MathUtils
return (Vector3.Dot(plane.Normal, point) + plane.D) / plane.Normal.Length(); return (Vector3.Dot(plane.Normal, point) + plane.D) / plane.Normal.Length();
} }
public static float DistanceFromNormalizedPlane(Plane plane, Vector3 point)
{
return Vector3.Dot(plane.Normal, point) + plane.D;
}
public static bool IsCoplanar(Plane p0, Plane p1) public static bool IsCoplanar(Plane p0, Plane p1)
{ {
var m = p0.D / p1.D; var m = p0.D / p1.D;