SHOW:
|
|
- or go back to the newest paste.
1 | <?php | |
2 | ||
3 | public function generateHollowSphere($x, $y, $z, $levelName, $radius, $blockId){ | |
4 | $block = new Block($blockId); | |
5 | $level = Server::getInstance()->getLevel($levelName); | |
6 | ||
7 | $shape = $this->generateCircle($radius); // generate the main circle | |
8 | ||
9 | $this->drawCircle($x, $y, $z, $radius, $block, $level); // Draw the middle circle of the sphere | |
10 | ||
11 | for($i=1;$i=<$radius;$i++){ | |
12 | $hight = $shape[$i]; | |
13 | - | $this->draw2CirclesOfSphere($x, $y, $x+$i, $x-$i, $hight, $block, $level); |
13 | + | $this->draw2CirclesOfSphere($x, $y, $z+$i, $z-$i, $hight, $block, $level); |
14 | } | |
15 | } | |
16 | ||
17 | // This is a fast method to draw 2 identical circles | |
18 | public function draw2CirclesOfSphere($x0, $y0, $z1, $z2, $radius, $block, $level){ | |
19 | $x = $radius; | |
20 | $y = 0; | |
21 | $radiusError = 1-$x; | |
22 | ||
23 | while($x >= $y){ | |
24 | $level->setBlock(new Vector3($x + $x0, $y + $y0, $z1), $block, false, false, true); | |
25 | $level->setBlock(new Vector3($y + $x0, $x + $y0, $z1), $block, false, false, true); | |
26 | $level->setBlock(new Vector3(-$x + $x0, $y + $y0, $z1), $block, false, false, true); | |
27 | $level->setBlock(new Vector3(-$y + $x0, $x + $y0, $z1), $block, false, false, true); | |
28 | $level->setBlock(new Vector3(-$x + $x0, -$y + $y0, $z1), $block, false, false, true); | |
29 | $level->setBlock(new Vector3(-$y + $x0, -$x + $y0, $z1), $block, false, false, true); | |
30 | $level->setBlock(new Vector3($x + $x0, -$y + $y0, $z1), $block, false, false, true); | |
31 | $level->setBlock(new Vector3($y + $x0, -$x + $y0, $z1), $block, false, false, true); | |
32 | ||
33 | $level->setBlock(new Vector3($x + $x0, $y + $y0, $z2), $block, false, false, true); | |
34 | $level->setBlock(new Vector3($y + $x0, $x + $y0, $z2), $block, false, false, true); | |
35 | $level->setBlock(new Vector3(-$x + $x0, $y + $y0, $z2), $block, false, false, true); | |
36 | $level->setBlock(new Vector3(-$y + $x0, $x + $y0, $z2), $block, false, false, true); | |
37 | $level->setBlock(new Vector3(-$x + $x0, -$y + $y0, $z2), $block, false, false, true); | |
38 | $level->setBlock(new Vector3(-$y + $x0, -$x + $y0, $z2), $block, false, false, true); | |
39 | $level->setBlock(new Vector3($x + $x0, -$y + $y0, $z2), $block, false, false, true); | |
40 | $level->setBlock(new Vector3($y + $x0, -$x + $y0, $z2), $block, false, false, true); | |
41 | ||
42 | $y++; | |
43 | if($radiusError<0){ | |
44 | $radiusError += 2 * $y + 1; | |
45 | }else{ | |
46 | $x--; | |
47 | $radiusError+= 2 * ($y - $x + 1); | |
48 | } | |
49 | } | |
50 | } | |
51 | ||
52 | // This is a fast method to draw 1 circle | |
53 | public function drawCircle($x0, $y0, $z, $radius, $block, $level){ | |
54 | $x = $radius; | |
55 | $y = 0; | |
56 | $radiusError = 1-$x; | |
57 | ||
58 | while($x >= $y){ | |
59 | $level->setBlock(new Vector3($x + $x0, $y + $y0, $z), $block, false, false, true); | |
60 | $level->setBlock(new Vector3($y + $x0, $x + $y0, $z), $block, false, false, true); | |
61 | $level->setBlock(new Vector3(-$x + $x0, $y + $y0, $z), $block, false, false, true); | |
62 | $level->setBlock(new Vector3(-$y + $x0, $x + $y0, $z), $block, false, false, true); | |
63 | $level->setBlock(new Vector3(-$x + $x0, -$y + $y0, $z), $block, false, false, true); | |
64 | $level->setBlock(new Vector3(-$y + $x0, -$x + $y0, $z), $block, false, false, true); | |
65 | $level->setBlock(new Vector3($x + $x0, -$y + $y0, $z), $block, false, false, true); | |
66 | $level->setBlock(new Vector3($y + $x0, -$x + $y0, $z), $block, false, false, true); | |
67 | ||
68 | $y++; | |
69 | if($radiusError<0){ | |
70 | $radiusError += 2 * $y + 1; | |
71 | }else{ | |
72 | $x--; | |
73 | $radiusError+= 2 * ($y - $x + 1); | |
74 | } | |
75 | } | |
76 | } | |
77 | ||
78 | // Generates 1/4 of a circle, so from 0 to 1/2 Pi | |
79 | public function generateCircle($radius){ | |
80 | $x = $radius; | |
81 | $y = 0; | |
82 | $radiusError = 1-$x; | |
83 | $shape = array(); | |
84 | ||
85 | while($x >= $y){ | |
86 | $shape[$x] = $y; | |
87 | $shape[$y] = $x; | |
88 | $y++; | |
89 | if($radiusError<0){ | |
90 | $radiusError += 2 * $y + 1; | |
91 | }else{ | |
92 | $x--; | |
93 | $radiusError+= 2 * ($y - $x + 1); | |
94 | } | |
95 | } | |
96 | ||
97 | return $shape; | |
98 | } |