Exemplo n.º 1
0
        private float[] GenerateHeightMap(Biome[] biomes, int chunkX, int chunkZ)
        {
            int minX = (chunkX * 16) - 1;
            int minZ = (chunkZ * 16) - 1;
            var maxX = ((chunkX + 1) << 4) - 1;
            var maxZ = ((chunkZ + 1) << 4) - 1;

            int cx = (chunkX * 16);
            int cz = (chunkZ * 16);

            float q11 = MathHelpers.Abs(WaterLevel + (128f * biomes[0].MaxHeight) * _mainNoise.GetValue(minX, minZ));
            float q12 = MathHelpers.Abs(WaterLevel + (128f * biomes[15].MaxHeight) * _mainNoise.GetValue(minX, maxZ));

            float q21 = MathHelpers.Abs(WaterLevel + (128f * biomes[240].MaxHeight) * _mainNoise.GetValue(maxX, minZ));
            float q22 = MathHelpers.Abs(WaterLevel + (128f * biomes[255].MaxHeight) * _mainNoise.GetValue(maxX, maxZ));

            /*float q11 = WaterLevel + 128f * MathHelpers.Abs(_mainNoise.GetValue(minX, minZ));
            *  float q12 = WaterLevel + 128f * MathHelpers.Abs(_mainNoise.GetValue(minX, maxZ));
            *
            *  float q21 = WaterLevel + 128f * MathHelpers.Abs(_mainNoise.GetValue(maxX, minZ));
            *  float q22 = WaterLevel + 128f * MathHelpers.Abs(_mainNoise.GetValue(maxX, maxZ));*/

            float[] heightMap = new float[16 * 16];

            for (int x = 0; x < 16; x++)
            {
                float rx = cx + x;

                for (int z = 0; z < 16; z++)
                {
                    float rz = cz + z;

                    var baseNoise = MathHelpers.BilinearCmr(
                        rx, rz,
                        q11,
                        q12,
                        q21,
                        q22,
                        minX, maxX, minZ, maxZ);

                    heightMap[(x << 4) + z] = baseNoise;                     //WaterLevel + ((128f * baseNoise));
                }
            }
            return(heightMap);
        }
        private float FeatureBlend(IModule2D feature, GameCoordinate coordinates)
        {
            const float multFactor = 6000;
            const float stepSize   = 100;
            // guarantees coords as 0 <= coord < stepSize
            var onex       = ((coordinates.x % stepSize) + stepSize) % stepSize;
            var oney       = ((coordinates.y % stepSize) + stepSize) % stepSize;
            var altx       = onex + stepSize;
            var alty       = oney + stepSize;
            var xWeight    = onex / stepSize;
            var yWeight    = oney / stepSize;
            var invXWeight = 1 - xWeight;
            var invYWeight = 1 - yWeight;

            return(feature.GetValue(onex * multFactor, oney * multFactor) * xWeight * yWeight
                   + feature.GetValue(altx * multFactor, oney * multFactor) * invXWeight * yWeight
                   + feature.GetValue(onex * multFactor, alty * multFactor) * xWeight * invYWeight
                   + feature.GetValue(altx * multFactor, alty * multFactor) * invXWeight * invYWeight);
        }
Exemplo n.º 3
0
        public async Task <float[]> GenerateSmoothMap(IModule2D noise, float noiseMin, float noiseMax, float rangeStart, float rangeEnd, int chunkX, int chunkZ)
        {
            return(await Task.Run(() =>
            {
                int minX = ((chunkX) * 16);
                int minZ = ((chunkZ) * 16);
                var maxX = ((chunkX + 1) << 4);
                var maxZ = ((chunkZ + 1) << 4);

                int cx = (chunkX * 16);
                int cz = (chunkZ * 16);

                float q11 = noise.GetValue(minX, minZ);
                float q12 = noise.GetValue(minX, maxZ);

                float q21 = noise.GetValue(maxX, minZ);
                float q22 = noise.GetValue(maxX, maxZ);

                float[] heightMap = new float[16 * 16];

                for (int x = 0; x < 16; x++)
                {
                    float rx = cx + x;

                    for (int z = 0; z < 16; z++)
                    {
                        float rz = cz + z;

                        var baseNoise = MathUtils.BilinearCmr(
                            rx, rz,
                            q11,
                            q12,
                            q21,
                            q22,
                            minX, maxX, minZ, maxZ);

                        heightMap[(x << 4) + z] = MathUtils.ConvertRange(noiseMin, noiseMax, rangeStart, rangeEnd, baseNoise); //WaterLevel + ((128f * baseNoise));
                    }
                }

                return heightMap;
            }));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Generates an plan of values within a specified range based on the coordinates of the specified start values.
        /// </summary>
        /// <param name="module"><see cref="IModule2D"/> represent a noise generator.</param>
        /// <param name="width">The width of the plan (x-axis).</param>
        /// <param name="height">The height of the plan (y-axis).</param>
        /// <param name="scaleFactor">The scale factor of the plan.</param>
        /// <param name="range">Target range to convert the plan.</param>
        /// <param name="start_x">The start coordinate on the x-axis.</param>
        /// <param name="start_y">The start coordinate on the y-axis.</param>
        /// <returns>The resulting plan in target range.</returns>
        static public float[,] GetPlane(this IModule2D module, int width, int height, float scaleFactor, NoiseRange range, int start_x, int start_y)
        {
            float[,] rslt = new float[width, height];
            for (int w = 0; w < width; w++)
            {
                for (int h = 0; h < height; h++)
                {
                    rslt[w, h] = module.GetValue((start_x + w) * scaleFactor, (start_y + h) * scaleFactor, range);
                }
            }

            return(rslt);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Generates an output value within a specified range based on the coordinates of the specified input value.
 /// </summary>
 /// <param name="module"><see cref="IModule2D"/> represent the noise generator.</param>
 /// <param name="x">The input coordinate on the x-axis.</param>
 /// <param name="y">The input coordinate on the y-axis.</param>
 /// <param name="range">Target range to convert the output value.</param>
 /// <returns>The resulting output value in target range.</returns>
 static public float GetValue(this IModule2D module, float x, float y, NoiseRange range)
 {
     return(ToRange(module.GetValue(x, y), range));
 }
 public static float GetValue(this IModule2D module, GameCoordinate coordinates) => module.GetValue(coordinates.x, coordinates.y);