Ejemplo n.º 1
0
        public ITraceInformation CalculateIntersection(Ray line)
        {
            ITraceInformation bestHit = null;

            foreach (var triangle in GetTriangles())
            {
                var hit = triangle.CalculateIntersection(line);
                if (!hit.Intersects)
                {
                    continue;
                }

                if (bestHit == null)
                {
                    bestHit = hit;
                    continue;
                }

                if (hit.Distance < bestHit.Distance)
                {
                    bestHit = hit;
                }
            }
            if (bestHit == null)
            {
                return(new NoIntersection());
            }
            return(new Intersection(bestHit.IntersectionPosition, line, Material, this)
            {
                Normal = bestHit.Normal
            });
        }
Ejemplo n.º 2
0
        public ITraceInformation Trace(Ray ray)
        {
            ITraceInformation closestHit = null;

            foreach (var entity in this)
            {
                var hitInfo = entity.CalculateIntersection(ray);
                if (!hitInfo.Intersects)
                {
                    continue;
                }
                if (closestHit == null)
                {
                    closestHit = hitInfo;
                    continue;
                }

                if (hitInfo.Distance < closestHit.Distance)
                {
                    closestHit = hitInfo;
                }
            }
            return(closestHit ?? new NoIntersection());
        }