Example #1
0
    private void BuildRainByNoise()
    {
        MidpointDisplacement mpd = new MidpointDisplacement(MapUtil.nFromDims(xDim, yDim));

        Rain = mpd.Elevation;
        MapUtil.TransformMapMinMax(ref Rain, MapUtil.dNormalize);
    }
Example #2
0
    public float[,] NoiseGrid(int _N)
    {
        MidpointDisplacement mpd = new MidpointDisplacement(_N, wrapEastWest, wrapNorthSouth);

        float[,] elevation = mpd.Elevation;
        return(elevation);
    }
    private float[,] Generate(int chunkSeed, int generationMethod, float roughness, float offsetX, float offsetY)
    {
        float[,] heightMap;
        switch ((int)generationMethod)
        {
        case 1:
            heightMap = MidpointDisplacement.GenerateHeightMap(chunkSize, chunkSeed, 0.5f, roughness);
            break;

        case 2:
            heightMap = DiamondSquare.GenerateHeightMap(chunkSize, chunkSeed, 0.5f, roughness);
            break;

        case 3:
            heightMap = SquareSquare.GenerateHeightMap(chunkSize, chunkSeed, roughness);
            break;

        /*
         * case 4:
         *      heightMap = Perlin.GenerateHeightMap (chunkSize, chunkSeed, offsetX, offsetY, perlin_Lacunarity, perlin_Persistance, perlin_Scale);
         *      break;
         */
        default:
            heightMap = null;
            break;
        }
        return(heightMap);
    }
Example #4
0
        Dictionary <bbPos, bbLand> InitializeLandsFromMidpointDisplacement(int _N, Dictionary <string, bbPos> pm)
        {
            Dictionary <bbPos, bbLand> landsDict = new Dictionary <bbPos, bbLand>();

            MidpointDisplacement mpd = new MidpointDisplacement(_N, wrapEastWest, wrapNorthSouth);

            float[,] elevation = mpd.Elevation;
            MapUtil.TransformMapMinMax(ref elevation, MapUtil.dNormalize);
            foreach (bbPos p in pm.Values)
            {
                bbLand newLand = new bbLand(p);
                newLand.setFromValue(elevation[(int)p.gridLoc.x(), (int)p.gridLoc.y()]);
                landsDict[p] = newLand;
            }

            return(landsDict);
        }
    public void SetElevationWithMidpointDisplacement(int iExpand, Benchmark bench = null)
    {
        if (!(bench == null))
        {
            bench.StartBenchmark("Midpoint Displacement");
        }
        MidpointDisplacement mpd = new MidpointDisplacement(N);

        Elevation = mpd.Elevation;
        MapUtil.TransformMapMinMax(ref Elevation, MapUtil.dNormalize);
        if (iExpand > 1)
        {
            ExpandSquare(iExpand, iExpand);
            Smooth();
        }
        if (!(bench == null))
        {
            bench.EndBenchmark("Midpoint Displacement");
        }
    }
Example #6
0
 /// <summary>
 /// Generate Midpoint Displacement procedurally
 /// /// </summary>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="crackedPercent"></param>
 /// <param name="iterationsPercent"></param>
 /// <param name="crackDirectionChangePercent"></param>
 /// <param name="crackLengthPercent"></param>
 /// <returns>Bitmap stream in jpg format</returns>
 public async Task <Stream> GetMidpointDisplacement(int width, int height, int crackedPercent, int iterationsPercent, int crackDirectionChangePercent, int crackLengthPercent)
 {
     if ((crackedPercent < 1) || (crackedPercent > 100))
     {
         throw new ArgumentException(nameof(crackedPercent) + " must between 1 and 100");
     }
     if ((iterationsPercent < 1) || (iterationsPercent > 100))
     {
         throw new ArgumentException(nameof(iterationsPercent) + " must between 1 and 100");
     }
     if ((crackDirectionChangePercent < 1) || (crackDirectionChangePercent > 100))
     {
         throw new ArgumentException(nameof(crackDirectionChangePercent) + " must between 1 and 100");
     }
     if ((crackLengthPercent < 1) || (crackLengthPercent > 100))
     {
         throw new ArgumentException(nameof(crackLengthPercent) + " must between 1 and 100");
     }
     return(await Task.Run(() => { return GetStreamFromBitmap(MidpointDisplacement.Generate(Width: width, Height: height, NumberOfCracks: crackedPercent, Iterations: iterationsPercent, MaxChange: crackDirectionChangePercent / 10, MaxLength: crackLengthPercent, Seed: Guid.NewGuid().GetHashCode())); }));
 }
Example #7
0
        void Generate()
        {
            CleanUp();
            _chunks = new Chunk[Mathf.FloorToInt(size / chunkSize),
                Mathf.FloorToInt(worldHeight / chunkSize),
                Mathf.FloorToInt(size / chunkSize)];

            //первый запуск, строим землю
            if (!_needToLoad)
            {
                _mpd = new MidpointDisplacement(size, roughFactor, 0, worldHeight, worldHeight*0.8f);
                _mpd.SetBaseValue();
                _mpd.SetRandomValue();
                _mpd.Generate(roughValues);
                _worldData = new float[size, worldHeight, size];

                //generate all world data
                for (int i = 0; i < size*size; i++)
                {
                    float height = Mathf.Min(_mpd.data[(int) i/size, i%size], worldHeight - 1);

                    for (int h = 0; h < (int) (height); h++)
                        _worldData[(int) i/size, h, i%size] = 1;

                    if (smooth)
                    {
                        if (height >= 0)
                            _worldData[(int) i/size, (int) (height), i%size] = height - (int) height;
                    }
                }

                //разбивает worldData на чанки
                for (var i = 0; i < _chunks.GetLength(0); i++)
                {
                    for (var j = 0; j < _chunks.GetLength(1); j++)
                    {
                        for (var k = 0; k < _chunks.GetLength(2); k++)
                        {
                            float chunkX = (i * chunkSize);
                            float chunkY = (j * chunkSize);
                            float chunkZ = (k * chunkSize);

                            _chunks[i, j, k] = CreateChunk(chunkX, chunkY, chunkZ);
                            Block[, ,] chunkData = WorldToBlocks((int)chunkX, (int)chunkY, (int)chunkZ);

                            _chunks[i, j, k].Initialize(chunkData, chunkSize, chunkMaterial, this);
                        }
                    }
                }
            }
            else
            {
                var terrain = GameSaver.Instance.LoadTerrain();
                var chunksSaveData = Helper.SingleToMulti(terrain.Chunk_0, terrain.Chunk_1, terrain.Chunk_2,
                    terrain.Chunks);

                for (var i = 0; i < _chunks.GetLength(0); i++)
                {
                    for (var j = 0; j < _chunks.GetLength(1); j++)
                    {
                        for (var k = 0; k < _chunks.GetLength(2); k++)
                        {
                            var saveData = chunksSaveData[i, j, k];
                            _chunks[i, j, k] = CreateChunk(saveData.Position.x, saveData.Position.y, saveData.Position.z);
                            _chunks[i, j, k].Initialize(saveData, chunkSize, chunkMaterial, this);
                        }
                    }
                }

                terrain = null;
                chunksSaveData = null;

                _needToLoad = false;
            }

            RegenerateAllChunks();
        }
 public void Setup()
 {
     _fakeHeightOffsetGenerator = new FakeHeightOffsetGenerator();
     _sut = new MidpointDisplacement(_fakeHeightOffsetGenerator);
 }