public static bool GetRayPlaneIntersection(ref Ray ray, ref Plane p, out float t, out Vector3 q)
{
float denominator;
Vector3.Dot(ref p.Normal, ref ray.Direction, out denominator);
if (denominator < Epsilon && denominator > -Epsilon)
{
//Surface of plane and line are parallel (or very close to it).
q = new Vector3();
t = float.MaxValue;
return false;
}
float numerator;
Vector3.Dot(ref p.Normal, ref ray.Position, out numerator);
t = (p.D - numerator) / denominator;
//Compute the intersection position.
Vector3.Multiply(ref ray.Direction, t, out q);
Vector3.Add(ref ray.Position, ref q, out q);
return t >= 0;
}