GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
Vector3 Class Reference

Public Member Functions

 __construct ($x=0, $y=0, $z=0)
 
 getX ()
 
 getY ()
 
 getZ ()
 
 getFloorX ()
 
 getFloorY ()
 
 getFloorZ ()
 
 getRight ()
 
 getUp ()
 
 getForward ()
 
 getSouth ()
 
 getWest ()
 
 add ($x, $y=0, $z=0)
 
 subtract ($x=0, $y=0, $z=0)
 
 multiply ($number)
 
 divide ($number)
 
 ceil ()
 
 floor ()
 
 round ()
 
 abs ()
 
 getSide ($side, $step=1)
 
 asVector3 ()
 
 distance (Vector3 $pos)
 
 distanceSquared (Vector3 $pos)
 
 maxPlainDistance ($x=0, $z=0)
 
 length ()
 
 lengthSquared ()
 
 normalize ()
 
 dot (Vector3 $v)
 
 cross (Vector3 $v)
 
 equals (Vector3 $v)
 
 getIntermediateWithXValue (Vector3 $v, $x)
 
 getIntermediateWithYValue (Vector3 $v, $y)
 
 getIntermediateWithZValue (Vector3 $v, $z)
 
 setComponents ($x, $y, $z)
 
 fromObjectAdd (Vector3 $pos, $x, $y, $z)
 
 __toString ()
 

Static Public Member Functions

static getOppositeSide ($side)
 
static createRandomDirection (Random $random)
 

Data Fields

const SIDE_DOWN = 0
 
const SIDE_UP = 1
 
const SIDE_NORTH = 2
 
const SIDE_SOUTH = 3
 
const SIDE_WEST = 4
 
const SIDE_EAST = 5
 
 $x
 
 $y
 
 $z
 

Constructor & Destructor Documentation

◆ __construct()

__construct (   $x = 0,
  $y = 0,
  $z = 0 
)

Vector3 constructor.

Parameters
int$x
int$y
int$z
46  {
47  $this->x = $x;
48  $this->y = $y;
49  $this->z = $z;
50  }

Member Function Documentation

◆ __toString()

__toString ( )
Returns
string
471  {
472  return "Vector3(x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")";
473  }

◆ abs()

abs ( )
Returns
Vector3
201  {
202  return new Vector3(abs($this->x), abs($this->y), abs($this->z));
203  }

◆ add()

add (   $x,
  $y = 0,
  $z = 0 
)
Parameters
Vector3 | int$x
int$y
int$z
Returns
Vector3
136  {
137  if($x instanceof Vector3){
138  return new Vector3($this->x + $x->x, $this->y + $x->y, $this->z + $x->z);
139  }else{
140  return new Vector3($this->x + $x, $this->y + $y, $this->z + $z);
141  }
142  }

◆ asVector3()

asVector3 ( )

Return a Vector3 instance

Returns
Vector3
235  : Vector3{
236  return new Vector3($this->x, $this->y, $this->z);
237  }

◆ ceil()

ceil ( )
Returns
Vector3
180  {
181  return new Vector3((int) ceil($this->x), (int) ceil($this->y), (int) ceil($this->z));
182  }

◆ createRandomDirection()

static createRandomDirection ( Random  $random)
static
Parameters
Random$random
Returns
Vector3
480  {
481  return VectorMath::getDirection3D($random->nextFloat() * 2 * pi(), $random->nextFloat() * 2 * pi());
482  }

◆ cross()

cross ( Vector3  $v)
Parameters
Vector3$v
Returns
Vector3
341  {
342  return new Vector3(
343  $this->y * $v->z - $this->z * $v->y,
344  $this->z * $v->x - $this->x * $v->z,
345  $this->x * $v->y - $this->y * $v->x
346  );
347  }

◆ distance()

distance ( Vector3  $pos)
Parameters
Vector3$pos
Returns
float
272  {
273  return sqrt($this->distanceSquared($pos));
274  }

◆ distanceSquared()

distanceSquared ( Vector3  $pos)
Parameters
Vector3$pos
Returns
number
281  {
282  return pow($this->x - $pos->x, 2) + pow($this->y - $pos->y, 2) + pow($this->z - $pos->z, 2);
283  }

◆ divide()

divide (   $number)
Parameters
$number
Returns
Vector3
173  {
174  return new Vector3($this->x / $number, $this->y / $number, $this->z / $number);
175  }

