Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.util.noise.SimplexNoiseGenerator Class Reference
Inheritance diagram for org.bukkit.util.noise.SimplexNoiseGenerator:
org.bukkit.util.noise.PerlinNoiseGenerator org.bukkit.util.noise.NoiseGenerator

Public Member Functions

 SimplexNoiseGenerator (World world)
 
 SimplexNoiseGenerator (long seed)
 
 SimplexNoiseGenerator (Random rand)
 
double noise (double xin, double yin, double zin)
 
double noise (double xin, double yin)
 
double noise (double x, double y, double z, double w)
 
- Public Member Functions inherited from org.bukkit.util.noise.PerlinNoiseGenerator
 PerlinNoiseGenerator (World world)
 
 PerlinNoiseGenerator (long seed)
 
 PerlinNoiseGenerator (Random rand)
 
double noise (double x, double y, double z)
 
- Public Member Functions inherited from org.bukkit.util.noise.NoiseGenerator
double noise (double x)
 
double noise (double x, double y)
 
abstract double noise (double x, double y, double z)
 
double noise (double x, int octaves, double frequency, double amplitude)
 
double noise (double x, int octaves, double frequency, double amplitude, boolean normalized)
 
double noise (double x, double y, int octaves, double frequency, double amplitude)
 
double noise (double x, double y, int octaves, double frequency, double amplitude, boolean normalized)
 
double noise (double x, double y, double z, int octaves, double frequency, double amplitude)
 
double noise (double x, double y, double z, int octaves, double frequency, double amplitude, boolean normalized)
 

Static Public Member Functions

static double getNoise (double xin)
 
static double getNoise (double xin, double yin)
 
static double getNoise (double xin, double yin, double zin)
 
static double getNoise (double x, double y, double z, double w)
 
static SimplexNoiseGenerator getInstance ()
 
- Static Public Member Functions inherited from org.bukkit.util.noise.PerlinNoiseGenerator
static double getNoise (double x)
 
static double getNoise (double x, double y)
 
static double getNoise (double x, double y, double z)
 
static PerlinNoiseGenerator getInstance ()
 
static double getNoise (double x, int octaves, double frequency, double amplitude)
 
static double getNoise (double x, double y, int octaves, double frequency, double amplitude)
 
static double getNoise (double x, double y, double z, int octaves, double frequency, double amplitude)
 
- Static Public Member Functions inherited from org.bukkit.util.noise.NoiseGenerator
static int floor (double x)
 

Static Protected Member Functions

static double dot (int g[], double x, double y)
 
static double dot (int g[], double x, double y, double z)
 
static double dot (int g[], double x, double y, double z, double w)
 
- Static Protected Member Functions inherited from org.bukkit.util.noise.NoiseGenerator
static double fade (double x)
 
static double lerp (double x, double y, double z)
 
static double grad (int hash, double x, double y, double z)
 

Static Protected Attributes

static final double SQRT_3 = Math.sqrt(3)
 
static final double SQRT_5 = Math.sqrt(5)
 
static final double F2 = 0.5 * (SQRT_3 - 1)
 
static final double G2 = (3 - SQRT_3) / 6
 
static final double G22 = G2 * 2.0 - 1
 
static final double F3 = 1.0 / 3.0
 
static final double G3 = 1.0 / 6.0
 
static final double F4 = (SQRT_5 - 1.0) / 4.0
 
static final double G4 = (5.0 - SQRT_5) / 20.0
 
static final double G42 = G4 * 2.0
 
static final double G43 = G4 * 3.0
 
static final double G44 = G4 * 4.0 - 1.0
 
static final int grad4 [][]
 
static final int simplex [][]
 
static double offsetW
 
- Static Protected Attributes inherited from org.bukkit.util.noise.PerlinNoiseGenerator
static final int grad3 [][]
 

Additional Inherited Members

- Protected Attributes inherited from org.bukkit.util.noise.NoiseGenerator
final int perm [] = new int[512]
 
double offsetX
 
double offsetY
 
double offsetZ
 

Detailed Description

Generates simplex-based noise.

This is a modified version of the freely published version in the paper by Stefan Gustavson at http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf

Definition at line 14 of file SimplexNoiseGenerator.java.

Constructor & Destructor Documentation

