Beispiel #1
0
        private float GenInterpolatedNoise(float x, float y, float z)
        {
            int floorX = (x > 0) ? (int)x : (int)x - 1;
            int floorY = (y > 0) ? (int)y : (int)y - 1;
            int floorZ = (z > 0) ? (int)z : (int)z - 1;

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

            float centerInter, bottomInter, belowInter, aboveInter;

            FastPerlinInterpolatedNoise3D noise;

            Vector3 key = new Vector3(floorX, floorY, floorZ);

            calcLookup.TryGetValue(key, out noise);

            if (noise == null)
            {
                noise             = new FastPerlinInterpolatedNoise3D();
                noise.center      = GenSmoothNoise(floorX, floorY, floorZ);
                noise.bottom      = GenSmoothNoise(floorX, floorY + 1, floorZ);
                noise.centerRight = GenSmoothNoise(floorX + 1, floorY, floorZ);
                noise.bottomRight = GenSmoothNoise(floorX + 1, floorY + 1, floorZ);

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

                calcLookup.Add(key, noise);
            }

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

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

            return(GraphMath.LinearInterpolateFloat(belowInter, aboveInter, fractionalZ));
        }
        private float GenInterpolatedNoise(float x, float y, float z)
        {
            int floorX = (x > 0) ? (int)x : (int)x - 1;
            int floorY = (y > 0) ? (int)y : (int)y - 1;
            int floorZ = (z > 0) ? (int)z : (int)z - 1;

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

            float centerInter, bottomInter, belowInter, aboveInter;

            FastPerlinInterpolatedNoise3D noise;

            Vector3 key = new Vector3(floorX, floorY, floorZ);

            calcLookup.TryGetValue(key, out noise);

            if(noise == null)
            {
                noise = new FastPerlinInterpolatedNoise3D();
                noise.center = GenSmoothNoise(floorX, floorY, floorZ);
                noise.bottom = GenSmoothNoise(floorX, floorY + 1, floorZ);
                noise.centerRight = GenSmoothNoise(floorX + 1, floorY, floorZ);
                noise.bottomRight = GenSmoothNoise(floorX + 1, floorY + 1, floorZ);

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

                calcLookup.Add(key, noise);
            }

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

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

            return GraphMath.LinearInterpolateFloat(belowInter, aboveInter, fractionalZ);
        }