/// Produces a heightmap using the Perlin noise generator.
    /// Returns true if the map must be renormalized.
    /// The debugHeightmap parameter is used for debug to display the generated curve (with higher precision).
    /// See e2dGeneratorCurveMethod for details.
    private bool GenerateCurvePerlin(float[] heightMap, Rect targetRect, ref float[] debugHeightmap)
    {
        // init the noise
        int frequency = 1 + Mathf.RoundToInt(Perlin.frequencyPerUnit * targetRect.width);

        frequency = Mathf.Max(frequency, 2);
        e2dPerlinNoise function = new e2dPerlinNoise(Perlin.octaves, 1.0f, frequency, Perlin.persistence);

        // produce some values
        function.Regenerate();

        // fill the heightmap
        for (int i = 0; i < heightMap.Length; i++)
        {
            float x = (float)i / (float)(heightMap.Length - 1);
            heightMap[i] = function.GetValue(x);
        }

        // fill the heightmap for debug
        if (e2dUtils.DEBUG_GENERATOR_CURVE)
        {
            debugHeightmap = new float[10 * heightMap.Length];
            for (int i = 0; i < debugHeightmap.Length; i++)
            {
                float x = (float)i / (float)(debugHeightmap.Length - 1);
                debugHeightmap[i] = function.GetValue(x) * targetRect.height;
            }
        }

        return(true);
    }
Esempio n. 2
0
    private bool GenerateCurvePerlin(float[] heightMap, Rect targetRect, ref float[] debugHeightmap)
    {
        int num = 1 + Mathf.RoundToInt(this.Perlin.frequencyPerUnit * targetRect.width);

        num = Mathf.Max(num, 2);
        e2dPerlinNoise e2dPerlinNoise = new e2dPerlinNoise(this.Perlin.octaves, 1f, num, this.Perlin.persistence);

        e2dPerlinNoise.Regenerate();
        for (int i = 0; i < heightMap.Length; i++)
        {
            float x = (float)i / (float)(heightMap.Length - 1);
            heightMap[i] = e2dPerlinNoise.GetValue(x);
        }
        if (e2dUtils.DEBUG_GENERATOR_CURVE)
        {
            debugHeightmap = new float[10 * heightMap.Length];
            for (int j = 0; j < debugHeightmap.Length; j++)
            {
                float x2 = (float)j / (float)(debugHeightmap.Length - 1);
                debugHeightmap[j] = e2dPerlinNoise.GetValue(x2) * targetRect.height;
            }
        }
        return(true);
    }