void PerlinNoiseCache::Cache(int cx, int cy) { ASSERT(cx >= 1 && cy >= 1); Clear(); sz = Size(cx, cy); InitNoise(); int xycnt = cx *cy; cache.Alloc(xycnt); float *q = ~cache; for (int y = 0; y < sz.cy; y++) for (int x = 0; x < sz.cx; x++, q++) *q = PerlinNoise2D(x, y); DeinitNoise(); }
void perlin(int low, int high, int type) { int x, y, z, i; int level = (high + low)/2; int scale = level - low; for(x = 0; x <= WORLDX; x++) { for(z = 0; z < WORLDZ; z++) { /* Give it small x/z values to increase smoothness; 2 octaves is enough */ y = level + (scale * PerlinNoise2D(x/47.0, z/47.0, 2, 2, 2)); /* Have to keep the result safely inside the boundaries of the earth. */ y = bounds(y, 0, WORLDY-1); for(i = y; world[x][i][z] == EMPTY; i--) { world[x][i][z] = type; } } } }
int getSandHeight(int x, int y){ float NoiseHeight = PerlinNoise2D(x / NoiseScaleX * 3 + 1222, y / NoiseScaleZ * 3 + 1222) / 4.0f - 2; return int(NoiseHeight); }
int getHeight(int x, int y){ float NoiseHeight = PerlinNoise2D(x / NoiseScaleX, y / NoiseScaleZ) / 4.0f; return int(NoiseHeight); }
real PerlinGenerator::mountainHeight( real u, real v ) { //return PerlinNoise2D( u, v, persistence, lacunarity, octaves ) ; return PerlinNoise2D( u, v, 2, 2, 4 ) ; }
//====================================================================================== //====================================================================================== double PNoise::PNoise2D(double x, double y) { return PerlinNoise2D(x, y, _n, _alpha, _beta); }