Esempio n. 1
0
        public static RColor getLight(P3 p, P3 normal)
        {
            RColor c = new RColor(0, 0, 0);

            foreach (Light l in lights)
            {
                c = c.Add(l.illumination(p, normal));
            }
            return(c);
        }
Esempio n. 2
0
        public Form1()
        {
            InitializeComponent();
            cs = new RColor[(int)width, (int)height];
            for (int i = 0; i < cs.GetLength(0); i++)
            {
                for (int j = 0; j < cs.GetLength(1); j++)
                {
                    cs[i, j] = new RColor(0, 0, 0);
                }
            }

            /*
             * objects = new List<SceneObject> {
             *  new SceneObject(new Sphere(new P3(-0.4f,0,0), 0.5f),
             *      new ImageTexture(RayTrace.Properties.Resources.Earth_texture),
             *      new NonReflective()),
             *  new SceneObject(new Sphere(new P3(0.4f,-.2f,0), 0.3f),
             *      new SolidTexture(new RColor(0,1,0)),
             *      new NonReflective()),
             *  new SceneObject(new Sphere(new P3(0.5f,-0.4f,-0.5f), 0.2f, ve: new P3(1, 0, 0)),
             *      new ImageTexture(RayTrace.Properties.Resources.Earth_texture),
             *      new NonReflective()),
             *  new SceneObject(new Plane(new P3(0,0,0.5f), new P3(0,0,-1)),
             *     new SolidTexture(new RColor(1,0,0)),
             *     new Mirror())};
             * lights = new List<Light> {
             *  new AmbientLight(new RColor(0.3f, 0.3f, 0.3f)),
             *  new DirectionalLight(new RColor(1,1,1), new P3(1,  -.2f, -.3f).Normalize())};
             * */
            objects = new List <SceneObject>();
            for (int i = -8; i < 9; i++)
            {
                for (int j = -8; j < 1; j++)
                {
                    objects.Add(new SceneObject(new Sphere(new P3(i, 50, j), 0.5f),
                                                new ImageTexture(RayTrace.Properties.Resources.Earth_texture), new NonReflective()));
                }
            }
            objects.Add(new SceneObject(new Plane(new P3(0, 0, 0.5f), new P3(0, 0, -1)),
                                        new SolidTexture(new RColor(1, 0, 0)),
                                        new Mirror()));
            lights = new List <Light> {
                new AmbientLight(new RColor(0.2f, 0.2f, 0.2f)),
                new DirectionalLight(new RColor(1, 1, 1), new P3(1, -.2f, -.3f).Normalize())
            };

            Trace();
            worldBox.Refresh();
        }
Esempio n. 3
0
 public RColor illumination(P3 point, P3 normal)
 {
     float inten = this.p.Dot(normal);
     RColor color = new RColor(0, 0, 0);
     if (inten > 0) {
         color = c.Scale(inten);
         float d;
         SceneObject s = Form1.shootRay(new Ray(point, this.p), out d);
         if (s != null) {
             return new RColor(0, 0, 0);
         }
     }
     return color;
 }
Esempio n. 4
0
        public RColor illumination(P3 point, P3 normal)
        {
            float  inten = this.p.Dot(normal);
            RColor color = new RColor(0, 0, 0);

            if (inten > 0)
            {
                color = c.Scale(inten);
                float       d;
                SceneObject s = Form1.shootRay(new Ray(point, this.p), out d);
                if (s != null)
                {
                    return(new RColor(0, 0, 0));
                }
            }
            return(color);
        }