org.bukkit.util.noise.SimplexNoiseGenerator.SimplexNoiseGenerator ( World  world)

Creates a seeded simplex noise generator for the given world

Parameters
worldWorld to construct this generator for

Definition at line 56 of file SimplexNoiseGenerator.java.

References org.bukkit.World.getSeed().

56  {
57  this(new Random(world.getSeed()));
58  }
org.bukkit.util.noise.SimplexNoiseGenerator.SimplexNoiseGenerator ( long  seed)

Creates a seeded simplex noise generator for the given seed

Parameters
seedSeed to construct this generator for

Definition at line 65 of file SimplexNoiseGenerator.java.

65  {
66  this(new Random(seed));
67  }
org.bukkit.util.noise.SimplexNoiseGenerator.SimplexNoiseGenerator ( Random  rand)

Creates a seeded simplex noise generator with the given Random

Parameters
randRandom to construct with

Definition at line 74 of file SimplexNoiseGenerator.java.

74  {
75  super(rand);
76  offsetW = rand.nextDouble() * 256;
77  }

Member Function Documentation

static SimplexNoiseGenerator org.bukkit.util.noise.SimplexNoiseGenerator.getInstance ( )
static

Gets the singleton unseeded instance of this generator

Returns
Singleton

Definition at line 517 of file SimplexNoiseGenerator.java.

517  {
518  return instance;
519  }
static double org.bukkit.util.noise.SimplexNoiseGenerator.getNoise ( double  xin)
static

Computes and returns the 1D unseeded simplex noise for the given coordinates in 1D space

Parameters
xinX coordinate
Returns
Noise at given location, from range -1 to 1

Definition at line 98 of file SimplexNoiseGenerator.java.

98  {
99  return instance.noise(xin);
100  }
static double org.bukkit.util.noise.SimplexNoiseGenerator.getNoise ( double  xin,
double  yin 
)
static

Computes and returns the 2D unseeded simplex noise for the given coordinates in 2D space

Parameters
xinX coordinate
yinY coordinate
Returns
Noise at given location, from range -1 to 1

Definition at line 110 of file SimplexNoiseGenerator.java.

110  {
111  return instance.noise(xin, yin);
112  }
static double org.bukkit.util.noise.SimplexNoiseGenerator.getNoise ( double  xin,
double  yin,
double  zin 
)
static

Computes and returns the 3D unseeded simplex noise for the given coordinates in 3D space

Parameters
xinX coordinate
yinY coordinate
zinZ coordinate
Returns
Noise at given location, from range -1 to 1

Definition at line 123 of file SimplexNoiseGenerator.java.

123  {
124  return instance.noise(xin, yin, zin);
125  }
static double org.bukkit.util.noise.SimplexNoiseGenerator.getNoise ( double  x,
double  y,
double  z,
double  w 
)
static

Computes and returns the 4D simplex noise for the given coordinates in 4D space

Parameters
xX coordinate
yY coordinate
zZ coordinate
wW coordinate
Returns
Noise at given location, from range -1 to 1

Definition at line 137 of file SimplexNoiseGenerator.java.

137  {
138  return instance.noise(x, y, z, w);
139  }
double org.bukkit.util.noise.SimplexNoiseGenerator.noise ( double  x,
double  y,
double  z,
double  w 
)

Computes and returns the 4D simplex noise for the given coordinates in 4D space

Parameters
xX coordinate
yY coordinate
zZ coordinate
wW coordinate
Returns
Noise at given location, from range -1 to 1

Definition at line 366 of file SimplexNoiseGenerator.java.

References org.bukkit.util.noise.NoiseGenerator.floor().

