Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- public function generateHollowSphere($x, $y, $z, $levelName, $radius, $blockId){
- $block = new Block($blockId);
- $level = Server::getInstance()->getLevel($levelName);
- $shape = $this->generateCircle($radius); // generate the main circle
- $this->drawCircle($x, $y, $z, $radius, $block, $level); // Draw the middle circle of the sphere
- for($i=1;$i=<$radius;$i++){
- $hight = $shape[$i];
- $this->draw2CirclesOfSphere($x, $y, $z+$i, $z-$i, $hight, $block, $level);
- }
- }
- // This is a fast method to draw 2 identical circles
- public function draw2CirclesOfSphere($x0, $y0, $z1, $z2, $radius, $block, $level){
- $x = $radius;
- $y = 0;
- $radiusError = 1-$x;
- while($x >= $y){
- $level->setBlock(new Vector3($x + $x0, $y + $y0, $z1), $block, false, false, true);
- $level->setBlock(new Vector3($y + $x0, $x + $y0, $z1), $block, false, false, true);
- $level->setBlock(new Vector3(-$x + $x0, $y + $y0, $z1), $block, false, false, true);
- $level->setBlock(new Vector3(-$y + $x0, $x + $y0, $z1), $block, false, false, true);
- $level->setBlock(new Vector3(-$x + $x0, -$y + $y0, $z1), $block, false, false, true);
- $level->setBlock(new Vector3(-$y + $x0, -$x + $y0, $z1), $block, false, false, true);
- $level->setBlock(new Vector3($x + $x0, -$y + $y0, $z1), $block, false, false, true);
- $level->setBlock(new Vector3($y + $x0, -$x + $y0, $z1), $block, false, false, true);
- $level->setBlock(new Vector3($x + $x0, $y + $y0, $z2), $block, false, false, true);
- $level->setBlock(new Vector3($y + $x0, $x + $y0, $z2), $block, false, false, true);
- $level->setBlock(new Vector3(-$x + $x0, $y + $y0, $z2), $block, false, false, true);
- $level->setBlock(new Vector3(-$y + $x0, $x + $y0, $z2), $block, false, false, true);
- $level->setBlock(new Vector3(-$x + $x0, -$y + $y0, $z2), $block, false, false, true);
- $level->setBlock(new Vector3(-$y + $x0, -$x + $y0, $z2), $block, false, false, true);
- $level->setBlock(new Vector3($x + $x0, -$y + $y0, $z2), $block, false, false, true);
- $level->setBlock(new Vector3($y + $x0, -$x + $y0, $z2), $block, false, false, true);
- $y++;
- if($radiusError<0){
- $radiusError += 2 * $y + 1;
- }else{
- $x--;
- $radiusError+= 2 * ($y - $x + 1);
- }
- }
- }
- // This is a fast method to draw 1 circle
- public function drawCircle($x0, $y0, $z, $radius, $block, $level){
- $x = $radius;
- $y = 0;
- $radiusError = 1-$x;
- while($x >= $y){
- $level->setBlock(new Vector3($x + $x0, $y + $y0, $z), $block, false, false, true);
- $level->setBlock(new Vector3($y + $x0, $x + $y0, $z), $block, false, false, true);
- $level->setBlock(new Vector3(-$x + $x0, $y + $y0, $z), $block, false, false, true);
- $level->setBlock(new Vector3(-$y + $x0, $x + $y0, $z), $block, false, false, true);
- $level->setBlock(new Vector3(-$x + $x0, -$y + $y0, $z), $block, false, false, true);
- $level->setBlock(new Vector3(-$y + $x0, -$x + $y0, $z), $block, false, false, true);
- $level->setBlock(new Vector3($x + $x0, -$y + $y0, $z), $block, false, false, true);
- $level->setBlock(new Vector3($y + $x0, -$x + $y0, $z), $block, false, false, true);
- $y++;
- if($radiusError<0){
- $radiusError += 2 * $y + 1;
- }else{
- $x--;
- $radiusError+= 2 * ($y - $x + 1);
- }
- }
- }
- // Generates 1/4 of a circle, so from 0 to 1/2 Pi
- public function generateCircle($radius){
- $x = $radius;
- $y = 0;
- $radiusError = 1-$x;
- $shape = array();
- while($x >= $y){
- $shape[$x] = $y;
- $shape[$y] = $x;
- $y++;
- if($radiusError<0){
- $radiusError += 2 * $y + 1;
- }else{
- $x--;
- $radiusError+= 2 * ($y - $x + 1);
- }
- }
- return $shape;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement