private IEnumerable<ISect> Intersections(Ray ray, Scene scene) { return scene.Things .Select(obj => obj.Intersect(ray)) .Where(inter => inter != null) .OrderBy(inter => inter.Dist); }
private Color TraceRay(Ray ray, Scene scene, int depth) { var isects = Intersections(ray, scene); ISect isect = isects.FirstOrDefault(); if (isect == null) return Color.Background; return Shade(isect, scene, depth); }
private double TestRay(Ray ray, Scene scene) { var isects = Intersections(ray, scene); ISect isect = isects.FirstOrDefault(); if (isect == null) return 0; return isect.Dist; }
public IEnumerable<ISect> Intersect(Ray r) { return from thing in Things select thing.Intersect(r); }
public override ISect Intersect(Ray ray) { double denom = Vector.Dot(Norm, ray.Dir); if (denom > 0) return null; return new ISect() { Thing = this, Ray = ray, Dist = (Vector.Dot(Norm, ray.Start) + Offset) / (-denom)}; }
public override ISect Intersect(Ray ray) { Vector eo = Vector.Minus(Center, ray.Start); double v = Vector.Dot(eo, ray.Dir); double dist; if (v < 0) { dist = 0; } else { double disc = Math.Pow(Radius,2) - (Vector.Dot(eo, eo) - Math.Pow(v,2)); dist = disc < 0 ? 0 : v - Math.Sqrt(disc); } if (dist == 0) return null; return new ISect() { Thing = this, Ray = ray, Dist = dist}; }
public abstract ISect Intersect(Ray ray);