GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
Simplex Class Reference

Public Member Functions

 __construct (Random $random, $octaves, $persistence, $expansion=1)
 
 getNoise3D ($x, $y, $z)
 
 getNoise2D ($x, $y)
 
- Public Member Functions inherited from Perlin
 __construct (Random $random, $octaves, $persistence, $expansion=1)
 
 getNoise3D ($x, $y, $z)
 
 getNoise2D ($x, $y)
 
- Public Member Functions inherited from Noise
 getNoise2D ($x, $z)
 
 getNoise3D ($x, $y, $z)
 
 noise2D ($x, $z, $normalized=false)
 
 noise3D ($x, $y, $z, $normalized=false)
 
 setOffset ($x, $y, $z)
 

Static Protected Member Functions

static dot2D ($g, $x, $y)
 
static dot3D ($g, $x, $y, $z)
 
static dot4D ($g, $x, $y, $z, $w)
 

Protected Attributes

 $offsetW
 
- Protected Attributes inherited from Noise
 $perm = []
 
 $offsetX = 0
 
 $offsetY = 0
 
 $offsetZ = 0
 
 $octaves = 8
 
 $persistence
 
 $expansion
 

Static Protected Attributes

static $SQRT_3
 
static $SQRT_5
 
static $F2
 
static $G2
 
static $G22
 
static $F3
 
static $G3
 
static $F4
 
static $G4
 
static $G42
 
static $G43
 
static $G44
 
static $grad4
 
static $simplex
 

Additional Inherited Members

- Static Public Member Functions inherited from Noise
static floor ($x)
 
static fade ($x)
 
static lerp ($x, $y, $z)
 
static linearLerp ($x, $x1, $x2, $q0, $q1)
 
static bilinearLerp ($x, $y, $q00, $q01, $q10, $q11, $x1, $x2, $y1, $y2)
 
static trilinearLerp ($x, $y, $z, $q000, $q001, $q010, $q011, $q100, $q101, $q110, $q111, $x1, $x2, $y1, $y2, $z1, $z2)
 
static grad ($hash, $x, $y, $z)
 
- Static Public Attributes inherited from Perlin
static $grad3
 

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

Constructor & Destructor Documentation

◆ __construct()

__construct ( Random  $random,
  $octaves,
  $persistence,
  $expansion = 1 
)

Simplex constructor.

Parameters
Random$random
$octaves
$persistence
int$expansion
74  {
75  parent::__construct($random, $octaves, $persistence, $expansion);
76  $this->offsetW = $random->nextFloat() * 256;
77  self::$SQRT_3 = sqrt(3);
78  self::$SQRT_5 = sqrt(5);
79  self::$F2 = 0.5 * (self::$SQRT_3 - 1);
80  self::$G2 = (3 - self::$SQRT_3) / 6;
81  self::$G22 = self::$G2 * 2.0 - 1;
82  self::$F3 = 1.0 / 3.0;
83  self::$G3 = 1.0 / 6.0;
84  self::$F4 = (self::$SQRT_5 - 1.0) / 4.0;
85  self::$G4 = (5.0 - self::$SQRT_5) / 20.0;
86  self::$G42 = self::$G4 * 2.0;
87  self::$G43 = self::$G4 * 3.0;
88  self::$G44 = self::$G4 * 4.0 - 1.0;
89  }

Member Function Documentation

◆ dot2D()

static dot2D (   $g,
  $x,
  $y 
)
staticprotected
Parameters
$g
$x
$y
Returns
mixed
98  {
99  return $g[0] * $x + $g[1] * $y;
100  }

◆ dot3D()

static dot3D (   $g,
  $x,
  $y,
  $z 
)
staticprotected
Parameters
$g
$x
$y
$z
Returns
mixed
110  {
111  return $g[0] * $x + $g[1] * $y + $g[2] * $z;
112  }

◆ dot4D()

static dot4D (   $g,
  $x,
  $y,
  $z,
  $w 
)
staticprotected
Parameters
$g
$x
$y
$z
$w
Returns
mixed
123  {
124  return $g[0] * $x + $g[1] * $y + $g[2] * $z + $g[3] * $w;
125  }

◆ getNoise2D()

