aboutsummaryrefslogtreecommitdiffstats
path: root/src/world.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c38
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;