366  {
367  x += offsetX;
368  y += offsetY;
369  z += offsetZ;
370  w += offsetW;
371 
372  double n0, n1, n2, n3, n4; // Noise contributions from the five corners
373 
374  // Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in
375  double s = (x + y + z + w) * F4; // Factor for 4D skewing
376  int i = floor(x + s);
377  int j = floor(y + s);
378  int k = floor(z + s);
379  int l = floor(w + s);
380 
381  double t = (i + j + k + l) * G4; // Factor for 4D unskewing
382  double X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space
383  double Y0 = j - t;
384  double Z0 = k - t;
385  double W0 = l - t;
386  double x0 = x - X0; // The x,y,z,w distances from the cell origin
387  double y0 = y - Y0;
388  double z0 = z - Z0;
389  double w0 = w - W0;
390 
391  // For the 4D case, the simplex is a 4D shape I won't even try to describe.
392  // To find out which of the 24 possible simplices we're in, we need to
393  // determine the magnitude ordering of x0, y0, z0 and w0.
394  // The method below is a good way of finding the ordering of x,y,z,w and
395  // then find the correct traversal order for the simplex we’re in.
396  // First, six pair-wise comparisons are performed between each possible pair
397  // of the four coordinates, and the results are used to add up binary bits
398  // for an integer index.
399  int c1 = (x0 > y0) ? 32 : 0;
400  int c2 = (x0 > z0) ? 16 : 0;
401  int c3 = (y0 > z0) ? 8 : 0;
402  int c4 = (x0 > w0) ? 4 : 0;
403  int c5 = (y0 > w0) ? 2 : 0;
404  int c6 = (z0 > w0) ? 1 : 0;
405  int c = c1 + c2 + c3 + c4 + c5 + c6;
406  int i1, j1, k1, l1; // The integer offsets for the second simplex corner
407  int i2, j2, k2, l2; // The integer offsets for the third simplex corner
408  int i3, j3, k3, l3; // The integer offsets for the fourth simplex corner
409 
410  // simplex[c] is a 4-vector with the numbers 0, 1, 2 and 3 in some order.
411  // Many values of c will never occur, since e.g. x>y>z>w makes x<z, y<w and x<w
412  // impossible. Only the 24 indices which have non-zero entries make any sense.
413  // We use a thresholding to set the coordinates in turn from the largest magnitude.
414 
415  // The number 3 in the "simplex" array is at the position of the largest coordinate.
416  i1 = simplex[c][0] >= 3 ? 1 : 0;
417  j1 = simplex[c][1] >= 3 ? 1 : 0;
418  k1 = simplex[c][2] >= 3 ? 1 : 0;
419  l1 = simplex[c][3] >= 3 ? 1 : 0;
420 
421  // The number 2 in the "simplex" array is at the second largest coordinate.
422  i2 = simplex[c][0] >= 2 ? 1 : 0;
423  j2 = simplex[c][1] >= 2 ? 1 : 0;
424  k2 = simplex[c][2] >= 2 ? 1 : 0;
425  l2 = simplex[c][3] >= 2 ? 1 : 0;
426 
427  // The number 1 in the "simplex" array is at the second smallest coordinate.
428  i3 = simplex[c][0] >= 1 ? 1 : 0;
429  j3 = simplex[c][1] >= 1 ? 1 : 0;
430  k3 = simplex[c][2] >= 1 ? 1 : 0;
431  l3 = simplex[c][3] >= 1 ? 1 : 0;
432 
433  // The fifth corner has all coordinate offsets = 1, so no need to look that up.
434 
435  double x1 = x0 - i1 + G4; // Offsets for second corner in (x,y,z,w) coords
436  double y1 = y0 - j1 + G4;
437  double z1 = z0 - k1 + G4;
438  double w1 = w0 - l1 + G4;
439 
440  double x2 = x0 - i2 + G42; // Offsets for third corner in (x,y,z,w) coords
441  double y2 = y0 - j2 + G42;
442  double z2 = z0 - k2 + G42;
443  double w2 = w0 - l2 + G42;
444 
445  double x3 = x0 - i3 + G43; // Offsets for fourth corner in (x,y,z,w) coords
446  double y3 = y0 - j3 + G43;
447  double z3 = z0 - k3 + G43;
448  double w3 = w0 - l3 + G43;
449 
450  double x4 = x0 + G44; // Offsets for last corner in (x,y,z,w) coords
451  double y4 = y0 + G44;
452  double z4 = z0 + G44;
453  double w4 = w0 + G44;
454 
455  // Work out the hashed gradient indices of the five simplex corners
456  int ii = i & 255;
457  int jj = j & 255;
458  int kk = k & 255;
459  int ll = l & 255;
460 
461  int gi0 = perm[ii + perm[jj + perm[kk + perm[ll]]]] % 32;
462  int gi1 = perm[ii + i1 + perm[jj + j1 + perm[kk + k1 + perm[ll + l1]]]] % 32;
463  int gi2 = perm[ii + i2 + perm[jj + j2 + perm[kk + k2 + perm[ll + l2]]]] % 32;
464  int gi3 = perm[ii + i3 + perm[jj + j3 + perm[kk + k3 + perm[ll + l3]]]] % 32;
465  int gi4 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32;
466 
467  // Calculate the contribution from the five corners
468  double t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
469  if (t0 < 0) {
470  n0 = 0.0;
471  } else {
472  t0 *= t0;
473  n0 = t0 * t0 * dot(grad4[gi0], x0, y0, z0, w0);
474  }
475 
476  double t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1;
477  if (t1 < 0) {
478  n1 = 0.0;
479  } else {
480  t1 *= t1;
481  n1 = t1 * t1 * dot(grad4[gi1], x1, y1, z1, w1);
482  }
483 
484  double t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2;
485  if (t2 < 0) {
486  n2 = 0.0;
487  } else {
488  t2 *= t2;
489  n2 = t2 * t2 * dot(grad4[gi2], x2, y2, z2, w2);
490  }
491 
492  double t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3;
493  if (t3 < 0) {
494  n3 = 0.0;
495  } else {
496  t3 *= t3;
497  n3 = t3 * t3 * dot(grad4[gi3], x3, y3, z3, w3);
498  }
499 
500  double t4 = 0.6 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4;
501  if (t4 < 0) {
502  n4 = 0.0;
503  } else {
504  t4 *= t4;
505  n4 = t4 * t4 * dot(grad4[gi4], x4, y4, z4, w4);
506  }
507 
508  // Sum up and scale the result to cover the range [-1,1]
509  return 27.0 * (n0 + n1 + n2 + n3 + n4);
510  }

