Beispiel #1
0
        private float[][] CreateGround()
        {
            var heightmap = new Graphics.Software.Texel.R32F[57, 121];

            Random r       = new Random(1024);
            int    xPieces = (int)(heightmap.GetLength(0) / (float)xSize);
            int    yPieces = (int)(heightmap.GetLength(1) / (float)ySize);


            float lastHeight = 0f;

            for (int y = 0; y < yPieces; y++)
            {
                for (int x = 0; x < xPieces; x++)
                {
                    float height = 0f;
                    if (r.NextDouble() > 0.92)
                    {
                        height = 16f * (float)r.NextDouble() - 8f;
                    }
                    else if (r.NextDouble() > 0.82)
                    {
                        height = 8f * (float)r.NextDouble() - 4f;
                    }
                    else
                    {
                        height = 1f * (float)r.NextDouble() - 1f;
                    }
                    for (int yp = 0; yp < ySize; yp++)
                    {
                        for (int xp = 0; xp < xSize; xp++)
                        {
                            if (x > 0 && y > 0)
                            {
                                heightmap[x * xSize + xp, y *ySize + yp].R = lastHeight + (height - lastHeight) * ((float)xp / (xSize - 1)) * ((float)yp / (ySize - 1)) + heightOffset;
                            }
                        }
                    }
                    lastHeight = height;
                }
            }

            var ground = new TestGround
            {
                Size       = new SizeF(size.Width, size.Height),
                Heightmap  = heightmap,
                NPieces    = new Size(xSize, ySize),
                Height     = 1,
                Simulation = motionSimulation
            };

            scene.Add(ground);
            ground.ConstructPieces();

            float[][] floatMap = new float[heightmap.GetLength(0)][];
            for (int i = 0; i < heightmap.GetLength(0); i++)
            {
                floatMap[i] = new float[heightmap.GetLength(1)];
                for (int j = 0; j < heightmap.GetLength(1); j++)
                {
                    floatMap[i][j] = heightmap[i, j].R;
                }
            }
            return(floatMap);
        }
        private float[][] CreateGround()
        {
            var heightmap = new Graphics.Software.Texel.R32F[57, 121];

            Random r = new Random(1024);
            int xPieces = (int)(heightmap.GetLength(0) / (float)xSize);
            int yPieces = (int)(heightmap.GetLength(1) / (float)ySize);

            float lastHeight = 0f;
            for (int y = 0; y < yPieces; y++)
            {
                for (int x = 0; x < xPieces; x++)
                {
                    float height = 0f;
                    if (r.NextDouble() > 0.92)
                        height = 16f * (float)r.NextDouble() - 8f;
                    else if (r.NextDouble() > 0.82)
                        height = 8f * (float)r.NextDouble() - 4f;
                    else
                        height = 1f * (float)r.NextDouble() - 1f;
                    for (int yp = 0; yp < ySize; yp++)
                        for (int xp = 0; xp < xSize; xp++)
                        {
                            if (x > 0 && y > 0)
                            {

                                heightmap[x * xSize + xp, y * ySize + yp].R = lastHeight + (height - lastHeight) * ((float)xp / (xSize - 1)) * ((float)yp / (ySize - 1)) + heightOffset;
                            }
                        }
                    lastHeight = height;
                }
            }

            var ground = new TestGround
            {
                Size = new SizeF(size.Width, size.Height),
                Heightmap = heightmap,
                NPieces = new Size(xSize, ySize),
                Height = 1,
                Simulation = motionSimulation
            };

            scene.Add(ground);
            ground.ConstructPieces();

            float[][] floatMap = new float[heightmap.GetLength(0)][];
            for (int i=0; i<heightmap.GetLength(0); i++)
            {
                floatMap[i] = new float[heightmap.GetLength(1)];
                for (int j=0; j<heightmap.GetLength(1); j++)
                {
                    floatMap[i][j] = heightmap[i, j].R;
                }
            }
            return floatMap;
        }