Beispiel #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));
                }
            });
        }
Beispiel #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);
        }
		static TerrainData CreateTerrain(IntSize3 size)
		{
			//var random = Helpers.Random;
			var random = new Random(1);

			var terrain = new TerrainData(size);

			var tg = new TerrainGenerator(terrain, random);

			var corners = new DiamondSquare.CornerData()
			{
				NE = 15,
				NW = 10,
				SW = 10,
				SE = 10,
			};

			tg.Generate(corners, 5, 0.75, 2);

			int grassLimit = terrain.Depth * 4 / 5;
			TerrainHelpers.CreateVegetation(terrain, random, grassLimit);

			return terrain;
		}
Beispiel #4
0
        void Generate()
        {
            var corners = new DiamondSquare.CornerData()
            {
                NW = ParseDouble(cornerNWTextBox.Text),
                NE = ParseDouble(cornerNETextBox.Text),
                SE = ParseDouble(cornerSETextBox.Text),
                SW = ParseDouble(cornerSWTextBox.Text),
            };

            //m_terrainGen.Generate(corners, this.RangeValue, this.HValue, this.Seed, this.Amplify);
            m_terrainGen.Generate(this.Seed);
        }