public IEnumerable IntersectionIterator(Ray ray) { if (ray.Intersection(Aabb)) { IRayTraceable checkFirst = nodeA; IRayTraceable checkSecond = nodeB; if (ray.directionNormal[splitingPlane] < 0) { checkFirst = nodeB; checkSecond = nodeA; } foreach (IntersectInfo info in checkFirst.IntersectionIterator(ray)) { if (info != null && info.hitType != IntersectionType.None) { yield return(info); } } if (checkSecond != null) { foreach (IntersectInfo info in checkSecond.IntersectionIterator(ray)) { if (info != null && info.hitType != IntersectionType.None) { yield return(info); } } } } }
public IntersectInfo GetClosestIntersection(Ray ray) { List <IntersectInfo> allPrimary = new List <IntersectInfo>(); Ray checkFrontAndBacks = new Ray(ray); checkFrontAndBacks.intersectionType = IntersectionType.Both; foreach (IntersectInfo info in primary.IntersectionIterator(checkFrontAndBacks)) { allPrimary.Add(info); } if (allPrimary.Count == 0) { // We did not hit the primary object. We are done. The subtract object does not mater. return(null); } allPrimary.Sort(new CompareIntersectInfoOnDistance()); // we hit the primary object, did we hit the subtract object before (within error) hitting the primary. List <IntersectInfo> allSubtract = new List <IntersectInfo>(); foreach (IntersectInfo info in subtract.IntersectionIterator(checkFrontAndBacks)) { allSubtract.Add(info); } if (allSubtract.Count == 0) { // we did not hit the subtract so return the first primary return(allPrimary[0]); } allSubtract.Sort(new CompareIntersectInfoOnDistance()); List <IntersectInfo> result = new List <IntersectInfo>(); IntersectInfo.Subtract(allPrimary, allSubtract, result); if (result.Count > 0) { return(result[0]); } return(null); }
public IEnumerable IntersectionIterator(Ray ray) { Ray localRay = GetLocalSpaceRay(ray); foreach (IntersectInfo localInfo in child.IntersectionIterator(localRay)) { IntersectInfo globalIntersection = GetGlobalSpaceInfo(localInfo); yield return(globalIntersection); } }