示例#1
0
        /// <summary>
        /// Run the generator against a world.
        /// </summary>
        /// <param name="world">The world to generate against.</param>
        public void RunGeneration(TWorld world)
        {
            var biasMap = (float[, ])null;

            switch (_biasType)
            {
            case HeightmapBias.CONTINENTS:
                biasMap = CreateRandomBias(world, CONTINENT_BIAS_SIZE);
                break;

            case HeightmapBias.AZEROTH:
                biasMap = CreateAzerothBias(world);
                break;

            case HeightmapBias.ISLANDS:
                biasMap = CreateRandomBias(world, ISLAND_BIAS_SIZE);
                break;

            case HeightmapBias.NONE:
                biasMap = CreateNoneBias(world);
                break;

            case HeightmapBias.LANDMASS:
                biasMap = CreateLandmassBias(world);
                break;

            default:
                throw new Exception("Unknown HeightmassBias: " + _biasType);
            }

            var noise = new SimplexNoiseGenerator(world.Seed + "height".GetHashCode());

            var noiseMap = new float[world.Width, world.Height];

            for (int x = 0; x < world.Width; x++)
            {
                for (int y = 0; y < world.Height; y++)
                {
                    noiseMap[x, y] = noise.CoherentNoise(x, y, 0, _octaves, _scale, 0.5f, _lacunarity, _persistence);
                }
            }

            noiseMap = MapUtil.Normalize(noiseMap);

            for (int x = 0; x < world.Width; x++)
            {
                for (int y = 0; y < world.Height; y++)
                {
                    world.GetCell(x, y).Height = world.MaxElevation * noiseMap[x, y] * biasMap[x, y];
                }
            }
        }
