private Color getReflectionColor(Thing thing, Vector pos, Vector normal, Vector rd, Scene scene, double depth) { return Color.scale(thing.surface.reflect(pos), this.traceRay(new Ray (pos, rd), scene, depth + 1)); }
public static Vector plus(Vector v1, Vector v2) { return new Vector(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z); }
public static double dot(Vector v1, Vector v2) { return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; }
public Plane(Vector norm, double offset, Surface surface) { this.norm = norm; this.offset = offset; this.surface = surface; }
public static Vector minus(Vector v1, Vector v2) { return new Vector(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z); }
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); }
public Ray(Vector start, Vector dir) { this.start = start; this.dir = dir; }
public Sphere(Vector center, double radius, Surface surface) { this.center = center; this.radius2 = radius * radius; this.surface = surface; }
public override Vector normal(Vector pos) { return Vector.norm(Vector.minus(pos, this.center)); }
abstract public Vector normal(Vector pos);
public Light(Vector pos, Color color) { this.pos = pos; this.color = color; }
abstract public double reflect(Vector pos);
abstract public Color specular(Vector pos);
abstract public Color diffuse(Vector pos);
private Color getNaturalColor(Thing thing, Vector pos, Vector norm, Vector rd, Scene scene) { this.thing = thing; this.pos = pos; this.norm = norm; this.rd = rd; this.scene = scene; return Reduce(scene.lights, Color.defaultColor); }
public static Vector times(double k, Vector v) { return new Vector(k * v.x, k * v.y, k * v.z); }
public static double mag(Vector v) { return Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z); }
public override Vector normal(Vector pos) { return norm; }
public static Vector cross(Vector v1, Vector v2) { return new Vector(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x); }
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))); }