private void CreateGround(bool flatGround)
        {
            var heightmap = new Graphics.Software.Texel.R32F[50, 50];

            Random r       = new Random(42);
            int    xSize   = 4;
            int    ySize   = 4;
            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.96)
                    {
                        height = 16f * (float)r.NextDouble() - 8f;
                    }
                    else if (r.NextDouble() > 0.92)
                    {
                        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)
                            if (flatGround)
                            {
                                heightmap[x * xSize + xp, y *ySize + yp].R = 0;
                            }
                            else
                            {
                                heightmap[x * xSize + xp, y *ySize + yp].R = lastHeight + (height - lastHeight) * ((float)xp / (xSize - 1)) * ((float)yp / (ySize - 1));
                            }
                        }
                    }
                    lastHeight = height;
                }
            }

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

            scene.Add(ground);
            ground.ConstructPieces();
        }
        private void CreateGround()
        {
            var heightmap = new Graphics.Software.Texel.R32F[100, 100];

            Random r       = new Random();
            int    xSize   = 4;
            int    ySize   = 4;
            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 = 2f * (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));
                            }
                        }
                    }
                    lastHeight = height;
                }
            }


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

            scene.Add(ground);
            ground.ConstructPieces();
        }
Example #3
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 void CreateGround()
        {
            var heightmap = new Graphics.Software.Texel.R32F[100, 100];

            Random r = new Random();
            int xSize = 4;
            int ySize = 4;
            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 = 2f * (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));
                        }
                    lastHeight = height;
                }
            }

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

            scene.Add(ground);
            ground.ConstructPieces();
        }
        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 void CreateGround(bool flatGround)
        {
            var heightmap = new Graphics.Software.Texel.R32F[50, 50];

            Random r = new Random(42);
            int xSize = 4;
            int ySize = 4;
            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.96)
                        height = 16f * (float)r.NextDouble() - 8f;
                    else if (r.NextDouble() > 0.92)
                        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)
                            if (flatGround)
                                heightmap[x * xSize + xp, y * ySize + yp].R = 0;
                            else
                                heightmap[x * xSize + xp, y * ySize + yp].R = lastHeight + (height - lastHeight) * ((float)xp / (xSize - 1)) * ((float)yp / (ySize - 1));
                        }
                    lastHeight = height;
                }
            }

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

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