Beispiel #1
0
        public Camera(Vector Position, Vector Taget)
        {
            Vector forward = Taget - Position;

            forward.Normalize();
            Vector down  = new Vector(0, -1, 0);
            Vector right = Vector.Corss(ref forward, ref down);

            right.Normalize();
            right *= 2;
            Vector up = Vector.Corss(ref forward, ref right);

            up.Normalize();
            up *= 1.5f;

            this.Position  = Position;
            this.Direction = forward;
            this.Y         = up;
            this.X         = right;
        }
Beispiel #2
0
        private Color GetNaturalColor(Shape thing, ref Vector pos, ref Vector norm, ref Vector rd, Scene scene)
        {
            rd.Normalize();
            Color ret = Color.Black;
            var   ray = new Ray();

            ray.Position = pos;
            for (int i = 0; i < scene.Lights.Length; i++)
            {
                Light  light = scene.Lights[i];
                Vector ldis  = light.Pos - pos;
                var    len   = ldis.Length;
                Vector livec = ldis * (1f / len);
                ray.Direction = livec;
                if (!scene.ShaowTest(ref ray, len))
                {
                    float illum = livec * norm;
                    if (illum > 0)
                    {
                        var lcolor = light.Color;
                        lcolor.Multiply(illum);
                        lcolor.Multiply(thing.Surface.Diffuse(pos));
                        ret.Add(ref lcolor);
                    }

                    float specular = livec * rd;
                    if (specular > 0)
                    {
                        var scolor = light.Color;
                        scolor.Multiply((float)Math.Pow(specular, thing.Surface.Power));
                        scolor.Multiply(thing.Surface.Specular(pos));
                        ret.Add(ref scolor);
                    }
                }
            }
            return(ret);
        }
Beispiel #3
0
 public override Vector GetNormal(Vector pos)
 {
     pos -= Center;
     pos.Normalize();
     return(pos);
 }