Exemplo n.º 1
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));
            }
        }
Exemplo n.º 2
0
        Color addLight(Color col, Light light)
        {
            var ldis       = Vector.minus(light.pos, pos);
            var livec      = Vector.norm(ldis);
            var neatIsect  = this.testRay(new Ray(pos, livec), scene);
            var isInShadow = (neatIsect == null) ? false : (neatIsect <= Vector.mag(ldis));

            if (isInShadow)
            {
                return(col);
            }
            else
            {
                var illum  = Vector.dot(livec, norm);
                var lcolor = (illum > 0) ? Color.scale(illum, light.color)
                                          : Color.defaultColor;
                var specular = Vector.dot(livec, Vector.norm(rd));
                var scolor   = (specular > 0) ? Color.scale(Math.Pow(specular, thing.surface.roughness), light.color)
                                          : Color.defaultColor;
                return(Color.plus(col, Color.plus(Color.times(thing.surface.diffuse(pos), lcolor),
                                                  Color.times(thing.surface.specular(pos), scolor))));
            }
        }
Exemplo n.º 3
0
 public override Vector normal(Vector pos)
 {
     return(Vector.norm(Vector.minus(pos, this.center)));
 }