Class: Vector3

Phaser.Math. Vector3

A representation of a vector in 3D space.

A three-component vector.


new Vector3( [x] [, y] [, z])

Parameters:
Name Type Argument Description
x number <optional>

The x component.

y number <optional>

The y component.

z number <optional>

The z component.

Since: 3.0.0
Source: src/math/Vector3.js (Line 12)

Members


x :number

The x component of this Vector.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/math/Vector3.js (Line 33)

y :number

The y component of this Vector.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/math/Vector3.js (Line 43)

z :number

The z component of this Vector.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/math/Vector3.js (Line 53)

Methods


add(v)

Add a given Vector to this Vector. Addition is component-wise.

Parameters:
Name Type Description
v Phaser.Math.Vector2 | Phaser.Math.Vector3

The Vector to add to this Vector.

Since: 3.0.0
Source: src/math/Vector3.js (Line 202)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

clone()

Make a clone of this Vector3.

Since: 3.0.0
Source: src/math/Vector3.js (Line 96)
Returns:

A new Vector3 object containing this Vectors values.

Type
Phaser.Math.Vector3

copy(src)

Copy the components of a given Vector into this Vector.

Parameters:
Name Type Description
src Phaser.Math.Vector2 | Phaser.Math.Vector3

The Vector to copy the components from.

Since: 3.0.0
Source: src/math/Vector3.js (Line 153)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

cross(v)

Calculate the cross (vector) product of this Vector (which will be modified) and the given Vector.

Parameters:
Name Type Description
v Phaser.Math.Vector3

The Vector to cross product with.

Since: 3.0.0
Source: src/math/Vector3.js (Line 443)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

crossVectors(a, b)

Calculate the cross (vector) product of two given Vectors.

Parameters:
Name Type Description
a Phaser.Math.Vector3

The first Vector to multiply.

b Phaser.Math.Vector3

The second Vector to multiply.

Since: 3.0.0
Source: src/math/Vector3.js (Line 109)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

distance(v)

Calculate the distance between this Vector and the given Vector.

Parameters:
Name Type Description
v Phaser.Math.Vector2 | Phaser.Math.Vector3

The Vector to calculate the distance to.

Since: 3.0.0
Source: src/math/Vector3.js (Line 327)
Returns:

The distance from this Vector to the given Vector.

Type
number

distanceSq(v)

Calculate the distance between this Vector and the given Vector, squared.

Parameters:
Name Type Description
v Phaser.Math.Vector2 | Phaser.Math.Vector3

The Vector to calculate the distance to.

Since: 3.0.0
Source: src/math/Vector3.js (Line 346)
Returns:

The distance from this Vector to the given Vector, squared.

Type
number

divide(v)

Perform a component-wise division between this Vector and the given Vector.

Divides this Vector by the given Vector.

Parameters:
Name Type Description
v Phaser.Math.Vector2 | Phaser.Math.Vector3

The Vector to divide this Vector by.

Since: 3.0.0
Source: src/math/Vector3.js (Line 289)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

dot(v)

Calculate the dot product of this Vector and the given Vector.

Parameters:
Name Type Description
v Phaser.Math.Vector3

The Vector3 to dot product with this Vector3.

Since: 3.0.0
Source: src/math/Vector3.js (Line 428)
Returns:

The dot product of this Vector and v.

Type
number

equals(v)

Check whether this Vector is equal to a given Vector.

Performs a strict equality check against each Vector's components.

Parameters:
Name Type Description
v Phaser.Math.Vector3

The Vector3 to compare against.

Since: 3.0.0
Source: src/math/Vector3.js (Line 136)
Returns:

True if the two vectors strictly match, otherwise false.

Type
boolean

length()

Calculate the length (or magnitude) of this Vector.

Since: 3.0.0
Source: src/math/Vector3.js (Line 365)
Returns:

The length of this Vector.

Type
number

lengthSq()

Calculate the length of this Vector squared.

Since: 3.0.0
Source: src/math/Vector3.js (Line 382)
Returns:

The length of this Vector, squared.

Type
number

lerp(v [, t])

Linearly interpolate between this Vector and the given Vector.

Interpolates this Vector towards the given Vector.

Parameters:
Name Type Argument Default Description
v Phaser.Math.Vector3

