Exemplo n.º 1
0
        public static float GetCanyonNoise(Vector2 position, NoiseParameters noiseParameters, FastNoise noise, CanyonParameters canyonParameters, int seed = 0)
        {
            //Noise Height, Value bettween CayonParameters's limits, Results
            float n  = 1.0f - GetFractalErosionNoise(position, noiseParameters, noise, seed);
            float n2 = MathFunc.Clamp01(MathFunc.Lerp(0f, 1f, MathFunc.InverseLerp(canyonParameters.minCanyonHeight, canyonParameters.canyonPlateauHeight, n)));
            float h  = 0f;
            float t  = (canyonParameters.canyonPlateauHeight - canyonParameters.minCanyonHeight);

            if (n <= canyonParameters.canyonPlateauHeight)
            {
                if (n >= canyonParameters.minCanyonHeight)
                {
                    h = canyonParameters.GetValueAtHeight(n2);
                    return(h);
                }
                else
                {
                    return(canyonParameters.minCanyonHeight - n * -3f);
                }
            }
            else
            {
                //h = (n*(canyonParameters.canyonPlateauHeight-canyonParameters.minCanyonHeight)/2f)+1f;
                //h = (n-t)*0.2f+t;
                float x = 1f;
                //h = (n)*x+(t*(x*2)+0);
                h = 1 + (n - canyonParameters.canyonPlateauHeight) * 0.2f;
                return(h);
            }
        }
Exemplo n.º 2
0
    public static float LerpAngle(float a, float b, float t)
    {
        float num = MathFunc.Repeat(b - a, 360f);

        if (num > 180f)
        {
            num -= 360f;
        }
        return(a + num * MathFunc.Clamp01(t));
    }
Exemplo n.º 3
0
        public float LevelProgress(int exp)
        {
            int   levelForExp = LevelForExp(exp);
            int   levelExp    = ExpForLevel(levelForExp);
            float expDiff     = exp - levelExp;
            float expDelta    = ExpToNextLevel(levelForExp);

            if (expDelta == 0)
            {
                return(1f);
            }
            return(MathFunc.Clamp01((float)expDiff / (float)expDelta));
        }
Exemplo n.º 4
0
    public static float InverseLerp(float a, float b, float value)
    {
        float result;

        if (a != b)
        {
            result = MathFunc.Clamp01((value - a) / (b - a));
        }
        else
        {
            result = 0f;
        }
        return(result);
    }
Exemplo n.º 5
0
        public static float GetFractalAlpsNoise(Vector2 position, NoiseParameters noiseParameters, FastNoise noise, int seed = 0)
        {
            float   warp = 1.5f;
            float   sum = 0f;
            float   freq = 1.0f, amp = 1.0f;
            Vector2 dsum = new Vector2(0, 0);

            for (int i = 0; i < noiseParameters.octaves; i++)
            {
                Vector3 n = GetDerivativePerlinNoise(position * freq, noise, seed + i);
                sum  += amp * (1 - MathFunc.Abs(n.x));
                dsum += amp * new Vector2(n.y, n.z) * -n.x;
                freq *= noiseParameters.lacunarity;
                amp  *= noiseParameters.gain * MathFunc.Clamp01(sum);
            }
            return(sum);
        }
Exemplo n.º 6
0
 public static float SmoothStep(float from, float to, float t)
 {
     t = MathFunc.Clamp01(t);
     t = -2f * t * t * t + 3f * t * t;
     return(to * t + from * (1f - t));
 }
Exemplo n.º 7
0
 public static float Lerp(float a, float b, float t)
 {
     return(a + (b - a) * MathFunc.Clamp01(t));
 }