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