The Vector3 to interpolate towards.

t number <optional>
0

The interpolation percentage, between 0 and 1.

Since: 3.0.0
Source: src/math/Vector3.js (Line 469)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

multiply(v)

Perform a component-wise multiplication between this Vector and the given Vector.

Multiplies this Vector by the given Vector.

Parameters:
Name Type Description
v Phaser.Math.Vector2 | Phaser.Math.Vector3

The Vector to multiply this Vector by.

Since: 3.0.0
Source: src/math/Vector3.js (Line 240)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

negate()

Negate the x, y and z components of this Vector.

Since: 3.0.0
Source: src/math/Vector3.js (Line 310)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

normalize()

Normalize this Vector.

Makes the vector a unit length vector (magnitude of 1) in the same direction.

Since: 3.0.0
Source: src/math/Vector3.js (Line 399)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

project(mat)

Multiplies this Vector3 by the specified matrix, applying a W divide. This is useful for projection,
e.g. unprojecting a 2D point into 3D space.

Parameters:
Name Type Description
mat Phaser.Math.Matrix4

The Matrix4 to multiply this Vector3 with.

Since: 3.0.0
Source: src/math/Vector3.js (Line 609)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

reset()

Make this Vector the zero vector (0, 0, 0).

Since: 3.0.0
Source: src/math/Vector3.js (Line 689)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

scale(scale)

Scale this Vector by the given value.

Parameters:
Name Type Description
scale number

The value to scale this Vector by.

Since: 3.0.0
Source: src/math/Vector3.js (Line 261)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

set(x [, y] [, z])

Set the x, y, and z components of this Vector to the given x, y, and z values.

Parameters:
Name Type Argument Description
x number | object

The x value to set for this Vector, or an object containing x, y and z components.

y number <optional>

The y value to set for this Vector.

z number <optional>

The z value to set for this Vector.

Since: 3.0.0
Source: src/math/Vector3.js (Line 172)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

subtract(v)

Subtract the given Vector from this Vector. Subtraction is component-wise.

Parameters:
Name Type Description
v Phaser.Math.Vector2 | Phaser.Math.Vector3

The Vector to subtract from this Vector.

Since: 3.0.0
Source: src/math/Vector3.js (Line 221)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

transformCoordinates(mat)

[description]

Parameters:
Name Type Description
mat Phaser.Math.Matrix4

The Matrix4 to transform this Vector3 with.

Since: 3.0.0
Source: src/math/Vector3.js (Line 545)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

transformMat3(mat)

Transform this Vector with the given Matrix.

Parameters:
Name Type Description
mat Phaser.Math.Matrix3

The Matrix3 to transform this Vector3 with.

Since: 3.0.0
Source: src/math/Vector3.js (Line 497)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

transformMat4(mat)

Transform this Vector with the given Matrix.

Parameters:
Name Type Description
mat Phaser.Math.Matrix4

The Matrix4 to transform this Vector3 with.

Since: 3.0.0
Source: src/math/Vector3.js (Line 521)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

transformQuat(q)

Transform this Vector with the given Quaternion.

Parameters:
Name Type Description
q Phaser.Math.Quaternion

The Quaternion to transform this Vector with.

Since: 3.0.0
Source: src/math/Vector3.js (Line 574)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

unproject(viewport, invProjectionView)

Unproject this point from 2D space to 3D space.
The point should have its x and y properties set to
2D screen space, and the z either at 0 (near plane)
or 1 (far plane). The provided matrix is assumed to already
be combined, i.e. projection view model.

After this operation, this vector's (x, y, z) components will
represent the unprojected 3D coordinate.

Parameters:
Name Type Description
viewport Phaser.Math.Vector4

Screen x, y, width and height in pixels.

invProjectionView Phaser.Math.Matrix4

Combined projection and view matrix.

Since: 3.0.0
Source: src/math/Vector3.js (Line 653)
Returns:

This Vector3.

Type
Phaser.Math.Vector3

up()

Set this Vector to point up.

Sets the y component of the vector to 1, and the others to 0.

Since: 3.0.0
Source: src/math/Vector3.js (Line 77)
Returns:

This Vector3.

Type
Phaser.Math.Vector3