當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Vector3::lengthSquared方法代碼示例

本文整理匯總了PHP中pocketmine\math\Vector3::lengthSquared方法的典型用法代碼示例。如果您正苦於以下問題:PHP Vector3::lengthSquared方法的具體用法?PHP Vector3::lengthSquared怎麽用?PHP Vector3::lengthSquared使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pocketmine\math\Vector3的用法示例。


在下文中一共展示了Vector3::lengthSquared方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: onUpdate

 public function onUpdate($currentTick)
 {
     if ($this->closed !== false) {
         return false;
     }
     if (++$this->switchDirectionTicker === 100) {
         $this->switchDirectionTicker = 0;
         if (mt_rand(0, 100) < 50) {
             $this->swimDirection = null;
         }
     }
     $this->lastUpdate = $currentTick;
     $this->timings->startTiming();
     $hasUpdate = parent::onUpdate($currentTick);
     if ($this->isAlive()) {
         if ($this->y > 62 and $this->swimDirection !== null) {
             $this->swimDirection->y = -0.5;
         }
         /*$inWater = $this->isInsideOfAir();
         		if(!$inWater){
         			//$this->motionY -= $this->gravity;
         			$this->swimDirection = null;
         		}else*/
         if ($this->swimDirection !== null) {
             if ($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2 <= $this->swimDirection->lengthSquared()) {
                 $this->motionX = $this->swimDirection->x * $this->swimSpeed;
                 $this->motionY = $this->swimDirection->y * $this->swimSpeed;
                 $this->motionZ = $this->swimDirection->z * $this->swimSpeed;
             }
         } else {
             $this->swimDirection = $this->generateRandomDirection();
             $this->swimSpeed = mt_rand(50, 100);
         }
         $expectedPos = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);
         $this->move($this->motionX, $this->motionY, $this->motionZ);
         if ($expectedPos->distanceSquared($this) > 0) {
             $this->swimDirection = $this->generateRandomDirection();
             $this->swimSpeed = mt_rand(50, 100);
         }
         $friction = 1 - $this->drag;
         $this->motionX *= $friction;
         $this->motionY *= 1 - $this->drag;
         $this->motionZ *= $friction;
         $f = sqrt($this->motionX ** 2 + $this->motionZ ** 2);
         $this->yaw = -atan2($this->motionX, $this->motionZ) * 180 / M_PI;
         $this->pitch = -atan2($f, $this->motionY) * 180 / M_PI;
         if ($this->onGround) {
             $this->motionY *= -0.5;
         }
         $this->updateMovement();
     }
     $this->timings->stopTiming();
     return $hasUpdate or !$this->onGround or abs($this->motionX) > 1.0E-5 or abs($this->motionY) > 1.0E-5 or abs($this->motionZ) > 1.0E-5;
 }
開發者ID:PepbookPvP,項目名稱:Genisys,代碼行數:54,代碼來源:Bat.php

示例2: onUpdate

 public function onUpdate($currentTick)
 {
     if ($this->closed !== \false) {
         return \false;
     }
     if (++$this->switchDirectionTicker === 100) {
         $this->switchDirectionTicker = 0;
         if (\mt_rand(0, 100) < 50) {
             $this->swimDirection = \null;
         }
     }
     $this->lastUpdate = $currentTick;
     $this->timings->startTiming();
     $hasUpdate = parent::onUpdate($currentTick);
     if (!$this->dead) {
         if ($this->y > 62 and $this->swimDirection !== \null) {
             $this->swimDirection->y = -0.5;
         }
         $inWater = $this->isInsideOfWater();
         if (!$inWater) {
             $this->motionY -= $this->gravity;
             $this->swimDirection = \null;
         } elseif ($this->swimDirection !== \null) {
             if ($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2 <= $this->swimDirection->lengthSquared()) {
                 $this->motionX = $this->swimDirection->x * $this->swimSpeed;
                 $this->motionY = $this->swimDirection->y * $this->swimSpeed;
                 $this->motionZ = $this->swimDirection->z * $this->swimSpeed;
             }
         } else {
             $this->swimDirection = $this->generateRandomDirection();
             $this->swimSpeed = \mt_rand(50, 100) / 2000;
         }
         $expectedPos = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);
         $this->move($this->motionX, $this->motionY, $this->motionZ);
         if ($expectedPos->distanceSquared($this) > 0) {
             $this->swimDirection = $this->generateRandomDirection();
             $this->swimSpeed = \mt_rand(50, 100) / 2000;
         }
         $friction = 1 - $this->drag;
         $this->motionX *= $friction;
         $this->motionY *= 1 - $this->drag;
         $this->motionZ *= $friction;
         $f = \sqrt($this->motionX ** 2 + $this->motionZ ** 2);
         $this->yaw = -\atan2($this->motionX, $this->motionZ) * 180 / M_PI;
         $this->pitch = -\atan2($f, $this->motionY) * 180 / M_PI;
         if ($this->onGround) {
             $this->motionY *= -0.5;
         }
     }
     $this->timings->stopTiming();
     return $hasUpdate or !$this->onGround or $this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0;
 }
開發者ID:Edwardthedog2,項目名稱:Steadfast2,代碼行數:52,代碼來源:Squid.php


注:本文中的pocketmine\math\Vector3::lengthSquared方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。