示例#1
0
        void GenerateHeightMap(DiamondSquare.CornerData corners, double range, double h, double amplify)
        {
            // +1 for diamond square
            var heightMap = new ArrayGrid2D <double>(m_size.Width + 1, m_size.Height + 1);

            double min, max;

            DiamondSquare.Render(heightMap, corners, range, h, m_random, out min, out max);

            Parallel.For(0, m_size.Height, y =>
            {
                double d = max - min;

                for (int x = 0; x < m_size.Width; ++x)
                {
                    var v = heightMap[x, y];

                    // normalize to 0.0 - 1.0
                    v = (v - min) / d;

                    // amplify
                    v = Math.Pow(v, amplify);

                    // adjust
                    v *= m_size.Depth / 2;
                    v += m_size.Depth / 2 - 1;

                    m_data.SetSurfaceLevel(x, y, MyMath.Round(v));
                }
            });
        }
示例#2
0
        public void Generate(DiamondSquare.CornerData corners, double range, double h, double amplify)
        {
            GenerateHeightMap(corners, range, h, amplify);

            FillMap();

            var random = m_random;
            var terrain = m_data;

            double xk = (random.NextDouble() * 2 - 1) * 0.01;
            double yk = (random.NextDouble() * 2 - 1) * 0.01;
            TerrainHelpers.CreateBaseMinerals(terrain, random, xk, yk);

            TerrainHelpers.CreateOreVeins(terrain, random, xk, yk);

            TerrainHelpers.CreateOreClusters(terrain, random);

            if (m_data.Width > 128)
            {
                var riverGen = new RiverGen(m_data, m_random);
                if (riverGen.CreateRiverPath())
                {
                    riverGen.AdjustRiver();
                }
                else
                {
                    Trace.TraceError("Failed to create river");
                }
            }

            int soilLimit = m_size.Depth * 4 / 5;
            TerrainHelpers.CreateSoil(m_data, soilLimit);
        }
示例#3
0
        public void Generate(DiamondSquare.CornerData corners, double range, double h, int seed, double amplify)
        {
            GenerateTerrain(corners, range, h, seed, amplify);

            CreateTileGrid();
        }
示例#4
0
        void GenerateTerrain(DiamondSquare.CornerData corners, double range, double h, int seed, double amplify)
        {
            // +1 for diamond square
            var doubleHeightMap = new ArrayGrid2D<double>(m_size.Width + 1, m_size.Height + 1);

            double min, max;

            DiamondSquare.Render(doubleHeightMap, corners, range, h, seed, out min, out max);

            var heightMap = m_data.HeightMap;

            Parallel.For(0, m_size.Height, y =>
                {
                    double d = max - min;

                    for (int x = 0; x < m_size.Width; ++x)
                    {
                        var v = doubleHeightMap[x, y];

                        // normalize to 0.0 - 1.0
                        v = (v - min) / d;

                        // amplify
                        v = Math.Pow(v, amplify);

                        // adjust
                        v *= m_size.Depth / 2;
                        v += m_size.Depth / 2 - 1;

                        heightMap[y, x] = (byte)Math.Round(v);
                    }
                });
        }
示例#5
0
        void GenerateHeightMap(DiamondSquare.CornerData corners, double range, double h, double amplify)
        {
            // +1 for diamond square
            var heightMap = new ArrayGrid2D<double>(m_size.Width + 1, m_size.Height + 1);

            double min, max;

            DiamondSquare.Render(heightMap, corners, range, h, m_random, out min, out max);

            Parallel.For(0, m_size.Height, y =>
                {
                    double d = max - min;

                    for (int x = 0; x < m_size.Width; ++x)
                    {
                        var v = heightMap[x, y];

                        // normalize to 0.0 - 1.0
                        v = (v - min) / d;

                        // amplify
                        v = Math.Pow(v, amplify);

                        // adjust
                        v *= m_size.Depth / 2;
                        v += m_size.Depth / 2 - 1;

                        m_data.SetSurfaceLevel(x, y, MyMath.Round(v));
                    }
                });
        }