3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 PseudoRandom(): m_next(0)
32 PseudoRandom(int seed): m_next(seed)
42 m_next = m_next * 1103515245 + 12345;
43 return((unsigned)(m_next/65536) % 32768);
45 int range(int min, int max)
47 if(max-min > 32768/10)
49 //dstream<<"WARNING: PseudoRandom::range: max > 32767"<<std::endl;
57 return (next()%(max-min+1))+min;
84 Noise(NoiseParams *np, int seed, int sx, int sy);
85 Noise(NoiseParams *np, int seed, int sx, int sy, int sz);
90 float step_x, float step_y,
93 float x, float y, float z,
94 float step_x, float step_y, float step_z,
96 float *perlinMap2D(float x, float y);
97 float *perlinMap3D(float x, float y, float z);
100 // Return value: -1 ... 1
101 float noise2d(int x, int y, int seed);
102 float noise3d(int x, int y, int z, int seed);
104 float noise2d_gradient(float x, float y, int seed);
105 float noise3d_gradient(float x, float y, float z, int seed);
107 float noise2d_perlin(float x, float y, int seed,
108 int octaves, float persistence);
110 float noise2d_perlin_abs(float x, float y, int seed,
111 int octaves, float persistence);
113 float noise3d_perlin(float x, float y, float z, int seed,
114 int octaves, float persistence);
116 float noise3d_perlin_abs(float x, float y, float z, int seed,
117 int octaves, float persistence);
119 inline float easeCurve(float t) {
120 return t * t * t * (t * (6.f * t - 15.f) + 10.f);
123 #define NoisePerlin2D(np, x, y, s) ((np)->offset + (np)->scale * \
124 noise2d_perlin((float)(x) * (np)->spread.X, (float)(y) * (np)->spread.Y, \
125 (s) + (np)->seed, (np)->octaves, (np)->persist))