X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fnoise.cpp;h=35057146da9c919c7bb8d90f64451bc51dd0431c;hb=206f0764225de4eeb3b2cef119e22df8005e5d60;hp=bfb1960c846c426d2d6104a0ea9162422af0e3c6;hpb=8d920dd09b2c354bf9993d9184132f7f2a68b027;p=oweals%2Fminetest.git diff --git a/src/noise.cpp b/src/noise.cpp index bfb1960c8..35057146d 100644 --- a/src/noise.cpp +++ b/src/noise.cpp @@ -1,6 +1,7 @@ /* -Minetest-c55 -Copyright (C) 2010-2011 celeron55, Perttu Ahola +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola +Copyright (C) 2010-2013 kwolekr, Ryan Kwolek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -20,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "noise.h" #include +#include // memset #include "debug.h" #include "util/numeric.h" @@ -507,7 +509,7 @@ void Noise::gradientMap3D(float x, float y, float z, float *Noise::perlinMap2D(float x, float y) { - float a = 0.0, f = 1.0, g = 1.0; + float f = 1.0, g = 1.0; int i, j, index, oct; x /= np->spread.X; @@ -536,8 +538,43 @@ float *Noise::perlinMap2D(float x, float y) { } +float *Noise::perlinMap2DModulated(float x, float y, float *persist_map) { + float f = 1.0; + int i, j, index, oct; + + x /= np->spread.X; + y /= np->spread.Y; + + memset(result, 0, sizeof(float) * sx * sy); + + float *g = new float[sx * sy]; + for (index = 0; index != sx * sy; index++) + g[index] = 1.0; + + for (oct = 0; oct < np->octaves; oct++) { + gradientMap2D(x * f, y * f, + f / np->spread.X, f / np->spread.Y, + seed + np->seed + oct); + + index = 0; + for (j = 0; j != sy; j++) { + for (i = 0; i != sx; i++) { + result[index] += g[index] * buf[index]; + g[index] *= persist_map[index]; + index++; + } + } + + f *= 2.0; + } + + delete[] g; + return result; +} + + float *Noise::perlinMap3D(float x, float y, float z) { - float a = 0.0, f = 1.0, g = 1.0; + float f = 1.0, g = 1.0; int i, j, k, index, oct; x /= np->spread.X;