Ejemplo n.º 1
0
        public void DrawScene(Bitmap bmp)
        {
            if (bmp.Width < camera.Dimention.Width || bmp.Height < camera.Dimention.Height)
            {
                camera.Dimention = bmp.Size;
            }

            Size dim = camera.Dimention;

            Thread[] threads = new Thread[threadCount];

            int linesCount = dim.Width / threadCount;

            completedLines = 0;
            for (int i = 0; i < threadCount; i++)
            {
                threads[i] = new Thread(this.ThreadFunction);
                DrawingInfo info = new DrawingInfo(i * linesCount, (i + 1) * linesCount, bmp);
                threads[i].Start(info);
            }
            for (int i = 0; i < threadCount; i++)
            {
                threads[i].Join();
            }
            completedLines = camera.Dimention.Width;
        }
Ejemplo n.º 2
0
        public void ThreadFunction(object obj)
        {
            DrawingInfo info = (DrawingInfo)obj;
            Color       clr;

            for (int i = info.line1; i < info.line2; i++)
            {
                for (int j = 0; j < camera.Dimention.Height; j++)
                {
                    clr = RayTracing(camera.GetRay(i, j), 0);
                    lock (bmpSync) {
                        info.bmp.SetPixel(i, j, clr);
                    }
                }
                Interlocked.Increment(ref completedLines);
            }
        }