示例#2
0
        private float[,] CreateRandomBias(TWorld world, int biasGridSize)
        {
            var noise = new SimplexNoiseGenerator(world.Seed + "height_bias".GetHashCode());

            var biasGrid = new float[biasGridSize, biasGridSize];

            for (int x = 0; x < biasGridSize; x++)
            {
                for (int y = 0; y < biasGridSize; y++)
                {
                    biasGrid[x, y] = noise.CoherentNoise(x, y, 0, 1, 3, 0.5f, 2, 0.9f);
                }
            }

            biasGrid = MapUtil.Normalize(biasGrid);

            for (int x = 0; x < biasGridSize; x++)
            {
                for (int y = 0; y < biasGridSize; y++)
                {
                    if (x <= 0 || x >= biasGridSize - 1 || y <= 0 || y >= biasGridSize - 1)
                    {
                        //Force a bias of zero at the edges.
                        biasGrid[x, y] = 0;
                    }
                    else
                    {
                        //select high points

                        if (biasGrid[x, y] > 0.6)
                        {
                            biasGrid[x, y] = 1;
                        }
                        else
                        {
                            biasGrid[x, y] = 0;
                        }
                    }
                }
            }

            return(ExpandBiasGridToMap(world, biasGrid, biasGridSize));
        }
        /// <summary>
        /// Run the generator against a world.
        /// </summary>
        /// <param name="world">The world to generate against.</param>
        public void RunGeneration(TWorld world)
        {
            var noiseMap = new float[world.Width, world.Height];

            var mountainNoise = new SimplexNoiseGenerator(world.Seed + "mountain_ridge".GetHashCode());

            for (int x = 0; x < world.Width; x++)
            {
                for (int y = 0; y < world.Height; y++)
                {
                    noiseMap[x, y] = Math.Abs(mountainNoise.CoherentNoise(x, y, 0, 1, 250, 0.5f, 2, 0.4f));
                }
            }

            noiseMap = MapUtil.Normalize(noiseMap);

            var newHeightMap = new float[world.Width, world.Height];

            for (int x = 0; x < world.Width; x++)
            {
                for (int y = 0; y < world.Height; y++)
                {
                    var noiseValue = 1 - (noiseMap[x, y] - 0.2f) * 1.25f;

                    var percHeight = world.GetCell(x, y).Height / world.MaxElevation;

                    newHeightMap[x, y] = 0.7f * percHeight + 0.3f * noiseValue * (0.5f + percHeight / 2);
                }
            }

            newHeightMap = MapUtil.Normalize(newHeightMap);

            for (int x = 0; x < world.Width; x++)
            {
                for (int y = 0; y < world.Height; y++)
                {
                    world.GetCell(x, y).Height = world.MaxElevation * newHeightMap[x, y];
                }
            }
        }
        /// <summary>
        /// Run the generator against a world.
        /// </summary>
        /// <param name="world">The world to generate against.</param>
        public void RunGeneration(TWorld world)
        {
            var oceanBiaser = new OceanBiaser <TWorld, TCell>();

            oceanBiaser.CreateBiasPoints(world, 25);

            var noise = new SimplexNoiseGenerator(world.Seed + "temperature".GetHashCode());

            var noiseMap = new float[world.Width, world.Height];

            for (int x = 0; x < world.Width; x++)
            {
                for (int y = 0; y < world.Height; y++)
                {
                    noiseMap[x, y] = noise.CoherentNoise(x, y, 0, 3, 100, 0.5f, 2, 0.4f);
                }
            }

            noiseMap = MapUtil.Normalize(noiseMap);

            for (int x = 0; x < world.Width; x++)
            {
                for (int y = 0; y < world.Height; y++)
                {
                    var baseT = y / (float)world.Height * 2;

                    if (y > world.Height / 2)
                    {
                        baseT = (world.Height - y) / (float)world.Height * 2;
                    }

                    var oceanBias = 1f - 0.3f * oceanBiaser.OceanBiasAt(new CellAddress(x, y));

                    world.GetCell(x, y).Temperature = (0.8f * baseT + 0.2f * noiseMap[x, y]) * oceanBias;
                }
            }
        }
        /// <summary>
        /// Run the generator against a world.
        /// </summary>
        /// <param name="world">The world to generate against.</param>
        public void RunGeneration(TWorld world)
        {
            var oceanBiaser = new OceanBiaser <TWorld, TCell>();

            oceanBiaser.CreateBiasPoints(world, 25);

            var noise = new SimplexNoiseGenerator(world.Seed + "rain".GetHashCode());

            var rainfallMap = new float[world.Width, world.Height];

            for (int x = 0; x < world.Width; x++)
            {
                for (int y = 0; y < world.Height; y++)
                {
                    var bias = (float)(-1 * Math.Cos(y / Math.PI / (world.Height / 6f)) / 2 + 0.5f);
                    bias = 0.75f * bias + 0.25f;

                    rainfallMap[x, y] = noise.CoherentNoise(x, y, 0, 3, 75, 0.5f, 2, 0.4f) * bias;
                }
            }

            rainfallMap = MapUtil.Normalize(rainfallMap);

            for (int x = 0; x < world.Width; x++)
            {
                for (int y = 0; y < world.Height; y++)
                {
                    if (!IsOcean(x, y, world))
                    {
                        var oceanBias = oceanBiaser.OceanBiasAt(new CellAddress(x, y));

                        world.GetCell(x, y).Rainfall = 0.8f * rainfallMap[x, y] + 0.2f * oceanBias;
                    }
                }
            }
        }
        /// <summary>
        /// Run the generator against a world.
        /// </summary>
        /// <param name="world">The world to generate against.</param>
        public void RunGeneration(TWorld world)
        {
            var noise = new SimplexNoiseGenerator(world.Seed + "rain".GetHashCode());

            var noiseMap = new float[world.Width, world.Height];

            for (int x = 0; x < world.Width; x++)
            {
                for (int y = 0; y < world.Height; y++)
                {
                    noiseMap[x, y] = noise.CoherentNoise(x, y, 0, _octaves, _scale, 0.5f, _lacunarity, _persistence);
                }
            }

            noiseMap = MapUtil.Normalize(noiseMap);

            for (int x = 0; x < world.Width; x++)
            {
                for (int y = 0; y < world.Height; y++)
                {
                    world.GetCell(x, y).Rainfall = noiseMap[x, y];
                }
            }
        }