Пример #1
0
        public Bitmap DrawSceneByPointsBitmap(int width, int height, List <MPoint> points)
        {
            Bitmap bitmap = new Bitmap(width, height);

            var zBufferManager = new Tools.ZBuffer(width, height);
            var zBuffer        = zBufferManager.GetBuffer(points);

            //Moves 0,0 point from top-left to bottom-left
            for (int i = 0; i < points.Count; ++i)
            {
                points[i].Y = height - points[i].Y;
            }

            for (int i = 0; i < bitmap.Width; ++i)
            {
                for (int j = 0; j < bitmap.Height; ++j)
                {
                    var color = System.Drawing.Color.FromArgb(zBuffer[i + j * width].ARGB);

                    bitmap.SetPixel(i, j, color);
                }
            }


            //for (int i = 0; i < points.Count; ++i)
            //    bitmap.SetPixel((int)points[i].X, (int)points[i].Y, System.Drawing.Color.Black);

            return(bitmap);
        }
Пример #2
0
        //public void DrawScene(Scene scene, HashSet<Point3D> points)
        //{
        //    Int32Rect rect = new Int32Rect(0, 0, (int)scene.Bitmap.Width, (int)scene.Bitmap.Height);

        //    byte[] pixels = new byte[(int)scene.Bitmap.Width * (int)scene.Bitmap.Height * scene.Bitmap.Format.BitsPerPixel / 8];

        //    for (int y = 0; y < scene.Bitmap.PixelHeight; y++)
        //    {
        //        for (int x = 0; x < scene.Bitmap.PixelWidth; x++)
        //        {
        //            var currPoint = new Point3D(x, y, 0);

        //            int alpha = 255;
        //            int red = 255;
        //            int green = 255;
        //            int blue = 255;

        //            if (points.Contains(currPoint))
        //            {
        //                alpha = 255;
        //                red = 0;
        //                green = 0;
        //                blue = 0;
        //            }

        //            int pixelOffset = (x + y * scene.Bitmap.PixelWidth) * scene.Bitmap.Format.BitsPerPixel / 8;
        //            pixels[pixelOffset] = (byte)blue;
        //            pixels[pixelOffset + 1] = (byte)green;
        //            pixels[pixelOffset + 2] = (byte)red;
        //            pixels[pixelOffset + 3] = (byte)alpha;
        //        }
        //    }

        //    int stride = (scene.Bitmap.PixelWidth * scene.Bitmap.Format.BitsPerPixel) / 8;

        //    scene.Bitmap.WritePixels(rect, pixels, stride, 0);
        //}


        public WriteableBitmap DrawSceneByPoints(int width, int height, List <MPoint> points)
        {
            WriteableBitmap wBitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgra32, null);

            Int32Rect rect = new Int32Rect(0, 0, width, height);

            var stride = (rect.Width * wBitmap.Format.BitsPerPixel + 7) / 8;

            byte[] pixels = new byte[rect.Height * stride];

            //Moves 0,0 point from top-left to bottom-left
            for (int i = 0; i < points.Count; ++i)
            {
                points[i].Y = height - points[i].Y;
            }

            var zBufferManager = new Tools.ZBuffer(width, height);
            var zBuffer        = zBufferManager.GetBuffer(points);

            for (int i = 0; i < zBuffer.Length; ++i)
            {
                var color = System.Drawing.Color.FromArgb(zBuffer[i].ARGB);

                int pixelOffset = i * wBitmap.Format.BitsPerPixel / 8;

                pixels[pixelOffset]     = color.B;
                pixels[pixelOffset + 1] = color.G;
                pixels[pixelOffset + 2] = color.R;
                pixels[pixelOffset + 3] = 255;
            }

            //for (int i = 0; i < points.Count; ++i)
            //{
            //    var color = System.Drawing.Color.FromArgb(zBuffer[(int)points[i].X + (int)points[i].Y * width].ARGB);

            //    int pixelOffset = (int)(points[i].X + points[i].Y * wBitmap.PixelWidth) * wBitmap.Format.BitsPerPixel / 8;

            //    pixels[pixelOffset] = color.B;
            //    pixels[pixelOffset + 1] = color.G;
            //    pixels[pixelOffset + 2] = color.R;
            //    pixels[pixelOffset + 3] = color.A;
            //}

            wBitmap.WritePixels(rect, pixels, stride, 0);

            return(wBitmap);
        }