commit 18ba03463e02ed86ed00b371947997c9a58dcb6f
parent 5d1a173bea9026bf34c8e135d3fe68d122710aa7
Author: William Casarin <jb55@jb55.com>
Date: Fri, 8 May 2020 19:31:47 -0700
dampen terrain height near edge
Diffstat:
1 file changed, 12 insertions(+), 0 deletions(-)
diff --git a/src/terrain.c b/src/terrain.c
@@ -195,6 +195,13 @@ static int collide_terrain_debug(struct terrain *terrain, struct terrain_cell *c
}
#endif /* DEBUG */
+static double distance_to_closest_edge(double size, double x, double y) {
+ double top = y;
+ double left = x;
+ double right = size - x;
+ double bottom = size - y;
+ return min(top, min(left, min(right, bottom)));
+}
void create_terrain(struct terrain *terrain, float scale, int seed) {
u32 i;
@@ -245,6 +252,11 @@ void create_terrain(struct terrain *terrain, float scale, int seed) {
int grid_x = verts[n] / terrain->cell_size;
int grid_y = verts[n+1] / terrain->cell_size;
+ // clamp height at edge
+
+ double d = distance_to_closest_edge(size, x, y);
+ z *= d / (size/2.0);
+
struct terrain_cell *cell =
index_terrain_cell(terrain, grid_x, grid_y);