예제 #1
0
 private double? testRay(Ray ray, Scene scene) 
 {
     var isect = this.intersections(ray, scene);
     if (isect != null) 
     {
         return isect.dist;
     } 
     else 
     {
         return null;
     }
 }
예제 #2
0
 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);
     }
 }
예제 #3
0
 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;
 }
예제 #4
0
 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);
     }
 }
예제 #5
0
 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);
     }
 }
예제 #6
0
 abstract public Intersection intersect(Ray ray);
예제 #7
0
 public Intersection(Thing thing, Ray ray, double dist)
 {
     this.thing = thing;
     this.ray = ray;
     this.dist = dist;
 }