From edc6fb1e5c4a0fe8142d571b40f358a1b964b2e0 Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Tue, 1 Oct 2024 15:31:18 +0300 Subject: [PATCH] /apps/scenery: make the world generate as you go --- apps/scenery/scenes/ingame.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/scenery/scenes/ingame.c b/apps/scenery/scenes/ingame.c index 2d3ca37..2e49be6 100644 --- a/apps/scenery/scenes/ingame.c +++ b/apps/scenery/scenes/ingame.c @@ -56,8 +56,11 @@ static void ingame_tick(State *state) { #define TERRAIN_FREQUENCY 0.1f - for (int y = 64; y--;) { - for (int x = 64; x--;) { + for (int ly = 64; ly--;) { + for (int lx = 64; lx--;) { + float x = SDL_truncf(scn->cam.pos.x + 32 - lx); + float y = SDL_truncf(scn->cam.pos.z + 32 - ly); + float d0 = stb_perlin_noise3((float)x * TERRAIN_FREQUENCY, (float)y * TERRAIN_FREQUENCY, 0, 0, 0, 0) * 3 - 6; float d1 = stb_perlin_noise3((float)(x + 1) * TERRAIN_FREQUENCY, (float)y * TERRAIN_FREQUENCY, 0, 0, 0, 0) * 3 - 6; float d2 = stb_perlin_noise3((float)(x + 1) * TERRAIN_FREQUENCY, (float)(y - 1) * TERRAIN_FREQUENCY, 0, 0, 0, 0) * 3 - 6;