public static Vector Times(double n, Vector v) { return new Vector(v.X * n, v.Y * n, v.Z * n); }
public static Vector Norm(Vector v) { double mag = Mag(v); double div = mag == 0 ? double.PositiveInfinity : 1 / mag; return Times(div, v); }
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 Mag(Vector v) { return Math.Sqrt(Dot(v, v)); }
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 double Dot(Vector v1, Vector v2) { return (v1.X * v2.X) + (v1.Y * v2.Y) + (v1.Z * v2.Z); }
public static bool Equals(Vector v1, Vector v2) { return (v1.X == v2.X) && (v1.Y == v2.Y) && (v1.Z == v2.Z); }
private Color GetReflectionColor(SceneObject thing, Vector pos, Vector norm, Vector rd, Scene scene, int depth) { return Color.Times(thing.Surface.Reflect(pos), TraceRay(new Ray(pos, rd), scene, depth + 1)); }
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))); }
private Color GetNaturalColor(SceneObject thing, Vector pos, Vector norm, Vector rd, Scene scene) { Color ret = new Color(0, 0, 0); foreach (Light light in scene.Lights) { Vector ldis = Vector.Minus(light.Pos, pos); Vector livec = Vector.Norm(ldis); double neatIsect = TestRay(new Ray(pos, livec), scene); bool isInShadow = !((neatIsect > Vector.Mag(ldis)) || (neatIsect == 0)); if (!isInShadow) { double illum = Vector.Dot(livec, norm); Color lcolor = illum > 0 ? Color.Times(illum, light.Color) : new Color(0, 0, 0); double specular = Vector.Dot(livec, Vector.Norm(rd)); Color scolor = specular > 0 ? Color.Times(Math.Pow(specular, thing.Surface.Roughness), light.Color) : new Color(0, 0, 0); ret = Color.Plus(ret, Color.Plus(Color.Times(thing.Surface.Diffuse(pos), lcolor), Color.Times(thing.Surface.Specular(pos), scolor))); } } return ret; }
public override Vector Normal(Vector pos) { return Vector.Norm(Vector.Minus(pos, Center)); }
public Sphere(Vector center, double radius, Surface surface) : base(surface) { Center = center; Radius = radius; }
public static Vector Norm(Vector v) { float mag = Mag(v); float div = mag == 0 ? float.PositiveInfinity : 1 / mag; return Times(div, v); }
public static float Mag(Vector v) { return (float)Math.Sqrt(Dot(v, v)); }