Added base terrain generator
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user