public Chunk Generate(Vector3 position) { const float MaxHeight = 14.0f; var chunk = new Chunk(position); float scaleX = 0.5f; float scaleZ = 0.5f; float sx = 1.0f / (Chunk.Width * scaleX); float sz = 1.0f / (Chunk.Depth * scaleZ); for (uint x = 0; x < Chunk.Width; ++x) { for (uint z = 0; z < Chunk.Depth; ++z) { float amplitude = _amplitude; float frequency = _frequency; float height = 0.0f; for (uint octave = 0; octave < _octaves; ++octave) { float mx = (position.X + x) * frequency; float mz = (position.Z + z) * frequency; var result = _noise.Evaluate(mx * sx, mz * sz); height += (float)Math.Max(Math.Min(result, 1.0), -1.0) * amplitude; frequency *= 2.0f; amplitude /= 2.0f; } height = (height + 1.0f) / 2.0f; float hy = (float)Math.Round(height * MaxHeight); for (uint y = 0; y < Chunk.Height; ++y) { float my = (position.Y + y); if (my <= hy) { chunk.Set(x, y, z, BlockType.Dirt); } else { chunk.Set(x, y, z, BlockType.Air); } } } } return(chunk); }