◆ dot()

dot ( Vector3  $v)
Parameters
Vector3$v
Returns
int
332  {
333  return $this->x * $v->x + $this->y * $v->y + $this->z * $v->z;
334  }

◆ equals()

equals ( Vector3  $v)
Parameters
Vector3$v
Returns
bool
354  {
355  return $this->x == $v->x and $this->y == $v->y and $this->z == $v->z;
356  }

◆ floor()

floor ( )
Returns
Vector3
187  {
188  return new Vector3((int) floor($this->x), (int) floor($this->y), (int) floor($this->z));
189  }

◆ fromObjectAdd()

fromObjectAdd ( Vector3  $pos,
  $x,
  $y,
  $z 
)
Parameters
Vector3$pos
$x
$y
$z
Returns
$this
461  {
462  $this->x = $pos->x + $x;
463  $this->y = $pos->y + $y;
464  $this->z = $pos->z + $z;
465  return $this;
466  }

◆ getFloorX()

getFloorX ( )
Returns
int
76  {
77  return (int) floor($this->x);
78  }

◆ getFloorY()

getFloorY ( )
Returns
int
83  {
84  return (int) floor($this->y);
85  }

◆ getFloorZ()

getFloorZ ( )
Returns
int
90  {
91  return (int) floor($this->z);
92  }

◆ getForward()

getForward ( )
Returns
int
111  {
112  return $this->z;
113  }

◆ getIntermediateWithXValue()

getIntermediateWithXValue ( Vector3  $v,
  $x 
)

Returns a new vector with x value equal to the second parameter, along the line between this vector and the passed in vector, or null if not possible.

Parameters
Vector3$v
float$x
Returns
Vector3
367  {
368  $xDiff = $v->x - $this->x;
369  $yDiff = $v->y - $this->y;
370  $zDiff = $v->z - $this->z;
371 
372  if(($xDiff * $xDiff) < 0.0000001){
373  return null;
374  }
375 
376  $f = ($x - $this->x) / $xDiff;
377 
378  if($f < 0 or $f > 1){
379  return null;
380  }else{
381  return new Vector3($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f);
382  }
383  }

◆ getIntermediateWithYValue()

getIntermediateWithYValue ( Vector3  $v,
  $y 
)

Returns a new vector with y value equal to the second parameter, along the line between this vector and the passed in vector, or null if not possible.

Parameters
Vector3$v
float$y
Returns
Vector3
394  {
395  $xDiff = $v->x - $this->x;
396  $yDiff = $v->y - $this->y;
397  $zDiff = $v->z - $this->z;
398 
399  if(($yDiff * $yDiff) < 0.0000001){
400  return null;
401  }
402 
403  $f = ($y - $this->y) / $yDiff;
404 
405  if($f < 0 or $f > 1){
406  return null;
407  }else{
408  return new Vector3($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f);
409  }
410  }

◆ getIntermediateWithZValue()

getIntermediateWithZValue ( Vector3  $v,
  $z 
)

Returns a new vector with z value equal to the second parameter, along the line between this vector and the passed in vector, or null if not possible.

Parameters
Vector3$v
float$z
Returns
Vector3
421  {
422  $xDiff = $v->x - $this->x;
423  $yDiff = $v->y - $this->y;
424  $zDiff = $v->z - $this->z;
425 
426  if(($zDiff * $zDiff) < 0.0000001){
427  return null;
428  }
429 
430  $f = ($z - $this->z) / $zDiff;
431 
432  if($f < 0 or $f > 1){
433  return null;
434  }else{
435  return new Vector3($this->x + $xDiff * $f, $this->y + $yDiff * $f, $this->z + $zDiff * $f);
436  }
437  }

◆ getOppositeSide()

static getOppositeSide (   $side)
static

Returns the Vector3 side number opposite the specified one

Parameters
int$side0-5 one of the Vector3::SIDE_* constants
Returns
int
Exceptions
248  {
249  switch((int) $side){
250  case Vector3::SIDE_DOWN:
251  return Vector3::SIDE_UP;
252  case Vector3::SIDE_UP:
253  return Vector3::SIDE_DOWN;
254  case Vector3::SIDE_NORTH:
255  return Vector3::SIDE_SOUTH;
256  case Vector3::SIDE_SOUTH:
257  return Vector3::SIDE_NORTH;
258  case Vector3::SIDE_WEST:
259  return Vector3::SIDE_EAST;
260  case Vector3::SIDE_EAST:
261  return Vector3::SIDE_WEST;
262  default:
263  return -1;
264  }
265  }

