예제 #1
0
        public HeightFieldObject(Vector3D origin, MaterialShader shader, Vector2D size, Bitmap bitmapSrc)
            : base(origin, shader, -1)
        {
            this.bitmapSrc = bitmapSrc;
            // calculate bounds
            areaExtent = size;
            Vector2D halfSize = size * 0.5;

            areaStart = origin - halfSize;
            areaEnd   = origin + halfSize;
            double szLen = size.Length();

            radius = Math.Sqrt((szLen * szLen) + (1.1 * 1.1)) / 2;

            hField = HeightField.FromBitmap(bitmapSrc);

            onePx = new Vector2D(areaExtent.X / hField.Width, areaExtent.Y / hField.Height);

            this.origin.Y = 0.5;

            zMin = 0;
            zTop = 1;

            rectangles = new Rectangle3D[]
            {
                new Rectangle3D(new Vector3D(areaStart.X, zTop, areaStart.Y), new Vector3D(areaEnd.X, zTop, areaEnd.Y),
                                new PlaneD(new Vector3D(0, 1, 0), -zTop)),          // top
                new Rectangle3D(new Vector3D(areaStart.X, zMin, areaStart.Y), new Vector3D(areaEnd.X, zMin, areaEnd.Y),
                                new PlaneD(new Vector3D(0, -1, 0), zMin)),          // bottom
                new Rectangle3D(new Vector3D(areaStart.X, zMin, areaStart.Y), new Vector3D(areaStart.X, zTop, areaEnd.Y),
                                new PlaneD(new Vector3D(-1, 0, 0), halfSize.X)),    // left
                new Rectangle3D(new Vector3D(areaEnd.X, zMin, areaStart.Y), new Vector3D(areaEnd.X, zTop, areaEnd.Y),
                                new PlaneD(new Vector3D(1, 0, 0), -halfSize.X)),    // right
                new Rectangle3D(new Vector3D(areaStart.X, zMin, areaStart.Y), new Vector3D(areaEnd.X, zTop, areaStart.Y),
                                new PlaneD(new Vector3D(0, 0, -1), halfSize.Y)),    // front
                new Rectangle3D(new Vector3D(areaStart.X, zMin, areaEnd.Y), new Vector3D(areaEnd.X, zTop, areaEnd.Y),
                                new PlaneD(new Vector3D(0, 0, 1), -halfSize.Y)),    // back
            };
        }
예제 #2
0
        public static HeightField FromBitmap(Bitmap bitmap)
        {
            HeightField hField = new HeightField(bitmap.Width, bitmap.Height);
            BitmapData  data   = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            unsafe
            {
                ARGB_32Bit *pixels  = (ARGB_32Bit *)data.Scan0.ToPointer();
                int         dataIdx = 0;
                for (int y = 0; y < bitmap.Height; y++)
                {
                    for (int x = 0; x < bitmap.Width; x++)
                    {
                        hField.values[dataIdx++] = (pixels->R + pixels->G + pixels->B) / 765f;
                        pixels++;
                    }
                }
            }

            bitmap.UnlockBits(data);
            return(hField);
        }
예제 #3
0
        public HeightFieldObject(Vector3D origin, MaterialShader shader, Vector2D size, Bitmap bitmapSrc)
            : base(origin, shader, -1)
        {
            this.bitmapSrc = bitmapSrc;
            // calculate bounds
            areaExtent = size;
            Vector2D halfSize = size * 0.5;
            areaStart = origin - halfSize;
            areaEnd = origin + halfSize;
            double szLen = size.Length();
            radius = Math.Sqrt((szLen * szLen) + (1.1 * 1.1)) / 2;

            hField = HeightField.FromBitmap(bitmapSrc);

            onePx = new Vector2D(areaExtent.X / hField.Width, areaExtent.Y / hField.Height);

            this.origin.Y = 0.5;

            zMin = 0;
            zTop = 1;

            rectangles = new Rectangle3D[]
            {
                new Rectangle3D(new Vector3D(areaStart.X, zTop, areaStart.Y), new Vector3D(areaEnd.X, zTop, areaEnd.Y),
                                new PlaneD(new Vector3D(0, 1, 0), -zTop)),           // top
                new Rectangle3D(new Vector3D(areaStart.X, zMin, areaStart.Y), new Vector3D(areaEnd.X, zMin, areaEnd.Y),
                                new PlaneD(new Vector3D(0, -1, 0), zMin)),          // bottom
                new Rectangle3D(new Vector3D(areaStart.X, zMin, areaStart.Y), new Vector3D(areaStart.X, zTop, areaEnd.Y), 
                                new PlaneD(new Vector3D(-1, 0, 0), halfSize.X)),    // left
                new Rectangle3D(new Vector3D(areaEnd.X, zMin, areaStart.Y), new Vector3D(areaEnd.X, zTop, areaEnd.Y),
                                new PlaneD(new Vector3D(1, 0, 0), -halfSize.X)),     // right
                new Rectangle3D(new Vector3D(areaStart.X, zMin, areaStart.Y), new Vector3D(areaEnd.X, zTop, areaStart.Y),
                                new PlaneD(new Vector3D(0, 0, -1), halfSize.Y)),    // front 
                new Rectangle3D(new Vector3D(areaStart.X, zMin, areaEnd.Y), new Vector3D(areaEnd.X, zTop, areaEnd.Y),
                                new PlaneD(new Vector3D(0, 0, 1), -halfSize.Y)),     // back
            };
        }
예제 #4
0
        public static HeightField FromBitmap(Bitmap bitmap)
        {
            HeightField hField = new HeightField(bitmap.Width, bitmap.Height);
            BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            unsafe
            {
                ARGB_32Bit* pixels = (ARGB_32Bit*)data.Scan0.ToPointer();
                int dataIdx = 0;
                for (int y = 0; y < bitmap.Height; y++)
                {
                    for (int x = 0; x < bitmap.Width; x++)
                    {
                        hField.values[dataIdx++] = (pixels->R + pixels->G + pixels->B) / 765f;
                        pixels++;
                    }
                }
            }

            bitmap.UnlockBits(data);
            return hField;
        }