diff options
author | nathan <nathan@disroot.org> | 2025-07-30 09:37:32 +0000 |
---|---|---|
committer | nathan <nathan@disroot.org> | 2025-07-30 09:37:32 +0000 |
commit | 1163519c148d0cc7d885630995874af2747419d0 (patch) | |
tree | 95398d5f19e774377236af351d4e3936371fb2cd /src/world.c | |
parent | 384fa265c8493aff5f37921cf98034bb847915a2 (diff) | |
download | FindThings-1163519c148d0cc7d885630995874af2747419d0.tar.gz FindThings-1163519c148d0cc7d885630995874af2747419d0.tar.bz2 FindThings-1163519c148d0cc7d885630995874af2747419d0.zip |
More pond stuff
Diffstat (limited to 'src/world.c')
-rw-r--r-- | src/world.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/world.c b/src/world.c index 87ca0d4..7b9abe4 100644 --- a/src/world.c +++ b/src/world.c @@ -395,11 +395,41 @@ Seed generateWorldItems(World* world, Seed seed, int start, int end) Seed generatePond(World* world, Color* heightmap, WorldUID id, Seed seed) { + // Create pond entity. Vector3 position = getRandomPositionFromCenter(world, &seed, PLACE_POND_MIN_DISTANCE, PLACE_POND_MAX_DISTANCE); Entity pond = createEntity(POND, position); world->entities[id] = pond; + + // Get lowest height. + int height = 255; + + Vector2 start = worldPositionToPixel(world, pond.box.min.x, pond.box.min.z); + Vector2 end = worldPositionToPixel(world, pond.box.max.x, pond.box.max.z); + + for (int y = start.y; y < end.y; ++y) + { + for (int x = start.x; x < end.x; ++x) + { + int pixelHeight = heightmap[y * WORLD_IMAGE_WIDTH + x].r; + + if (pixelHeight < height) + { + height = pixelHeight; + } + } + } + + // Set new height. + for (int y = start.y; y < end.y; ++y) + { + for (int x = start.x; x < end.x; ++x) + { + heightmap[y * WORLD_IMAGE_WIDTH + x] = + (Color){height, height, height, 255}; + } + } return seed; } @@ -540,6 +570,14 @@ void freeWorld(World world) freeWorldBVH(world.bvh); } +Vector2 worldPositionToPixel(const World* world, float x, float y) +{ + return (Vector2){ + roundf((float)WORLD_IMAGE_WIDTH / world->size.x * x), + roundf((float)WORLD_IMAGE_HEIGHT / world->size.z * y) + }; +} + float getWorldHeightAtLocation(const World* world, float x, float y) { float mapX = (float)WORLD_IMAGE_WIDTH / world->size.x * x; |