Ejemplo n.º 1
0
        private void DrawVerticalLine(DepthTexture texture, Pixel color, float depth, int startX, int startY, float width)
        {
            //make sure the range is in drawing area
            startY = Math.Max(startY, 0);
            int xEnd = Math.Min(startX + (int)Math.Ceiling(width), texture.Width - 1);

            //draw the rectangle
            for (int xOff = Math.Max(0, startX); xOff < xEnd; xOff++)
            {
                for (int y = startY; y < texture.Height; y++)
                {
                    BasePixel tmpPx = texture.GetPixel(xOff, y);

                    if (tmpPx.Depth < depth)
                    {
                        break;
                    }

                    tmpPx.R     = color.R;
                    tmpPx.G     = color.G;
                    tmpPx.B     = color.B;
                    tmpPx.Depth = depth;
                }
            }
        }
Ejemplo n.º 2
0
        public static unsafe void DrawToScreen(DepthTexture screenArray, FormMain drawTo)
        {
            //simple error checking to keep program from crashing if array is oversized
            if (screenArray.Width != bitmap.Width || screenArray.Height != bitmap.Height)
            {
                throw new System.ArgumentException("Parameter array is not the same size as the screen", "original");
            }

            //lock bits to draw screen buffer
            System.Drawing.Imaging.BitmapData bmpData = bitmap.LockBits(rectScreen, System.Drawing.Imaging.ImageLockMode.WriteOnly, bitmap.PixelFormat);

            //Pixel array to bitmap
            UInt32 *pixel = (UInt32 *)bmpData.Scan0.ToPointer();
            int     tempW = bitmap.Width;
            int     tempH = bitmap.Height;

            //for (int x = 0; x < bitmap.Width; x++)
            Parallel.For(0, tempH, y =>
            {
                int tmpY = y * tempW;
                for (int x = 0; x < tempW; x++)
                {
                    BasePixel tmpPx = screenArray.GetPixel(x, y);
                    pixel[tmpY + x] = 0xFF000000 | (((UInt32)tmpPx.R) << 16 | (((UInt32)tmpPx.G) << 8)) | tmpPx.B;
                }
            });

            //unlock bits then draw
            bitmap.UnlockBits(bmpData);
            drawTo.DrawImage(bitmap);
        }
Ejemplo n.º 3
0
        public Terrain(DepthTexture diffuseMap, DepthTexture bumpMap, float yScale, float xzScale)
        {
            if (diffuseMap.Height != bumpMap.Height || diffuseMap.Width != bumpMap.Width)
            {
                throw new Exception("diffuseMap and bumpMap must be the same size");
            }

            if (yScale < 1.0f || xzScale < 1.0f)
            {
                throw new Exception("only can scale up or keep a scale of 1");
            }

            //make bare-bones simplified arrays/per-computed values
            this.xzScale = xzScale;
            h            = bumpMap.Height;
            w            = bumpMap.Width;

            this.bumpMap    = new float[bumpMap.Width, bumpMap.Height];
            this.diffuseMap = new Pixel[diffuseMap.Width, diffuseMap.Height];

            Parallel.For(0, bumpMap.Width, x =>
            {
                for (int y = 0; y < bumpMap.Height; y++)
                {
                    this.bumpMap[x, y] = bumpMap.GetPixel(x, y).R *yScale;

                    ref Pixel tmpPix = ref this.diffuseMap[x, y];

                    BasePixel tmpPix2 = diffuseMap.GetPixel(x, y);
                    tmpPix.R          = tmpPix2.R;
                    tmpPix.G          = tmpPix2.G;
                    tmpPix.B          = tmpPix2.B;
                }
            });
        }
Ejemplo n.º 4
0
 public void PixelCopy(BasePixel pixelToCopy)
 {
     r     = pixelToCopy.R;
     g     = pixelToCopy.G;
     b     = pixelToCopy.B;
     a     = pixelToCopy.A;
     depth = pixelToCopy.Depth;
 }
Ejemplo n.º 5
0
 // returns if it was successful
 public bool PixelSetDepthTest(BasePixel pixelToCopy, float depth)
 {
     if (depth < this.depth && pixelToCopy.A != 0)
     {
         pixelToCopy.depth = depth;
         PixelCopy(pixelToCopy);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 6
0
        private void MakeTexture(int width, int height, float depth)
        {
            TextureArr = new BasePixel[width, height];
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    TextureArr[x, y] = new BasePixel(depth);
                }
            }

            UpdateSize();
        }
Ejemplo n.º 7
0
        public static BasePixel[,] LoadImage(string filename)
        {
            Bitmap tmpImg = (Bitmap)Image.FromFile(filename);

            BasePixel[,] returnArray = new BasePixel[tmpImg.Width, tmpImg.Height];

            for (int x = 0; x < tmpImg.Width; x++)
            {
                for (int y = 0; y < tmpImg.Height; y++)
                {
                    Color tmpColor = tmpImg.GetPixel(x, y);

                    returnArray[x, y] = new BasePixel(
                        tmpColor.R,
                        tmpColor.G,
                        tmpColor.B,
                        tmpColor.A,
                        0);
                }
            }

            return(returnArray);
        }
Ejemplo n.º 8
0
 //copies a pixel if passes a depth test and alpha test
 public void PixelSetDepthTest(BasePixel pixelToCopy)
 {
     PixelSetDepthTest(pixelToCopy, pixelToCopy.depth);
 }
Ejemplo n.º 9
0
 public bool SetPixelDepthTest(int x, int y, BasePixel pix, float depth)
 {
     return(TextureArr[x, y].PixelSetDepthTest(pix, depth));
 }
Ejemplo n.º 10
0
 public void SetPixel(int x, int y, BasePixel pix)
 {
     TextureArr[x, y].PixelCopy(pix);
 }