◆ getRight()

getRight ( )
Returns
int
97  {
98  return $this->x;
99  }

◆ getSide()

getSide (   $side,
  $step = 1 
)
Parameters
$side
int$step
Returns
$this|Vector3
211  {
212  switch((int) $side){
213  case Vector3::SIDE_DOWN:
214  return new Vector3($this->x, $this->y - $step, $this->z);
215  case Vector3::SIDE_UP:
216  return new Vector3($this->x, $this->y + $step, $this->z);
217  case Vector3::SIDE_NORTH:
218  return new Vector3($this->x, $this->y, $this->z - $step);
219  case Vector3::SIDE_SOUTH:
220  return new Vector3($this->x, $this->y, $this->z + $step);
221  case Vector3::SIDE_WEST:
222  return new Vector3($this->x - $step, $this->y, $this->z);
223  case Vector3::SIDE_EAST:
224  return new Vector3($this->x + $step, $this->y, $this->z);
225  default:
226  return $this;
227  }
228  }

◆ getSouth()

getSouth ( )
Returns
int
118  {
119  return $this->x;
120  }

◆ getUp()

getUp ( )
Returns
int
104  {
105  return $this->y;
106  }

◆ getWest()

getWest ( )
Returns
int
125  {
126  return $this->z;
127  }

◆ getX()

getX ( )
Returns
int
55  {
56  return $this->x;
57  }

◆ getY()

getY ( )
Returns
int
62  {
63  return $this->y;
64  }

◆ getZ()

getZ ( )
Returns
int
69  {
70  return $this->z;
71  }

◆ length()

length ( )
Returns
float
304  {
305  return sqrt($this->lengthSquared());
306  }

◆ lengthSquared()

lengthSquared ( )
Returns
int
311  {
312  return $this->x * $this->x + $this->y * $this->y + $this->z * $this->z;
313  }

◆ maxPlainDistance()

maxPlainDistance (   $x = 0,
  $z = 0 
)
Parameters
int$x
int$z
Returns
mixed
291  {
292  if($x instanceof Vector3){
293  return $this->maxPlainDistance($x->x, $x->z);
294  }elseif($x instanceof Vector2){
295  return $this->maxPlainDistance($x->x, $x->y);
296  }else{
297  return max(abs($this->x - $x), abs($this->z - $z));
298  }
299  }

◆ multiply()

multiply (   $number)
Parameters
$number
Returns
Vector3
164  {
165  return new Vector3($this->x * $number, $this->y * $number, $this->z * $number);
166  }

◆ normalize()

normalize ( )
Returns
Vector3
318  {
319  $len = $this->lengthSquared();
320  if($len > 0){
321  return $this->divide(sqrt($len));
322  }
323 
324  return new Vector3(0, 0, 0);
325  }

◆ round()

round ( )
Returns
Vector3
194  {
195  return new Vector3((int) round($this->x), (int) round($this->y), (int) round($this->z));
196  }

◆ setComponents()

setComponents (   $x,
  $y,
  $z 
)
Parameters
$x
$y
$z
Returns
Vector3
446  {
447  $this->x = $x;
448  $this->y = $y;
449  $this->z = $z;
450  return $this;
451  }

◆ subtract()

subtract (   $x = 0,
  $y = 0,
  $z = 0 
)
Parameters
Vector3 | int$x
int$y
int$z
Returns
Vector3
151  {
152  if($x instanceof Vector3){
153  return $this->add(-$x->x, -$x->y, -$x->z);
154  }else{
155  return $this->add(-$x, -$y, -$z);
156  }
157  }

Field Documentation

◆ $x

$x

◆ $y

$y

◆ $z

$z

◆ SIDE_DOWN

const SIDE_DOWN = 0

◆ SIDE_EAST

const SIDE_EAST = 5

◆ SIDE_NORTH

const SIDE_NORTH = 2

◆ SIDE_SOUTH

const SIDE_SOUTH = 3

◆ SIDE_UP

const SIDE_UP = 1

◆ SIDE_WEST

const SIDE_WEST = 4

The documentation for this class was generated from the following file: