diff --git a/src/inc/generator.hpp b/src/inc/generator.hpp index 309af6f..de46047 100644 --- a/src/inc/generator.hpp +++ b/src/inc/generator.hpp @@ -2,4 +2,31 @@ void generate_world(world* out, unsigned int seed) { + // Use rand() and RAND_MAX for white noise. + + srand(seed); + + // Use FastNoise for fractal Simplex noise. + + FastNoise noise; + + noise.SetSeed(seed); + + noise.SetNoiseType(FastNoise::SimplexFractal); + + noise.SetFractalOctaves(4); + + // Generate the base terrain. + + float frequency = 4.0f; + + for (float x = 0.0f; x < float(out->x_res); x += 1.0f) + for (float y = 0.0f; y < float(out->y_res); y += 1.0f) + for (float z = 0.0f; z < float(out->z_res); z += 1.0f) + { + if (y / float(out->y_res) + noise.GetValueFractal(x * frequency, y * frequency, z * frequency) * 0.32f > 0.5f) + { + out->set_id(int(x), int(y), int(z), id_stone); + } + } } \ No newline at end of file