Member Data Documentation

final int org.bukkit.util.noise.SimplexNoiseGenerator.grad4[][]
staticprotected
Initial value:
= {{0, 1, 1, 1}, {0, 1, 1, -1}, {0, 1, -1, 1}, {0, 1, -1, -1},
{0, -1, 1, 1}, {0, -1, 1, -1}, {0, -1, -1, 1}, {0, -1, -1, -1},
{1, 0, 1, 1}, {1, 0, 1, -1}, {1, 0, -1, 1}, {1, 0, -1, -1},
{-1, 0, 1, 1}, {-1, 0, 1, -1}, {-1, 0, -1, 1}, {-1, 0, -1, -1},
{1, 1, 0, 1}, {1, 1, 0, -1}, {1, -1, 0, 1}, {1, -1, 0, -1},
{-1, 1, 0, 1}, {-1, 1, 0, -1}, {-1, -1, 0, 1}, {-1, -1, 0, -1},
{1, 1, 1, 0}, {1, 1, -1, 0}, {1, -1, 1, 0}, {1, -1, -1, 0},
{-1, 1, 1, 0}, {-1, 1, -1, 0}, {-1, -1, 1, 0}, {-1, -1, -1, 0}}

Definition at line 27 of file SimplexNoiseGenerator.java.

final int org.bukkit.util.noise.SimplexNoiseGenerator.simplex[][]
staticprotected
Initial value:
= {
{0, 1, 2, 3}, {0, 1, 3, 2}, {0, 0, 0, 0}, {0, 2, 3, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {1, 2, 3, 0},
{0, 2, 1, 3}, {0, 0, 0, 0}, {0, 3, 1, 2}, {0, 3, 2, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {1, 3, 2, 0},
{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0},
{1, 2, 0, 3}, {0, 0, 0, 0}, {1, 3, 0, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {2, 3, 0, 1}, {2, 3, 1, 0},
{1, 0, 2, 3}, {1, 0, 3, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {2, 0, 3, 1}, {0, 0, 0, 0}, {2, 1, 3, 0},
{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0},
{2, 0, 1, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {3, 0, 1, 2}, {3, 0, 2, 1}, {0, 0, 0, 0}, {3, 1, 2, 0},
{2, 1, 0, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {3, 1, 0, 2}, {0, 0, 0, 0}, {3, 2, 0, 1}, {3, 2, 1, 0}}

Definition at line 35 of file SimplexNoiseGenerator.java.


The documentation for this class was generated from the following file: