diff options
author | Perttu Ahola <celeron55@gmail.com> | 2011-02-28 02:01:40 +0200 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2011-02-28 02:01:40 +0200 |
commit | c8be58a65ce5f06bc23353b41caf9495e3b9d484 (patch) | |
tree | 1dc57a45f1fac9c2f7730bb2c80201e46ec70997 /src/noise.cpp | |
parent | 5707c309c9c84589a964067477027b775a511aeb (diff) | |
download | hax-minetest-server-c8be58a65ce5f06bc23353b41caf9495e3b9d484.tar.gz hax-minetest-server-c8be58a65ce5f06bc23353b41caf9495e3b9d484.zip |
A third try on terrain generation. No trees yet.
Diffstat (limited to 'src/noise.cpp')
-rw-r--r-- | src/noise.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/noise.cpp b/src/noise.cpp index 63682e1e4..bc5148545 100644 --- a/src/noise.cpp +++ b/src/noise.cpp @@ -92,8 +92,7 @@ double noise3d(int x, int y, int z, int seed) return 1.0 - (double)n/1073741824; } -#if 0 -// This is too slow +#if 1 double noise2d_gradient(double x, double y, int seed) { // Calculate the integer coordinates @@ -118,7 +117,7 @@ double noise2d_gradient(double x, double y, int seed) } #endif -#if 1 +#if 0 double noise2d_gradient(double x, double y, int seed) { // Calculate the integer coordinates @@ -175,6 +174,21 @@ double noise2d_perlin(double x, double y, int seed, return a; } +double noise2d_perlin_abs(double x, double y, int seed, + int octaves, double persistence) +{ + double a = 0; + double f = 1.0; + double g = 1.0; + for(int i=0; i<octaves; i++) + { + a += g * fabs(noise2d_gradient(x*f, y*f, seed+i)); + f *= 2.0; + g *= persistence; + } + return a; +} + double noise3d_perlin(double x, double y, double z, int seed, int octaves, double persistence) { @@ -190,3 +204,18 @@ double noise3d_perlin(double x, double y, double z, int seed, return a; } +double noise3d_perlin_abs(double x, double y, double z, int seed, + int octaves, double persistence) +{ + double a = 0; + double f = 1.0; + double g = 1.0; + for(int i=0; i<octaves; i++) + { + a += g * fabs(noise3d_gradient(x*f, y*f, z*f, seed+i)); + f *= 2.0; + g *= persistence; + } + return a; +} + |