Class: Vector4

Phaser.Math. Vector4

A representation of a vector in 4D space.

A four-component vector.


new Vector4( [x] [, y] [, z] [, w])

Parameters:
Name Type Argument Description
x number <optional>

The x component.

y number <optional>

The y component.

z number <optional>

The z component.

w number <optional>

The w component.

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

Members


w :number

The w component of this Vector.

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

x :number

The x component of this Vector.

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

y :number

The y component of this Vector.

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

z :number

The z component of this Vector.

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

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 | Phaser.Math.Vector4

The Vector to add to this Vector.

Since: 3.0.0
Source: src/math/Vector4.js (Line 173)
Returns:

This Vector4.

Type
Phaser.Math.Vector4

clone()

Make a clone of this Vector4.

Since: 3.0.0
Source: src/math/Vector4.js (Line 90)
Returns:

A clone of this Vector4.

Type
Phaser.Math.Vector4

copy(src)

Copy the components of a given Vector into this Vector.

Parameters:
Name Type Description
src Phaser.Math.Vector4

The Vector to copy the components from.

Since: 3.0.0
Source: src/math/Vector4.js (Line 103)
Returns:

This Vector4.

Type
Phaser.Math.Vector4

distance(v)

Calculate the distance between this Vector and the given Vector.

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

The Vector to calculate the distance to.

Since: 3.0.0
Source: src/math/Vector4.js (Line 389)
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 | Phaser.Math.Vector4

The Vector to calculate the distance to.

Since: 3.0.0
Source: src/math/Vector4.js (Line 409)
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 | Phaser.Math.Vector4

The Vector to divide this Vector by.

Since: 3.0.0
Source: src/math/Vector4.js (Line 367)
Returns:

This Vector4.

Type
Phaser.Math.Vector4

dot(v)

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

Parameters:
Name Type Description
v Phaser.Math.Vector4

The Vector4 to dot product with this Vector4.

Since: 3.0.0
Source: src/math/Vector4.js (Line 300)
Returns:

The dot product of this Vector and the given Vector.

Type
number

equals(v)

Check whether this Vector is equal to a given Vector.

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

Parameters:
Name Type Description
v Phaser.Math.Vector4

The vector to check equality with.

Since: 3.0.0
Source: src/math/Vector4.js (Line 123)
Returns:

A boolean indicating whether the two Vectors are equal or not.

Type
boolean

length()

Calculate the length (or magnitude) of this Vector.

Since: 3.0.0
Source: src/math/Vector4.js (Line 233)
Returns:

The length of this Vector.

Type
number

lengthSq()

Calculate the length of this Vector squared.

Since: 3.0.0
Source: src/math/Vector4.js (Line 251)
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.Vector4

The Vector4 to interpolate towards.

t number <optional>
0

The interpolation percentage, between 0 and 1.

Since: 3.0.0
Source: src/math/Vector4.js (Line 315)
Returns:

This Vector4.

Type
Phaser.Math.Vector4

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 | Phaser.Math.Vector4

The Vector to multiply this Vector by.

Since: 3.0.0
Source: src/math/Vector4.js (Line 345)
Returns:

This Vector4.

Type
Phaser.Math.Vector4

negate()

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

Since: 3.0.0
Source: src/math/Vector4.js (Line 429)
Returns:

This Vector4.

Type
Phaser.Math.Vector4

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/Vector4.js (Line 269)
Returns:

This Vector4.

Type
Phaser.Math.Vector4

reset()

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

Since: 3.0.0
Source: src/math/Vector4.js (Line 507)
Returns:

This Vector4.

Type
Phaser.Math.Vector4

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/Vector4.js (Line 213)
Returns:

This Vector4.

Type
Phaser.Math.Vector4

set(x, y, z, w)

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

Parameters:
Name Type Description
x number | object

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

y number

The y value to set for this Vector.

z number

The z value to set for this Vector.

w number

The z value to set for this Vector.

Since: 3.0.0
Source: src/math/Vector4.js (Line 140)
Returns:

This Vector4.

Type
Phaser.Math.Vector4

subtract(v)

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

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

The Vector to subtract from this Vector.

Since: 3.0.0
Source: src/math/Vector4.js (Line 193)
Returns:

This Vector4.

Type
Phaser.Math.Vector4

transformMat4(mat)

Transform this Vector with the given Matrix.

Parameters:
Name Type Description
mat Phaser.Math.Matrix4

The Matrix4 to transform this Vector4 with.

Since: 3.0.0
Source: src/math/Vector4.js (Line 447)
Returns:

This Vector4.

Type
Phaser.Math.Vector4

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/Vector4.js (Line 473)
Returns:

This Vector4.

Type
Phaser.Math.Vector4