コード例 #1
0
        private Color GetNaturalColor(SceneObject thing, Vector pos, Vector norm, Vector rd, Scene scene)
		{
            Color ret = Color.Make(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() { Start = pos, Dir = 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) : Color.Make(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) : Color.Make(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;
        }
コード例 #2
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() { Start = pos, Dir = rd }, scene, depth + 1));
        }
コード例 #3
0
 public override Vector Normal(Vector pos) {
     return Norm;
 }
コード例 #4
0
 public abstract Vector Normal(Vector pos);
コード例 #5
0
 public override Vector Normal(Vector pos) {
     return Vector.Norm(Vector.Minus(pos, Center));
 }
コード例 #6
0
 public static bool Equals(Vector v1, Vector v2) {
     return (v1.X == v2.X) && (v1.Y == v2.Y) && (v1.Z == v2.Z);
 }
コード例 #7
0
        public static Camera Create(Vector pos, Vector lookAt) {
            Vector forward = Vector.Norm(Vector.Minus(lookAt, pos));
            Vector down = new Vector(0, -1, 0);
            Vector right = Vector.Times(1.5, Vector.Norm(Vector.Cross(forward, down)));
            Vector up = Vector.Times(1.5, Vector.Norm(Vector.Cross(forward, right)));

            return new Camera() { Pos = pos, Forward = forward, Up = up, Right = right };
        }
コード例 #8
0
 public static Vector Norm(Vector v) {
     double mag = Mag(v);
     double div = mag == 0 ? double.PositiveInfinity : 1 / mag;
     return Times(div, v);
 }
コード例 #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)));
 }
コード例 #10
0
 public static double Mag(Vector v) { return Math.Sqrt(Dot(v, v)); }
コード例 #11
0
 public static double Dot(Vector v1, Vector v2) {
     return (v1.X * v2.X) + (v1.Y * v2.Y) + (v1.Z * v2.Z);
 }
コード例 #12
0
 public static Vector Plus(Vector v1, Vector v2) {
     return new Vector(v1.X + v2.X, v1.Y + v2.Y, v1.Z + v2.Z);
 }
コード例 #13
0
 public static Vector Minus(Vector v1, Vector v2) {
     return new Vector(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z);
 }
コード例 #14
0
 public static Vector Times(double n, Vector v) {
     return new Vector(v.X * n, v.Y * n, v.Z * n);
 }