getNoise2D (   $x,
  $y 
)
Parameters
$x
$y
Returns
float
264  {
265  $x += $this->offsetX;
266  $y += $this->offsetY;
267 
268  // Skew the input space to determine which simplex cell we're in
269  $s = ($x + $y) * self::$F2; // Hairy factor for 2D
270  $i = (int) ($x + $s);
271  $j = (int) ($y + $s);
272  $t = ($i + $j) * self::$G2;
273  // Unskew the cell origin back to (x,y) space
274  $x0 = $x - ($i - $t); // The x,y distances from the cell origin
275  $y0 = $y - ($j - $t);
276 
277  // For the 2D case, the simplex shape is an equilateral triangle.
278 
279  // Determine which simplex we are in.
280  if($x0 > $y0){
281  $i1 = 1;
282  $j1 = 0;
283  } // lower triangle, XY order: (0,0)->(1,0)->(1,1)
284  else{
285  $i1 = 0;
286  $j1 = 1;
287  }
288  // upper triangle, YX order: (0,0)->(0,1)->(1,1)
289 
290  // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
291  // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
292  // c = (3-sqrt(3))/6
293 
294  $x1 = $x0 - $i1 + self::$G2; // Offsets for middle corner in (x,y) unskewed coords
295  $y1 = $y0 - $j1 + self::$G2;
296  $x2 = $x0 + self::$G22; // Offsets for last corner in (x,y) unskewed coords
297  $y2 = $y0 + self::$G22;
298 
299  // Work out the hashed gradient indices of the three simplex corners
300  $ii = $i & 255;
301  $jj = $j & 255;
302 
303  $n = 0;
304 
305  // Calculate the contribution from the three corners
306  $t0 = 0.5 - $x0 * $x0 - $y0 * $y0;
307  if($t0 > 0){
308  $gi0 = self::$grad3[$this->perm[$ii + $this->perm[$jj]] % 12];
309  $n += $t0 * $t0 * $t0 * $t0 * ($gi0[0] * $x0 + $gi0[1] * $y0); // (x,y) of grad3 used for 2D gradient
310  }
311 
312  $t1 = 0.5 - $x1 * $x1 - $y1 * $y1;
313  if($t1 > 0){
314  $gi1 = self::$grad3[$this->perm[$ii + $i1 + $this->perm[$jj + $j1]] % 12];
315  $n += $t1 * $t1 * $t1 * $t1 * ($gi1[0] * $x1 + $gi1[1] * $y1);
316  }
317 
318  $t2 = 0.5 - $x2 * $x2 - $y2 * $y2;
319  if($t2 > 0){
320  $gi2 = self::$grad3[$this->perm[$ii + 1 + $this->perm[$jj + 1]] % 12];
321  $n += $t2 * $t2 * $t2 * $t2 * ($gi2[0] * $x2 + $gi2[1] * $y2);
322  }
323 
324  // Add contributions from each corner to get the noise value.
325  // The result is scaled to return values in the interval [-1,1].
326  return 70.0 * $n;
327  }

◆ getNoise3D()

