Exemplo n.º 1
0
        public void nonThreadedTrace()
        {
            float       distance;
            P3          d;
            Ray         r;
            SceneObject s;

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    d = new P3(i / Form1.width * 2 - 1, 0, j / Form1.height * 2 - 1);
                    r = new Ray(Form1.cameraPos, d.Sub(Form1.cameraPos));
                    s = Form1.shootRay(r, out distance);
                    if (s != null)
                    {
                        try {
                            Form1.cs[i, j] = s.ColorAt(r.Travel(distance), r);
                        } catch (Exception e) { //Set pixel to black if there are any errors
                            Form1.cs[i, j] = new RColor(0, 0, 0);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static void Trace(float minRange, float maxRange)
        {
            float       distance;
            P3          d;
            Ray         r;
            SceneObject s;

            for (int i = 0; i < Form1.width; i++)
            {
                for (int j = (int)minRange; j < (int)maxRange; j++)
                {
                    d = new P3(i / Form1.width * 2 - 1, 0, j / Form1.height * 2 - 1);
                    r = new Ray(Form1.cameraPos, d.Sub(Form1.cameraPos));
                    s = Form1.shootRay(r, out distance);
                    if (s != null)
                    {
                        try {
                            Form1.cs[i, j] = s.ColorAt(r.Travel(distance), r);
                        } catch (FormatException e) { //Set pixel to black if there are any errors
                            Console.WriteLine(e);
                            Form1.cs[i, j] = new RColor(0, 0, 0);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 public RColor Color(P3 p, Ray r, SceneObject s)
 {
     P3 N = s.Geo.Normal(p);
     float c1 = -N.Dot(r.direction);
     P3 R1 = r.direction.Add(N.Scale(2).Scale(c1));
     float d;
     Ray r1 = new Ray(p, R1);
     SceneObject so = Form1.shootRay(r1, out d);
     if (so == null) {
         return new RColor(0, 0, 0);
     } else return so.ColorAt(r1.Travel(d), r1);
 }
Exemplo n.º 4
0
        public RColor Color(P3 p, Ray r, SceneObject s)
        {
            P3          N  = s.Geo.Normal(p);
            float       c1 = -N.Dot(r.direction);
            P3          R1 = r.direction.Add(N.Scale(2).Scale(c1));
            float       d;
            Ray         r1 = new Ray(p, R1);
            SceneObject so = Form1.shootRay(r1, out d);

            if (so == null)
            {
                return(new RColor(0, 0, 0));
            }
            else
            {
                return(so.ColorAt(r1.Travel(d), r1));
            }
        }
Exemplo n.º 5
0
 public void nonThreadedTrace()
 {
     float distance;
     P3 d;
     Ray r;
     SceneObject s;
     for (int i = 0; i < width; i++) {
         for (int j = 0; j < height; j++) {
             d = new P3(i / Form1.width * 2 - 1, 0, j / Form1.height * 2 - 1);
             r = new Ray(Form1.cameraPos, d.Sub(Form1.cameraPos));
             s = Form1.shootRay(r, out distance);
             if (s != null) {
                 try {
                     Form1.cs[i, j] = s.ColorAt(r.Travel(distance), r);
                 } catch (Exception e) { //Set pixel to black if there are any errors
                     Form1.cs[i, j] = new RColor(0, 0, 0);
                 }
             }
         }
     }
 }