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

Public Member Functions

 __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 Public Attributes

static $grad3
 

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)
 
- Protected Attributes inherited from Noise
 $perm = []
 
 $offsetX = 0
 
 $offsetY = 0
 
 $offsetZ = 0
 
 $octaves = 8
 
 $persistence
 
 $expansion
 

Constructor & Destructor Documentation

◆ __construct()

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

Perlin constructor.

Parameters
Random$random
$octaves
$persistence
int$expansion
42  {
43  $this->octaves = $octaves;
44  $this->persistence = $persistence;
45  $this->expansion = $expansion;
46  $this->offsetX = $random->nextFloat() * 256;
47  $this->offsetY = $random->nextFloat() * 256;
48  $this->offsetZ = $random->nextFloat() * 256;
49 
50  for($i = 0; $i < 512; ++$i){
51  $this->perm[$i] = 0;
52  }
53 
54  for($i = 0; $i < 256; ++$i){
55  $this->perm[$i] = $random->nextBoundedInt(256);
56  }
57 
58  for($i = 0; $i < 256; ++$i){
59  $pos = $random->nextBoundedInt(256 - $i) + $i;
60  $old = $this->perm[$i];
61 
62  $this->perm[$i] = $this->perm[$pos];
63  $this->perm[$pos] = $old;
64  $this->perm[$i + 256] = $this->perm[$i];
65  }
66 
67  }

Member Function Documentation

◆ getNoise2D()

getNoise2D (   $x,
  $y 
)
Parameters
$x
$y
Returns
mixed
166  {
167  return $this->getNoise3D($x, $y, 0);
168  }

◆ getNoise3D()

getNoise3D (   $x,
  $y,
  $z 
)
Parameters
$x
$y
$z
Returns
mixed
76  {
77  $x += $this->offsetX;
78  $y += $this->offsetY;
79  $z += $this->offsetZ;
80 
81  $floorX = (int) $x;
82  $floorY = (int) $y;
83  $floorZ = (int) $z;
84 
85  $X = $floorX & 0xFF;
86  $Y = $floorY & 0xFF;
87  $Z = $floorZ & 0xFF;
88 
89  $x -= $floorX;
90  $y -= $floorY;
91  $z -= $floorZ;
92 
93  //Fade curves
94  //$fX = self::fade($x);
95  //$fY = self::fade($y);
96  //$fZ = self::fade($z);
97  $fX = $x * $x * $x * ($x * ($x * 6 - 15) + 10);
98  $fY = $y * $y * $y * ($y * ($y * 6 - 15) + 10);
99  $fZ = $z * $z * $z * ($z * ($z * 6 - 15) + 10);
100 
101  //Cube corners
102  $A = $this->perm[$X] + $Y;
103  $B = $this->perm[$X + 1] + $Y;
104 
105  $AA = $this->perm[$A] + $Z;
106  $AB = $this->perm[$A + 1] + $Z;
107  $BA = $this->perm[$B] + $Z;
108  $BB = $this->perm[$B + 1] + $Z;
109 
110  $AA1 = self::grad($this->perm[$AA], $x, $y, $z);
111  $BA1 = self::grad($this->perm[$BA], $x - 1, $y, $z);
112  $AB1 = self::grad($this->perm[$AB], $x, $y - 1, $z);
113  $BB1 = self::grad($this->perm[$BB], $x - 1, $y - 1, $z);
114  $AA2 = self::grad($this->perm[$AA + 1], $x, $y, $z - 1);
115  $BA2 = self::grad($this->perm[$BA + 1], $x - 1, $y, $z - 1);
116  $AB2 = self::grad($this->perm[$AB + 1], $x, $y - 1, $z - 1);
117  $BB2 = self::grad($this->perm[$BB + 1], $x - 1, $y - 1, $z - 1);
118 
119  $xLerp11 = $AA1 + $fX * ($BA1 - $AA1);
120 
121  $zLerp1 = $xLerp11 + $fY * ($AB1 + $fX * ($BB1 - $AB1) - $xLerp11);
122 
123  $xLerp21 = $AA2 + $fX * ($BA2 - $AA2);
124 
125  return $zLerp1 + $fZ * ($xLerp21 + $fY * ($AB2 + $fX * ($BB2 - $AB2) - $xLerp21) - $zLerp1);
126 
127  /*
128  return self::lerp(
129  $fZ,
130  self::lerp(
131  $fY,
132  self::lerp(
133  $fX,
134  self::grad($this->perm[$AA], $x, $y, $z),
135  self::grad($this->perm[$BA], $x - 1, $y, $z)
136  ),
137  self::lerp(
138  $fX,
139  self::grad($this->perm[$AB], $x, $y - 1, $z),
140  self::grad($this->perm[$BB], $x - 1, $y - 1, $z)
141  )
142  ),
143  self::lerp(
144  $fY,
145  self::lerp(
146  $fX,
147  self::grad($this->perm[$AA + 1], $x, $y, $z - 1),
148  self::grad($this->perm[$BA + 1], $x - 1, $y, $z - 1)
149  ),
150  self::lerp(
151  $fX,
152  self::grad($this->perm[$AB + 1], $x, $y - 1, $z - 1),
153  self::grad($this->perm[$BB + 1], $x - 1, $y - 1, $z - 1)
154  )
155  )
156  );
157  */
158  }

Field Documentation

◆ $grad3

$grad3
static
Initial value:
= [
[1, 1, 0], [-1, 1, 0], [1, -1, 0], [-1, -1, 0],
[1, 0, 1], [-1, 0, 1], [1, 0, -1], [-1, 0, -1],
[0, 1, 1], [0, -1, 1], [0, 1, -1], [0, -1, -1]
]

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