getNoise3D (   $x,
  $y,
  $z 
)
Parameters
$x
$y
$z
Returns
float
134  {
135  $x += $this->offsetX;
136  $y += $this->offsetY;
137  $z += $this->offsetZ;
138 
139  // Skew the input space to determine which simplex cell we're in
140  $s = ($x + $y + $z) * self::$F3; // Very nice and simple skew factor for 3D
141  $i = (int) ($x + $s);
142  $j = (int) ($y + $s);
143  $k = (int) ($z + $s);
144  $t = ($i + $j + $k) * self::$G3;
145  // Unskew the cell origin back to (x,y,z) space
146  $x0 = $x - ($i - $t); // The x,y,z distances from the cell origin
147  $y0 = $y - ($j - $t);
148  $z0 = $z - ($k - $t);
149 
150  // For the 3D case, the simplex shape is a slightly irregular tetrahedron.
151 
152  // Determine which simplex we are in.
153  if($x0 >= $y0){
154  if($y0 >= $z0){
155  $i1 = 1;
156  $j1 = 0;
157  $k1 = 0;
158  $i2 = 1;
159  $j2 = 1;
160  $k2 = 0;
161  } // X Y Z order
162  elseif($x0 >= $z0){
163  $i1 = 1;
164  $j1 = 0;
165  $k1 = 0;
166  $i2 = 1;
167  $j2 = 0;
168  $k2 = 1;
169  } // X Z Y order
170  else{
171  $i1 = 0;
172  $j1 = 0;
173  $k1 = 1;
174  $i2 = 1;
175  $j2 = 0;
176  $k2 = 1;
177  }
178  // Z X Y order
179  }else{ // x0<y0
180  if($y0 < $z0){
181  $i1 = 0;
182  $j1 = 0;
183  $k1 = 1;
184  $i2 = 0;
185  $j2 = 1;
186  $k2 = 1;
187  } // Z Y X order
188  elseif($x0 < $z0){
189  $i1 = 0;
190  $j1 = 1;
191  $k1 = 0;
192  $i2 = 0;
193  $j2 = 1;
194  $k2 = 1;
195  } // Y Z X order
196  else{
197  $i1 = 0;
198  $j1 = 1;
199  $k1 = 0;
200  $i2 = 1;
201  $j2 = 1;
202  $k2 = 0;
203  }
204  // Y X Z order
205  }
206 
207  // A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),
208  // a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
209  // a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
210  // c = 1/6.
211  $x1 = $x0 - $i1 + self::$G3; // Offsets for second corner in (x,y,z) coords
212  $y1 = $y0 - $j1 + self::$G3;
213  $z1 = $z0 - $k1 + self::$G3;
214  $x2 = $x0 - $i2 + 2.0 * self::$G3; // Offsets for third corner in (x,y,z) coords
215  $y2 = $y0 - $j2 + 2.0 * self::$G3;
216  $z2 = $z0 - $k2 + 2.0 * self::$G3;
217  $x3 = $x0 - 1.0 + 3.0 * self::$G3; // Offsets for last corner in (x,y,z) coords
218  $y3 = $y0 - 1.0 + 3.0 * self::$G3;
219  $z3 = $z0 - 1.0 + 3.0 * self::$G3;
220 
221  // Work out the hashed gradient indices of the four simplex corners
222  $ii = $i & 255;
223  $jj = $j & 255;
224  $kk = $k & 255;
225 
226  $n = 0;
227 
228  // Calculate the contribution from the four corners
229  $t0 = 0.6 - $x0 * $x0 - $y0 * $y0 - $z0 * $z0;
230  if($t0 > 0){
231  $gi0 = self::$grad3[$this->perm[$ii + $this->perm[$jj + $this->perm[$kk]]] % 12];
232  $n += $t0 * $t0 * $t0 * $t0 * ($gi0[0] * $x0 + $gi0[1] * $y0 + $gi0[2] * $z0);
233  }
234 
235  $t1 = 0.6 - $x1 * $x1 - $y1 * $y1 - $z1 * $z1;
236  if($t1 > 0){
237  $gi1 = self::$grad3[$this->perm[$ii + $i1 + $this->perm[$jj + $j1 + $this->perm[$kk + $k1]]] % 12];
238  $n += $t1 * $t1 * $t1 * $t1 * ($gi1[0] * $x1 + $gi1[1] * $y1 + $gi1[2] * $z1);
239  }
240 
241  $t2 = 0.6 - $x2 * $x2 - $y2 * $y2 - $z2 * $z2;
242  if($t2 > 0){
243  $gi2 = self::$grad3[$this->perm[$ii + $i2 + $this->perm[$jj + $j2 + $this->perm[$kk + $k2]]] % 12];
244  $n += $t2 * $t2 * $t2 * $t2 * ($gi2[0] * $x2 + $gi2[1] * $y2 + $gi2[2] * $z2);
245  }
246 
247  $t3 = 0.6 - $x3 * $x3 - $y3 * $y3 - $z3 * $z3;
248  if($t3 > 0){
249  $gi3 = self::$grad3[$this->perm[$ii + 1 + $this->perm[$jj + 1 + $this->perm[$kk + 1]]] % 12];
250  $n += $t3 * $t3 * $t3 * $t3 * ($gi3[0] * $x3 + $gi3[1] * $y3 + $gi3[2] * $z3);
251  }
252 
253  // Add contributions from each corner to get the noise value.
254  // The result is scaled to stay just inside [-1,1]
255  return 32.0 * $n;
256  }

Field Documentation

◆ $F2

$F2
staticprotected

◆ $F3

$F3
staticprotected

◆ $F4

$F4
staticprotected

◆ $G2

$G2
staticprotected

◆ $G22

$G22
staticprotected

◆ $G3

$G3
staticprotected

◆ $G4

$G4
staticprotected

◆ $G42

$G42
staticprotected

◆ $G43

$G43
staticprotected

◆ $G44

$G44
staticprotected

◆ $grad4

$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]]

◆ $offsetW

$offsetW
protected

◆ $simplex

$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]]

◆ $SQRT_3

$SQRT_3
staticprotected

◆ $SQRT_5

$SQRT_5
staticprotected

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