Generator works!

This commit is contained in:
Shoghi Cervantes
2015-03-15 16:40:18 +01:00
parent 5bfc747622
commit d5601b0c9f
19 changed files with 317 additions and 182 deletions

View File

@ -64,9 +64,9 @@ class Perlin extends Noise{
$y += $this->offsetY;
$z += $this->offsetZ;
$floorX = (int) floor($x);
$floorY = (int) floor($y);
$floorZ = (int) floor($z);
$floorX = (int) $x;
$floorY = (int) $y;
$floorZ = (int) $z;
$X = $floorX & 0xFF;
$Y = $floorY & 0xFF;
@ -77,26 +77,70 @@ class Perlin extends Noise{
$z -= $floorZ;
//Fade curves
$fX = self::fade($x);
$fY = self::fade($y);
$fZ = self::fade($z);
//$fX = self::fade($x);
//$fY = self::fade($y);
//$fZ = self::fade($z);
$fX = $x ** 3 * ($x * ($x * 6 - 15) + 10);
$fY = $y ** 3 * ($y * ($y * 6 - 15) + 10);
$fZ = $z ** 3 * ($z * ($z * 6 - 15) + 10);
//Cube corners
$A = $this->perm[$X] + $Y;
$B = $this->perm[$X + 1] + $Y;
$AA = $this->perm[$A] + $Z;
$AB = $this->perm[$A + 1] + $Z;
$B = $this->perm[$X + 1] + $Y;
$BA = $this->perm[$B] + $Z;
$BB = $this->perm[$B + 1] + $Z;
return self::lerp($fZ, self::lerp($fY, self::lerp($fX, self::grad($this->perm[$AA], $x, $y, $z),
self::grad($this->perm[$BA], $x - 1, $y, $z)),
self::lerp($fX, self::grad($this->perm[$AB], $x, $y - 1, $z),
self::grad($this->perm[$BB], $x - 1, $y - 1, $z))),
self::lerp($fY, self::lerp($fX, self::grad($this->perm[$AA + 1], $x, $y, $z - 1),
self::grad($this->perm[$BA + 1], $x - 1, $y, $z - 1)),
self::lerp($fX, self::grad($this->perm[$AB + 1], $x, $y - 1, $z - 1),
self::grad($this->perm[$BB + 1], $x - 1, $y - 1, $z - 1))));
$AA1 = self::grad($this->perm[$AA], $x, $y, $z);
$BA1 = self::grad($this->perm[$BA], $x - 1, $y, $z);
$AB1 = self::grad($this->perm[$AB], $x, $y - 1, $z);
$BB1 = self::grad($this->perm[$BB], $x - 1, $y - 1, $z);
$AA2 = self::grad($this->perm[$AA + 1], $x, $y, $z - 1);
$BA2 = self::grad($this->perm[$BA + 1], $x - 1, $y, $z - 1);
$AB2 = self::grad($this->perm[$AB + 1], $x, $y - 1, $z - 1);
$BB2 = self::grad($this->perm[$BB + 1], $x - 1, $y - 1, $z - 1);
$xLerp11 = $AA1 + $fX * ($BA1 - $AA1);
$zLerp1 = $xLerp11 + $fY * ($AB1 + $fX * ($BB1 - $AB1) - $xLerp11);
$xLerp21 = $AA2 + $fX * ($BA2 - $AA2);
return $zLerp1 + $fZ * ($xLerp21 + $fY * ($AB2 + $fX * ($BB2 - $AB2) - $xLerp21) - $zLerp1);
/*
return self::lerp(
$fZ,
self::lerp(
$fY,
self::lerp(
$fX,
self::grad($this->perm[$AA], $x, $y, $z),
self::grad($this->perm[$BA], $x - 1, $y, $z)
),
self::lerp(
$fX,
self::grad($this->perm[$AB], $x, $y - 1, $z),
self::grad($this->perm[$BB], $x - 1, $y - 1, $z)
)
),
self::lerp(
$fY,
self::lerp(
$fX,
self::grad($this->perm[$AA + 1], $x, $y, $z - 1),
self::grad($this->perm[$BA + 1], $x - 1, $y, $z - 1)
),
self::lerp(
$fX,
self::grad($this->perm[$AB + 1], $x, $y - 1, $z - 1),
self::grad($this->perm[$BB + 1], $x - 1, $y - 1, $z - 1)
)
)
);
*/
}
public function getNoise2D($x, $y){