private double? testRay(Ray ray, Scene scene) { var isect = this.intersections(ray, scene); if (isect != null) { return isect.dist; } else { return null; } }
private Color traceRay(Ray ray, Scene scene, double depth) { var isect = this.intersections(ray, scene); if (isect == null) { return Color.background; } else { return this.shade(isect, scene, depth); } }
private Intersection intersections(Ray ray, Scene scene) { var closest = double.PositiveInfinity; Intersection closestInter = null; foreach (var i in scene.things) { var inter = i.intersect(ray); if (inter != null && inter.dist < closest) { closestInter = inter; closest = inter.dist; } } return closestInter; }
public override Intersection intersect(Ray ray) { var denom = Vector.dot(norm, ray.dir); if (denom > 0) { return null; } else { var dist = (Vector.dot(norm, ray.start) + offset) / (-denom); return new Intersection(this, ray, dist); } }
public override Intersection intersect(Ray ray) { var eo = Vector.minus(this.center, ray.start); var v = Vector.dot(eo, ray.dir); var dist = 0.0; if (v >= 0) { var disc = this.radius2 - (Vector.dot(eo, eo) - v * v); if (disc >= 0) { dist = v - Math.Sqrt(disc); } } if (dist == 0) { return null; } else { return new Intersection(this, ray, dist); } }
abstract public Intersection intersect(Ray ray);
public Intersection(Thing thing, Ray ray, double dist) { this.thing = thing; this.ray = ray; this.dist = dist; }