diff --git a/GodotHelper/src/Math/Planes.cs b/GodotHelper/src/Math/Planes.cs new file mode 100644 index 0000000..7121ef7 --- /dev/null +++ b/GodotHelper/src/Math/Planes.cs @@ -0,0 +1,14 @@ +namespace GodotHelpers; + +using Godot; +public static partial class SJKMath +{ + public static Vector3? MouseToPlane(this Plane plane, Camera3D viewCamera, Vector2? mousePos = null) + { + var from = viewCamera.ProjectRayOrigin( mousePos ?? viewCamera.GetViewport().GetMousePosition()); + var normal = viewCamera.ProjectRayNormal(mousePos ?? viewCamera.GetViewport().GetMousePosition()); + return plane.IntersectsRay(from, normal); + } + public static Vector3? MouseToGroundPlane(this Camera3D viewCamera, Vector2? mousePos = null, float offset = 0) => + (Plane.PlaneXZ with { D = offset }).MouseToPlane(viewCamera, mousePos); +}