本文整理匯總了PHP中pocketmine\math\Vector3::length方法的典型用法代碼示例。如果您正苦於以下問題:PHP Vector3::length方法的具體用法?PHP Vector3::length怎麽用?PHP Vector3::length使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pocketmine\math\Vector3
的用法示例。
在下文中一共展示了Vector3::length方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: explodeA
/**
* @return bool
*/
public function explodeA() : bool
{
if ($this->size < 0.1) {
return false;
}
$vector = new Vector3(0, 0, 0);
$vBlock = new Vector3(0, 0, 0);
$mRays = intval($this->rays - 1);
for ($i = 0; $i < $this->rays; ++$i) {
for ($j = 0; $j < $this->rays; ++$j) {
for ($k = 0; $k < $this->rays; ++$k) {
if ($i === 0 or $i === $mRays or $j === 0 or $j === $mRays or $k === 0 or $k === $mRays) {
$vector->setComponents($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1);
$vector->setComponents($vector->x / ($len = $vector->length()) * $this->stepLen, $vector->y / $len * $this->stepLen, $vector->z / $len * $this->stepLen);
$pointerX = $this->source->x;
$pointerY = $this->source->y;
$pointerZ = $this->source->z;
for ($blastForce = $this->size * (mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75) {
$x = (int) $pointerX;
$y = (int) $pointerY;
$z = (int) $pointerZ;
$vBlock->x = $pointerX >= $x ? $x : $x - 1;
$vBlock->y = $pointerY >= $y ? $y : $y - 1;
$vBlock->z = $pointerZ >= $z ? $z : $z - 1;
if ($vBlock->y < 0 or $vBlock->y > 127) {
break;
}
$block = $this->level->getBlock($vBlock);
if ($block->getId() !== 0) {
$blastForce -= ($block->getResistance() / 5 + 0.3) * $this->stepLen;
if ($blastForce > 0) {
if (!isset($this->affectedBlocks[$index = Level::blockHash($block->x, $block->y, $block->z)])) {
$this->affectedBlocks[$index] = $block;
}
}
}
$pointerX += $vector->x;
$pointerY += $vector->y;
$pointerZ += $vector->z;
}
}
}
}
}
return true;
}
示例2: explodeBlocks
public function explodeBlocks(Position $source, $rays = 16, $size = 4)
{
$vector = new Vector3(0, 0, 0);
$vBlock = new Vector3(0, 0, 0);
$stepLen = 0.3;
$mRays = \intval($rays - 1);
$affectedBlocks = array();
for ($i = 0; $i < $rays; ++$i) {
for ($j = 0; $j < $rays; ++$j) {
for ($k = 0; $k < $rays; ++$k) {
if ($i === 0 or $i === $mRays or $j === 0 or $j === $mRays or $k === 0 or $k === $mRays) {
$vector->setComponents($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1);
$vector->setComponents($vector->x / ($len = $vector->length()) * $stepLen, $vector->y / $len * $stepLen, $vector->z / $len * $stepLen);
$pointerX = $source->x;
$pointerY = $source->y;
$pointerZ = $source->z;
for ($blastForce = $size * (\mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $stepLen * 0.75) {
$x = (int) $pointerX;
$y = (int) $pointerY;
$z = (int) $pointerZ;
$vBlock->x = $pointerX >= $x ? $x : $x - 1;
$vBlock->y = $pointerY >= $y ? $y : $y - 1;
$vBlock->z = $pointerZ >= $z ? $z : $z - 1;
if ($vBlock->y < 0 or $vBlock->y > 127) {
break;
}
$block = $source->getLevel()->getBlock($vBlock);
if ($block->getId() !== 0) {
$blastForce -= (mt_rand(1, 3) / 5 + 0.3) * $stepLen;
if ($blastForce > 0) {
if (!isset($affectedBlocks[$index = \PHP_INT_SIZE === 8 ? ($block->x & 0xfffffff) << 35 | ($block->y & 0x7f) << 28 | $block->z & 0xfffffff : $block->x . ":" . $block->y . ":" . $block->z])) {
$affectedBlocks[$index] = $block;
}
}
}
$pointerX += $vector->x;
$pointerY += $vector->y;
$pointerZ += $vector->z;
}
}
}
}
}
foreach ($affectedBlocks as $block) {
if ($block instanceof Block) {
$block->getLevel()->setBlock($block, new Air(), false, false);
}
}
}
示例3: explodeA
/**
* @return bool
*/
public function explodeA()
{
if ($this->size < 0.1) {
return \false;
}
$vector = new Vector3(0, 0, 0);
$vBlock = new Vector3(0, 0, 0);
$mRays = \intval($this->rays - 1);
for ($i = 0; $i < $this->rays; ++$i) {
for ($j = 0; $j < $this->rays; ++$j) {
for ($k = 0; $k < $this->rays; ++$k) {
if ($i === 0 or $i === $mRays or $j === 0 or $j === $mRays or $k === 0 or $k === $mRays) {
$vector->setComponents($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1);
$vector->setComponents($vector->x / ($len = $vector->length()) * $this->stepLen, $vector->y / $len * $this->stepLen, $vector->z / $len * $this->stepLen);
$pointerX = $this->source->x;
$pointerY = $this->source->y;
$pointerZ = $this->source->z;
for ($blastForce = $this->size * (\mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75) {
$x = (int) $pointerX;
$y = (int) $pointerY;
$z = (int) $pointerZ;
$vBlock->x = $pointerX >= $x ? $x : $x - 1;
$vBlock->y = $pointerY >= $y ? $y : $y - 1;
$vBlock->z = $pointerZ >= $z ? $z : $z - 1;
if ($vBlock->y < 0 or $vBlock->y > 127) {
break;
}
$block = $this->level->getBlock($vBlock);
if ($block->getId() !== 0) {
$blastForce -= ($block->getHardness() / 5 + 0.3) * $this->stepLen;
if ($blastForce > 0) {
if (!isset($this->affectedBlocks[$index = \PHP_INT_SIZE === 8 ? ($block->x & 0xfffffff) << 35 | ($block->y & 0x7f) << 28 | $block->z & 0xfffffff : $block->x . ":" . $block->y . ":" . $block->z])) {
$this->affectedBlocks[$index] = $block;
}
}
}
$pointerX += $vector->x;
$pointerY += $vector->y;
$pointerZ += $vector->z;
}
}
}
}
}
return \true;
}