コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }