From fb80a7c111c138d335f4c7e68fc098f8aa8483d3 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Thu, 11 Dec 2014 02:53:10 -0500 Subject: Clean up Noise macros --- src/noise.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'src/noise.cpp') diff --git a/src/noise.cpp b/src/noise.cpp index 069c60d44..93f9651ed 100644 --- a/src/noise.cpp +++ b/src/noise.cpp @@ -314,7 +314,60 @@ float contour(float v) } -///////////////////////// [ New perlin stuff ] //////////////////////////// +///////////////////////// [ New noise ] //////////////////////////// + + +float NoisePerlin2D(NoiseParams *np, float x, float y, int seed) +{ + float a = 0; + float f = 1.0; + float g = 1.0; + + x /= np->spread.X; + y /= np->spread.Y; + seed += np->seed; + + for (size_t i = 0; i < np->octaves; i++) { + float noiseval = noise2d_gradient(x * f, y * f, seed + i, + np->flags & (NOISE_FLAG_DEFAULTS | NOISE_FLAG_EASED)); + + if (np->flags & NOISE_FLAG_ABSVALUE) + noiseval = fabs(noiseval); + + a += g * noiseval; + f *= np->lacunarity; + g *= np->persist; + } + + return np->offset + a * np->scale; +} + + +float NoisePerlin3D(NoiseParams *np, float x, float y, float z, int seed) +{ + float a = 0; + float f = 1.0; + float g = 1.0; + + x /= np->spread.X; + y /= np->spread.Y; + z /= np->spread.Z; + seed += np->seed; + + for (size_t i = 0; i < np->octaves; i++) { + float noiseval = noise3d_gradient(x * f, y * f, z * f, seed + i, + np->flags & NOISE_FLAG_EASED); + + if (np->flags & NOISE_FLAG_ABSVALUE) + noiseval = fabs(noiseval); + + a += g * noiseval; + f *= np->lacunarity; + g *= np->persist; + } + + return np->offset + a * np->scale; +} Noise::Noise(NoiseParams *np_, int seed, int sx, int sy, int sz) -- cgit v1.2.3