From 5fcf9db59cf0f8c26acf9be4e29bb20187720b02 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Sun, 6 Oct 2024 10:55:56 +0100 Subject: [PATCH] Add sphere to sphere intersection test --- KeepersCompound.Lightmapper/MathUtils.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/KeepersCompound.Lightmapper/MathUtils.cs b/KeepersCompound.Lightmapper/MathUtils.cs index 13a418a..4a82249 100644 --- a/KeepersCompound.Lightmapper/MathUtils.cs +++ b/KeepersCompound.Lightmapper/MathUtils.cs @@ -49,6 +49,12 @@ public static class MathUtils return d2 < r2; } + public static bool Intersects(Sphere sphere, Sphere other) + { + var rsum = sphere.Radius + other.Radius; + return (sphere.Position - other.Position).Length() <= rsum; + } + public static float DistanceFromPlane(Plane plane, Vector3 point) { return Math.Abs(Vector3.Dot(plane.Normal, point) + plane.D) / plane.Normal.Length();