예제 #1
0
 public abstract ISect Intersect(Ray ray);
예제 #2
0
 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
                };
 }
예제 #3
0
 public IEnumerable<ISect> Intersect(Ray r)
 {
     return from thing in this.Things
            select thing.Intersect(r);
 }
예제 #4
0
 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)
                };
 }
예제 #5
0
 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);
 }
예제 #6
0
 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;
 }
예제 #7
0
 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);
 }