Esempio n. 1
0
        static public double GenInterpolatedNoise(double x, double y, double z, int seed)
        {
            int floorX = (x > 0) ? (int)x : (int)Math.Floor(x);
            int floorY = (y > 0) ? (int)y : (int)Math.Floor(y);
            int floorZ = (z > 0) ? (int)z : (int)Math.Floor(z);

            double fractionalX = x - floorX;
            double fractionalY = y - floorY;
            double fractionalZ = z - floorZ;

            double center, centerRight, bottom, bottomRight;
            double centerAbove, centerRightAbove, bottomAbove, bottomRightAbove;
            double centerInter, bottomInter, belowInter, aboveInter;

            center      = GenSmoothNoise(floorX, floorY, floorZ, seed);
            bottom      = GenSmoothNoise(floorX, floorY + 1, floorZ, seed);
            centerRight = GenSmoothNoise(floorX + 1, floorY, floorZ, seed);
            bottomRight = GenSmoothNoise(floorX + 1, floorY + 1, floorZ, seed);

            centerAbove      = GenSmoothNoise(floorX, floorY, floorZ + 1, seed);
            bottomAbove      = GenSmoothNoise(floorX, floorY + 1, floorZ + 1, seed);
            centerRightAbove = GenSmoothNoise(floorX + 1, floorY, floorZ + 1, seed);
            bottomRightAbove = GenSmoothNoise(floorX + 1, floorY + 1, floorZ + 1, seed);

            centerInter = GraphMath.CosineInterpolate(center, centerRight, fractionalX);
            bottomInter = GraphMath.CosineInterpolate(bottom, bottomRight, fractionalX);
            belowInter  = GraphMath.CosineInterpolate(centerInter, bottomInter, fractionalY);

            centerInter = GraphMath.CosineInterpolate(centerAbove, centerRightAbove, fractionalX);
            bottomInter = GraphMath.CosineInterpolate(bottomAbove, bottomRightAbove, fractionalX);
            aboveInter  = GraphMath.CosineInterpolate(centerInter, bottomInter, fractionalY);

            return(GraphMath.CosineInterpolate(belowInter, aboveInter, fractionalZ));
        }
Esempio n. 2
0
        static public double GenInterpolatedNoise(double x, double y, int seed)
        {
            int floorX = (int)x;
            int floorY = (int)y;

            double center, centerRight, bottom, bottomRight;
            double centerInter, bottomInter;

            center      = GenSmoothNoise(floorX, floorY, seed);
            centerRight = GenSmoothNoise(floorX + 1, floorY, seed);
            bottom      = GenSmoothNoise(floorX, floorY + 1, seed);
            bottomRight = GenSmoothNoise(floorX + 1, floorY + 1, seed);

            centerInter = GraphMath.CosineInterpolate(center, centerRight, floorX - x); //Interpolates the two
            bottomInter = GraphMath.CosineInterpolate(bottom, bottomRight, floorX - x); // Horizontal parts.

            return(GraphMath.CosineInterpolate(centerInter, bottomInter, y - floorY));  //Interpolatse the interpolated
                                                                                        //Horizontal parts vertically
        }