--- deliantra/server/common/noise.C 2011/04/23 04:46:25 1.4 +++ deliantra/server/common/noise.C 2011/04/23 06:35:55 1.7 @@ -1,7 +1,7 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * * Deliantra is free software: you can redistribute it and/or modify it under * the terms of the Affero GNU General Public License as published by the @@ -25,6 +25,7 @@ ///////////////////////////////////////////////////////////////////////////// // http://www-wales.ch.cam.ac.uk/~wales/CCD/Thomson/table.html, random permutation +// used as gradient vectors for noise3d static const float charges[256][3] = { 6.32096444e-01, -6.11406706e-01, 4.76062943e-01, 5.19172442e-01, 8.08229585e-01, -2.77893708e-01, -8.81072422e-01, -4.68301230e-01, 6.63727731e-02, -1.92122323e-01, 9.81341519e-01, -7.60505942e-03, @@ -156,6 +157,25 @@ -3.07350590e-01, -9.14677987e-01, 2.62487703e-01, 5.60298616e-01, 1.74821302e-01, 8.09631381e-01, }; +///////////////////////////////////////////////////////////////////////////// + +template +template +void +permutation::seed (random_generator &rng) +{ + for (int i = 0; i < N; ++i) + pmap[i] = i; + + // fisher-yates to randomly perturb + for (int i = N; --i; ) + ::swap (pmap[i], pmap[rng (i + 1)]); +} + +template class permutation<256, uint8_t>; + +///////////////////////////////////////////////////////////////////////////// + static vec2d floor (vec2d v) { @@ -172,7 +192,7 @@ { seedable_rand_gen rng (seed); -#if 1 +#if 0 for (int i = 0; i < 256; ++i) { vec2d rv (rng () - 0.5f, rng () - 0.5f); @@ -187,12 +207,12 @@ } #endif -#if 0 - float offset = rng () * 3.14159265; +#if 1 + float offset = rng () * M_PI; for (int i = 0; i < 256; ++i) { - float phi = i * (3.14159265 * 2 / 256) + offset; + float phi = i * (M_PI * 2 / 256) + offset; rvec[i][0] = sinf (phi); rvec[i][1] = -cosf (phi); @@ -518,13 +538,13 @@ ///////////////////////////////////////////////////////////////////////////// -#if 0 -void hack(); void hack() +void noise_test (); +void noise_test () { - frac_gen gen (0.5, 2); + frac_gen gen (0.5, 1.9); frac_gen gen3; -#if 0 +#if 1 int N = 1024; printf ("P5 %d %d 255\n", N, N); @@ -537,7 +557,7 @@ //putc (127 * n.noise (x * 0.1, y * 0.1, 0, 0,0,1) + 128, stdout); //putc (256 * gen.terrain2 (x * 0.004, y * 0.004, 8), stdout); //putc (256 * gen.fBm (x * 0.01, y * 0.01, 3), stdout); - //putc (256 * gen.turbulence (x * 0.004 - 1, y * 0.004 - 1, 8), stdout); + putc (256 * gen.turbulence (vec2d (x * 0.004 - 1, y * 0.004 - 1), 8), stdout); //putc (256 * gen.heterofractal (x * 0.008, y * 0.008, 8, 0.9), stdout); // mountais or somesuch(?) @@ -546,7 +566,9 @@ // temperature //putc (256 * gen.fBm (x * 0.002, y * 0.002, 2), stdout); // rain - //putc (256 * gen.ridgedmultifractal (x * 0.01, y * 0.01, 3, 1.03, 2), stdout); + + //cells + //putc (256 * gen.ridgedmultifractal (vec2d (x * 0.01, y * 0.01), 3, 0.5 + gen.noise(vec2d(x*0.01,y*0.01)), 2), stdout); } } #else @@ -592,4 +614,3 @@ exit (0); } -#endif