Example #1
0
        public Camera(Vector pos, Vector lookAt)
        {
            this.pos = pos;
            var down = new Vector(0.0, -1.0, 0.0);

            this.forward = Vector.norm(Vector.minus(lookAt, pos));
            this.right   = Vector.times(1.5, Vector.norm(Vector.cross(this.forward, down)));
            this.up      = Vector.times(1.5, Vector.norm(Vector.cross(this.forward, this.right)));
        }
Example #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))));
            }
        }
Example #3
0
 Vector getPoint(double x, double y, Camera camera)
 {
     return(Vector.norm(Vector.plus(camera.forward, Vector.plus(Vector.times(recenterX(x), camera.right), Vector.times(recenterY(y), camera.up)))));
 }
Example #4
0
 public override Vector normal(Vector pos)
 {
     return(Vector.norm(Vector.minus(pos, this.center)));
 }