本文整理匯總了PHP中Position::DistanceTo方法的典型用法代碼示例。如果您正苦於以下問題:PHP Position::DistanceTo方法的具體用法?PHP Position::DistanceTo怎麽用?PHP Position::DistanceTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Position
的用法示例。
在下文中一共展示了Position::DistanceTo方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: dodrivenext
function dodrivenext(Player $player, $numparams, $params)
{
$pos = $player->Position();
$nearest = null;
$distance = 0;
for ($i = 0; $i < 700; $i++) {
GetVehiclePos($i, &$x, &$y, &$z);
if ($x == 0 && $y == 0 && $z == 0) {
continue;
}
$vpos = new Position($x, $y, $z);
$dist = $vpos->DistanceTo($pos);
if ($nearest === null || $dist < $distance) {
$distance = $dist;
$nearest = $i;
}
}
if ($nearest !== null) {
PutPlayerInVehicle($player->id, $nearest, 0);
}
return COMMAND_OK;
}
示例2: AddObject
/**
** AddOBject
** Adds a dynamic object to this location. If sight is -1, then objects are always shown.
**
** Parameters:
** - modelid: Model of the object
** - position: Position of the object
** - rotation: Rotation of the object
**/
public function AddObject($modelid, Position $position, Position $rotation = null, $sight = 0)
{
/* Create the object */
if ($sight == 0) {
$sight = $this->sight;
}
if ($rotation == null) {
$rotation = new Position(0, 0, 0, 0);
}
$obj = new Obj($modelid, $position, $rotation, $sight);
/* Find this object nearest objects */
if ($sight != -1) {
foreach ($this->objects as $o) {
if ($position->DistanceTo($o->position) < $sight) {
$obj->SetNear($o);
$o->SetNear($obj);
}
}
}
/* This object is also near itself */
$obj->SetNear($obj);
/* Add the object to this location objects list */
$this->objects[] = $obj;
/* Add the object to its sector objects */
$sector = $this->area->Locate($position);
if ($sight != -1) {
$sectors = $sector->FindSectors($position, $sight);
foreach ($sectors as $sector) {
$sector->AddObject($obj);
}
} else {
$sector->AddObject($obj);
}
}
示例3: FindNearestObject
public function FindNearestObject(Position $position, &$nearest, &$distance)
{
foreach ($this->objects as $o) {
$tmpdist = $position->DistanceTo($o->position);
if ($tmpdist > $o->Sight()) {
continue;
}
if ($tmpdist < $distance || $nearest == null) {
$nearest = $o;
$distance = $tmpdist;
}
}
}