public bool Find() { if (Result != IntersectionResult.NotComputed) { return(Result == IntersectionResult.Intersects); } // [RMS] if either line direction is not a normalized vector, // results are garbage, so fail query if (ray.Direction.IsNormalized == false) { Type = IntersectionType.Empty; Result = IntersectionResult.InvalidQuery; return(false); } RayParam0 = 0.0; RayParam1 = double.MaxValue; IntrLine3AxisAlignedBox3.DoClipping(ref RayParam0, ref RayParam1, ref ray.Origin, ref ray.Direction, ref box, true, ref Quantity, ref Point0, ref Point1, ref Type); Result = (Type != IntersectionType.Empty) ? IntersectionResult.Intersects : IntersectionResult.NoIntersection; return(Result == IntersectionResult.Intersects); }
/// <summary> /// Find intersection of ray with AABB, without having to construct any new classes. /// Returns ray T-value of first intersection (or double.MaxVlaue on miss) /// </summary> public static bool FindRayIntersectT(ref Ray3d ray, ref AxisAlignedBox3d box, out double RayParam) { double RayParam0 = 0.0; double RayParam1 = double.MaxValue; int Quantity = 0; Vector3d Point0 = Vector3d.Zero; Vector3d Point1 = Vector3d.Zero; IntersectionType Type = IntersectionType.Empty; IntrLine3AxisAlignedBox3.DoClipping(ref RayParam0, ref RayParam1, ref ray.Origin, ref ray.Direction, ref box, true, ref Quantity, ref Point0, ref Point1, ref Type); if (Type != IntersectionType.Empty) { RayParam = RayParam0; return(true); } else { RayParam = double.MaxValue; return(false); } }