mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
Improved exponentiation
This commit is contained in:
@ -42,7 +42,7 @@ abstract class Generator{
|
||||
}
|
||||
|
||||
public static function fade($x){
|
||||
return $x * $x * $x * ($x * ($x * 6 - 15) + 10);
|
||||
return $x ** 3 * ($x * ($x * 6 - 15) + 10);
|
||||
}
|
||||
|
||||
public static function lerp($x, $y, $z){
|
||||
|
@ -191,36 +191,36 @@ class Simplex extends Perlin{
|
||||
$gi3 = $this->perm[$ii + 1 + $this->perm[$jj + 1 + $this->perm[$kk + 1]]] % 12;
|
||||
|
||||
// Calculate the contribution from the four corners
|
||||
$t0 = 0.6 - $x0 * $x0 - $y0 * $y0 - $z0 * $z0;
|
||||
$t0 = 0.6 - $x0 ** 2 - $y0 ** 2 - $z0 ** 2;
|
||||
if($t0 < 0){
|
||||
$n0 = 0.0;
|
||||
}else{
|
||||
$t0 *= $t0;
|
||||
$n0 = $t0 * $t0 * self::dot3D(self::$grad3[$gi0], $x0, $y0, $z0);
|
||||
$t0 **= 2;
|
||||
$n0 = $t0 ** 2 * self::dot3D(self::$grad3[$gi0], $x0, $y0, $z0);
|
||||
}
|
||||
|
||||
$t1 = 0.6 - $x1 * $x1 - $y1 * $y1 - $z1 * $z1;
|
||||
$t1 = 0.6 - $x1 ** 2 - $y1 ** 2 - $z1 ** 2;
|
||||
if($t1 < 0){
|
||||
$n1 = 0.0;
|
||||
}else{
|
||||
$t1 *= $t1;
|
||||
$n1 = $t1 * $t1 * self::dot3D(self::$grad3[$gi1], $x1, $y1, $z1);
|
||||
$t1 **= 2;
|
||||
$n1 = $t1 ** 2 * self::dot3D(self::$grad3[$gi1], $x1, $y1, $z1);
|
||||
}
|
||||
|
||||
$t2 = 0.6 - $x2 * $x2 - $y2 * $y2 - $z2 * $z2;
|
||||
$t2 = 0.6 - $x2 ** 2 - $y2 ** 2 - $z2 ** 2;
|
||||
if($t2 < 0){
|
||||
$n2 = 0.0;
|
||||
}else{
|
||||
$t2 *= $t2;
|
||||
$n2 = $t2 * $t2 * self::dot3D(self::$grad3[$gi2], $x2, $y2, $z2);
|
||||
$t2 **= 2;
|
||||
$n2 = $t2 ** 2 * self::dot3D(self::$grad3[$gi2], $x2, $y2, $z2);
|
||||
}
|
||||
|
||||
$t3 = 0.6 - $x3 * $x3 - $y3 * $y3 - $z3 * $z3;
|
||||
$t3 = 0.6 - $x3 ** 2 - $y3 ** 2 - $z3 ** 2;
|
||||
if($t3 < 0){
|
||||
$n3 = 0.0;
|
||||
}else{
|
||||
$t3 *= $t3;
|
||||
$n3 = $t3 * $t3 * self::dot3D(self::$grad3[$gi3], $x3, $y3, $z3);
|
||||
$t3 **= 2;
|
||||
$n3 = $t3 ** 2 * self::dot3D(self::$grad3[$gi3], $x3, $y3, $z3);
|
||||
}
|
||||
|
||||
// Add contributions from each corner to get the noise value.
|
||||
@ -272,28 +272,28 @@ class Simplex extends Perlin{
|
||||
$gi2 = $this->perm[$ii + 1 + $this->perm[$jj + 1]] % 12;
|
||||
|
||||
// Calculate the contribution from the three corners
|
||||
$t0 = 0.5 - $x0 * $x0 - $y0 * $y0;
|
||||
$t0 = 0.5 - $x0 ** 2 - $y0 ** 2;
|
||||
if($t0 < 0){
|
||||
$n0 = 0.0;
|
||||
}else{
|
||||
$t0 *= $t0;
|
||||
$n0 = $t0 * $t0 * self::dot2D(self::$grad3[$gi0], $x0, $y0); // (x,y) of grad3 used for 2D gradient
|
||||
$t0 **= 2;
|
||||
$n0 = $t0 ** 2 * self::dot2D(self::$grad3[$gi0], $x0, $y0); // (x,y) of grad3 used for 2D gradient
|
||||
}
|
||||
|
||||
$t1 = 0.5 - $x1 * $x1 - $y1 * $y1;
|
||||
$t1 = 0.5 - $x1 ** 2 - $y1 ** 2;
|
||||
if($t1 < 0){
|
||||
$n1 = 0.0;
|
||||
}else{
|
||||
$t1 *= $t1;
|
||||
$n1 = $t1 * $t1 * self::dot2D(self::$grad3[$gi1], $x1, $y1);
|
||||
$t1 **= 2;
|
||||
$n1 = $t1 ** 2 * self::dot2D(self::$grad3[$gi1], $x1, $y1);
|
||||
}
|
||||
|
||||
$t2 = 0.5 - $x2 * $x2 - $y2 * $y2;
|
||||
$t2 = 0.5 - $x2 ** 2 - $y2 ** 2;
|
||||
if($t2 < 0){
|
||||
$n2 = 0.0;
|
||||
}else{
|
||||
$t2 *= $t2;
|
||||
$n2 = $t2 * $t2 * self::dot2D(self::$grad3[$gi2], $x2, $y2);
|
||||
$t2 **= 2;
|
||||
$n2 = $t2 ** 2 * self::dot2D(self::$grad3[$gi2], $x2, $y2);
|
||||
}
|
||||
|
||||
// Add contributions from each corner to get the noise value.
|
||||
|
Reference in New Issue
Block a user