Esempio n. 5
0
        public Form1()
        {
            InitializeComponent();
            cs = new RColor[(int)width, (int)height];
            for (int i = 0; i < cs.GetLength(0); i++) {
                for (int j = 0; j < cs.GetLength(1); j++) {
                    cs[i, j] = new RColor(0, 0, 0);
                }
            }
            /*
            objects = new List<SceneObject> {
                new SceneObject(new Sphere(new P3(-0.4f,0,0), 0.5f),
                    new ImageTexture(RayTrace.Properties.Resources.Earth_texture),
                    new NonReflective()),
                new SceneObject(new Sphere(new P3(0.4f,-.2f,0), 0.3f),
                    new SolidTexture(new RColor(0,1,0)),
                    new NonReflective()),
                new SceneObject(new Sphere(new P3(0.5f,-0.4f,-0.5f), 0.2f, ve: new P3(1, 0, 0)),
                    new ImageTexture(RayTrace.Properties.Resources.Earth_texture),
                    new NonReflective()),
                new SceneObject(new Plane(new P3(0,0,0.5f), new P3(0,0,-1)),
                   new SolidTexture(new RColor(1,0,0)),
                   new Mirror())};
            lights = new List<Light> {
                new AmbientLight(new RColor(0.3f, 0.3f, 0.3f)),
                new DirectionalLight(new RColor(1,1,1), new P3(1,  -.2f, -.3f).Normalize())};
             * */
            objects = new List<SceneObject>();
            for (int i = -8; i < 9; i++) {
                for (int j = -8; j < 1; j++) {
                    objects.Add(new SceneObject(new Sphere(new P3(i, 50, j), 0.5f),
                                new ImageTexture(RayTrace.Properties.Resources.Earth_texture), new NonReflective()));
                }
            }
            objects.Add(new SceneObject(new Plane(new P3(0, 0, 0.5f), new P3(0, 0, -1)),
                   new SolidTexture(new RColor(1, 0, 0)),
                   new Mirror()));
            lights = new List<Light> { new AmbientLight(new RColor(0.2f, 0.2f, 0.2f)),
                                        new DirectionalLight(new RColor(1, 1, 1), new P3(1, -.2f, -.3f).Normalize())};

            Trace();
            worldBox.Refresh();
        }
Esempio n. 6
0
 public void NormalizeColors(RColor[,] cs)
 {
     float max = 0;
     for (int i = 0; i < cs.GetLength(0); i++) {
         for (int j = 0; j < cs.GetLength(1); j++) {
             max = Math.Max(max, cs[i, j].Intensity());
         }
     }
     for (int i = 0; i < cs.GetLength(0); i++) {
         for (int j = 0; j < cs.GetLength(1); j++) {
             cs[i, j] = cs[i, j].Normalize(max);
         }
     }
 }
Esempio n. 7
0
 public Ray(P3 start, P3 direction)
 {
     this.start = start;
     this.direction = direction.Normalize();
     color = new RColor(0, 0, 0);
 }
Esempio n. 8
0
 public SolidTexture(RColor c)
 {
     this.c = c;
 }
Esempio n. 9
0
 public RColor Color(P3 p, Ray r, SceneObject s) {
     RColor light = Form1.getLight(p, s.Geo.Normal(p));
     return light.Mul(s.Texture.Color(s.Geo.ToP2(p)));
 }
Esempio n. 10
0
 public RColor Mul(RColor c)
 {
     return(new RColor(this.R * c.R, this.G * c.G, this.B * c.B));
 }
Esempio n. 11
0
 public AmbientLight(RColor l)
 {
     this.l = l;
 }
Esempio n. 12
0
 public SolidTexture(RColor c)
 {
     this.c = c;
 }
Esempio n. 13
0
 public RColor Add(RColor c)
 {
     return(new RColor(this.R + c.R, this.G + c.G, this.B + c.B));
 }
Esempio n. 14
0
 public static RColor getLight(P3 p, P3 normal)
 {
     RColor c = new RColor(0, 0, 0);
     foreach (Light l in lights) {
         c = c.Add(l.illumination(p, normal));
     }
     return c;
 }
Esempio n. 15
0
 public RColor Add(RColor c)
 {
     return new RColor(this.R + c.R, this.G + c.G, this.B + c.B);
 }
Esempio n. 16
0
 public DirectionalLight(RColor c, float theta, float phi)
 {
     this.c = c;
     this.p = P3.fromSphere(theta, phi);
 }
Esempio n. 17
0
 public DirectionalLight(RColor c, P3 p)
 {
     this.c = c;
     this.p = p;
 }
Esempio n. 18
0
 public RColor Mul(RColor c)
 {
     return new RColor(this.R * c.R, this.G * c.G, this.B * c.B);
 }
Esempio n. 19
0
 public DirectionalLight(RColor c, P3 p)
 {
     this.c = c;
     this.p = p;
 }
Esempio n. 20
0
 public DirectionalLight(RColor c, float theta, float phi)
 {
     this.c = c;
     this.p = P3.fromSphere(theta, phi);
 }
Esempio n. 21
0
 public Ray(P3 start, P3 direction)
 {
     this.start     = start;
     this.direction = direction.Normalize();
     color          = new RColor(0, 0, 0);
 }
Esempio n. 22
0
 public AmbientLight(RColor l)
 {
     this.l = l;
 }