Beispiel #1
0
 public static Vector Times(double n, Vector v)
 {
     return new Vector(v.X * n, v.Y * n, v.Z * n);
 }
Beispiel #2
0
 public static Vector Norm(Vector v)
 {
     double mag = Mag(v);
     double div = mag == 0 ? double.PositiveInfinity : 1 / mag;
     return Times(div, v);
 }
Beispiel #3
0
 public static Vector Plus(Vector v1, Vector v2)
 {
     return new Vector(v1.X + v2.X, v1.Y + v2.Y, v1.Z + v2.Z);
 }
Beispiel #4
0
 public static double Mag(Vector v)
 {
     return Math.Sqrt(Dot(v, v));
 }
Beispiel #5
0
 public static Vector Minus(Vector v1, Vector v2)
 {
     return new Vector(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z);
 }
Beispiel #6
0
 public static double Dot(Vector v1, Vector v2)
 {
     return (v1.X * v2.X) + (v1.Y * v2.Y) + (v1.Z * v2.Z);
 }
Beispiel #7
0
 public static bool Equals(Vector v1, Vector v2)
 {
     return (v1.X == v2.X) && (v1.Y == v2.Y) && (v1.Z == v2.Z);
 }
Beispiel #8
0
 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));
 }
Beispiel #9
0
 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)));
 }
Beispiel #10
0
 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;
 }
Beispiel #11
0
 public override Vector Normal(Vector pos)
 {
     return Vector.Norm(Vector.Minus(pos, Center));
 }
Beispiel #12
0
 public Sphere(Vector center, double radius, Surface surface) : base(surface) { Center = center; Radius = radius; }
Beispiel #13
0
 public static Vector Norm(Vector v)
 {
     float mag = Mag(v);
     float div = mag == 0 ? float.PositiveInfinity : 1 / mag;
     return Times(div, v);
 }
Beispiel #14
0
 public static float Mag(Vector v)
 {
     return (float)Math.Sqrt(Dot(v, v));
 }