Exemple #1
0
        public static Vector norm(Vector v)
        {
            var mag = Vector.mag(v);
            var div = (mag == 0) ? double.PositiveInfinity : 1.0 / mag;

            return(Vector.times(div, v));
        }
Exemple #2
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)));
        }
Exemple #3
0
        private Color shade(Intersection isect, Scene scene, double depth)
        {
            var d              = isect.ray.dir;
            var pos            = Vector.plus(Vector.times(isect.dist, d), isect.ray.start);
            var normal         = isect.thing.normal(pos);
            var reflectDir     = Vector.minus(d, Vector.times(2, Vector.times(Vector.dot(normal, d), normal)));
            var naturalColor   = Color.plus(Color.background, this.getNaturalColor(isect.thing, pos, normal, reflectDir, scene));
            var reflectedColor = (depth >= this.maxDepth) ? Color.grey : this.getReflectionColor(isect.thing, pos, normal, reflectDir, scene, depth);

            return(Color.plus(naturalColor, reflectedColor));
        }
Exemple #4
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)))));
 }