Пример #1
0
    // -------------------------------------------------------
    public TGeosphere(int seed = 0)
    {
        xSeed        = seed;
        xPerlinNoise = new TPerlin3DNoise(xSeed);         //TUnityPerlinNoise TPerlin3DNoise

        //xFBM = new OaxoaSubtractiveFBM(xPerlinNoise, 10);
        //xFBM = new FBM(xPerlinNoise);
        //xFBM = new HybridFBM(xPerlinNoise);
        xFBM = new DomainWarpingFBM(xPerlinNoise, 2);
        xFBM.SetSpectrum(10, 0.7f);
        xFBM.Scale = 0.003f;
    }
    public void Start()
    {
        offsetX = Random.Range(0, 99999);
        offsetY = Random.Range(0, 99999);

        Random.InitState(System.DateTime.Now.Millisecond);
        randomGradientVector2D = new Vector2[width, height];
        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                //randomGradientVector2D[i, j] = new Vector2(Random.Range(-0.5f, 0.5f), Random.Range(-0.5f, 0.5f));
                //print(randomGradientVector2D[i, j]);
                do
                {
                    randomGradientVector2D[i, j] = new Vector2(BetterRandom.betterRandom(-50000, 50000) / 100000f, BetterRandom.betterRandom(-50000, 50000) / 100000f);
                } while (randomGradientVector2D[i, j].x == 0 || randomGradientVector2D[i, j].y == 0 || randomGradientVector2D[i, j].x == randomGradientVector2D[i, j].y);
            }
        }

        do
        {
            randomVector = new Vector2(BetterRandom.betterRandom(-10000000, 10000000) / 100000f, BetterRandom.betterRandom(-10000000, 10000000) / 100000f);
        } while (randomVector.x == 0 || randomVector.y == 0 || randomVector.x == randomVector.y);
        randomSinMulti = BetterRandom.betterRandom(10000, 100000) + (BetterRandom.betterRandom(1000000, 10000000) / 10000000f);
        //randomSinMulti = 1;

        randomWarpStartCoords = new Vector2[20];
        for (int i = 0; i < 10; i++) // Generate random start coorinations for each warping
        {
            randomWarpStartCoords[i]      = new Vector2(BetterRandom.betterRandom(0, 1000) / 100f, BetterRandom.betterRandom(0, 1000) / 100f);
            randomWarpStartCoords[i + 10] = new Vector2(BetterRandom.betterRandom(0, 1000) / 100f, BetterRandom.betterRandom(0, 1000) / 100f);
        }

        terrain = GetComponent <Terrain>();      //for Terrain Data
        terrain.terrainData.heightmapResolution = width;
        terrain.terrainData.alphamapResolution  = width;
        terrain.terrainData.size = new Vector3(width, depth, height);

        map = new float[width, height]; // Storing the heightmap data (for the noise combination)
        if (useAlone)
        {
            terrain.terrainData = GenerateTerrain(terrain.terrainData);
        }
        else if (!useAlone)
        {
            terrain.terrainData = GenerateTerrain(terrain.terrainData);
            map = GenerateHeights(); // Storing the heightmap data (for the noise combination)
        }

        domainWarpingFBM = GetComponent <DomainWarpingFBM>();
    }