Exemplo n.º 1
0
 public abstract ISect Intersect(Ray ray);
Exemplo n.º 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
                };
 }
Exemplo n.º 3
0
 public IEnumerable<ISect> Intersect(Ray r)
 {
     return from thing in this.Things
            select thing.Intersect(r);
 }
Exemplo n.º 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)
                };
 }
Exemplo n.º 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);
 }
Exemplo n.º 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;
 }
Exemplo n.º 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);
 }