Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function createSphere($px, $py, $pz, $level, $radius, $id){
- $radiusX = $radius + 0.5;
- $radiusY = $radius + 0.5;
- $radiusZ = $radius + 0.5;
- $invRadiusX = 1 / $radiusX;
- $invRadiusY = 1 / $radiusY;
- $invRadiusZ = 1 / $radiusZ;
- $ceilRadiusX = (int) ceil($radiusX);
- $ceilRadiusY = (int) ceil($radiusY);
- $ceilRadiusZ = (int) ceil($radiusZ);
- $nextXn = 0;
- for ($x = 0; $x <= $ceilRadiusX; ++$x) {
- $xn = $nextXn;
- $nextXn = ($x + 1) * $invRadiusX;
- $nextYn = 0;
- for ($y = 0; $y <= $ceilRadiusY; ++$y) {
- $yn = $nextYn;
- $nextYn = ($y + 1) * $invRadiusY;
- $nextZn = 0;
- for ($z = 0; $z <= $ceilRadiusZ; ++$z) {
- $zn = $nextZn;
- $nextZn = ($z + 1) * $invRadiusZ;
- $distanceSq = $this->lengthSq($xn, $yn, $zn);
- if ($distanceSq > 1) {
- if ($z == 0) {
- if ($y == 0) {
- $x++;
- continue;
- }
- $y++;
- continue;
- }
- $z++;
- continue;
- }
- if ($this->lengthSq($nextXn, $yn, $zn) <= 1 && $this->lengthSq($xn, $nextYn, $zn) <= 1 && $this->lengthSq($xn, $yn, $nextZn) <= 1) {
- continue;
- }
- $level->setBlockIdAt($x + $px, $y + $py, $z + $pz, $id);
- $level->setBlockIdAt(-$x + $px, $y + $py, $z + $pz, $id);
- $level->setBlockIdAt($x + $px, -$y + $py, $z + $pz, $id);
- $level->setBlockIdAt($x + $px, $y + $py, -$z + $pz, $id);
- $level->setBlockIdAt(-$x + $px, -$y + $py, $z + $pz, $id);
- $level->setBlockIdAt($x + $px, -$y + $py, -$z + $pz, $id);
- $level->setBlockIdAt(-$x + $px, $y + $py, -$z + $pz, $id);
- $level->setBlockIdAt(-$x + $px, -$y + $py, -$z + $pz, $id);
- }
- }
- }
- }
- public function lengthSq($x, $y, $z) {
- return (($x * $x) + ($y * $y) + ($z * $z));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement