From 42daf819df69ca000a3b148fe9f53baa3e62e865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 26 Jul 2012 21:10:12 +0000 Subject: [PATCH] paysages : Small fixes. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@401 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- lib_paysages/heightmap.c | 48 +++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/lib_paysages/heightmap.c b/lib_paysages/heightmap.c index 47b0767..d5a9016 100644 --- a/lib_paysages/heightmap.c +++ b/lib_paysages/heightmap.c @@ -121,11 +121,31 @@ double heightmapGetValue(HeightMap* heightmap, double x, double z) { int xmax = heightmap->resolution_x - 1; int zmax = heightmap->resolution_z - 1; - int xlow = floor(x * xmax); - int zlow = floor(z * zmax); + int xlow; + int zlow; double stencil[16]; int ix, iz, cx, cz; + if (x < 0.0) + { + x = 0.0; + } + else if (x > 1.0) + { + x = 1.0; + } + if (z < 0.0) + { + z = 0.0; + } + else if (z > 1.0) + { + z = 1.0; + } + + xlow = floor(x * xmax); + zlow = floor(z * zmax); + for (ix = xlow - 1; ix <= xlow + 2; ix++) { for (iz = zlow - 1; iz <= zlow + 2; iz++) @@ -152,22 +172,38 @@ static inline void _getBrushBoundaries(HeightMapBrush* brush, int rx, int rz, in *x2 = (int)ceil(cx + sx); *z1 = (int)floor(cz - sz); *z2 = (int)ceil(cz + sz); - if (*x1 < 0) + if (*x1 < 0) { *x1 = 0; } - if (*x1 > rx) + else if (*x1 > rx) { *x1 = rx; } - if (*z1 < 0) + if (*x2 < 0) + { + *x2 = 0; + } + else if (*x2 > rx) + { + *x2 = rx; + } + if (*z1 < 0) { *z1 = 0; } - if (*z1 > rz) + else if (*z1 > rz) { *z1 = rz; } + if (*z2 < 0) + { + *z2 = 0; + } + else if (*z2 > rz) + { + *z2 = rz; + } } typedef double (*BrushCallback)(HeightMap* heightmap, HeightMapBrush* brush, double x, double z, double basevalue, double influence, double force, void* data);