コード例 #1
0
ファイル: Form1.cs プロジェクト: Jiig/school-examples
        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);
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: Threads.cs プロジェクト: Jiig/school-examples
        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);
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: Mirror.cs プロジェクト: Jiig/school-examples
 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);
 }
コード例 #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));
            }
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: Jiig/school-examples
 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);
                 }
             }
         }
     }
 }