Skip to content

Latest commit

 

History

History
706 lines (307 loc) · 7.89 KB

File metadata and controls

706 lines (307 loc) · 7.89 KB

Home > server > Vector3

Vector3 class

Represents a 3-dimensional vector.

Signature:

export default class Vector3 extends Float32Array implements Vector3Like 

Extends: Float32Array

Implements: Vector3Like

Remarks

All vector methods result in mutation of the vector instance. This class extends Float32Array to provide an efficient way to create and manipulate a 3-dimensional vector. Various convenience methods are provided for common vector operations.

Constructors

Constructor

Modifiers

Description

(constructor)(x, y, z)

Constructs a new instance of the Vector3 class

Properties

Property

Modifiers

Type

Description

length

readonly

number

The length of the vector.

magnitude

readonly

number

The magnitude of the vector. Alias for length.

squaredLength

readonly

number

The squared length of the vector.

squaredMagnitude

readonly

number

The squared magnitude of the vector. Alias for squaredLength.

x

number

The x-component of the vector.

y

number

The y-component of the vector.

z

number

The z-component of the vector.

Methods

Method

Modifiers

Description

add(vector3)

Adds a vector to the current vector.

ceil()

Rounds each component of the vector up to the nearest integer.

clone()

Returns a new vector with the same components as the current vector.

copy(vector3)

Copies the components of a vector to the current vector.

create()

static

Creates a new Vector3 instance.

cross(vector3)

Calculates the cross product of the current vector and another vector.

distance(vector3)

Calculates the distance between the current vector and another vector.

divide(vector3)

Divides each component of the current vector by the corresponding component of another vector.

dot(vector3)

Returns the dot product of this vector and another vector.

equals(vector3)

Checks if the current vector is approximately equal to another vector.

exactEquals(vector3)

Checks if the current vector is exactly equal to another vector.

floor()

Rounds each component of the vector down to the nearest integer.

fromVector3Like(vector3Like)

static

Creates a new Vector3 instance from a Vector3Like object.

invert()

Inverts each component of the vector.

lerp(vector3, t)

Linearly interpolates between the current vector and another vector.

max(vector3)

Sets each component of the vector to the maximum of the current vector and another vector.

min(vector3)

Sets each component of the vector to the minimum of the current vector and another vector.

multiply(vector3)

Multiplies each component of the current vector by the corresponding component of another vector.

negate()

Negates each component of the vector.

normalize()

Normalizes the vector.

randomize(scale)

Randomizes the vector.

rotateX(vector3, angle)

Rotates the vector around the x-axis.

rotateY(vector3, angle)

Rotates the vector around the y-axis.

rotateZ(vector3, angle)

Rotates the vector around the z-axis.

round()

Rounds each component of the vector to the nearest integer.

scale(scale)

Scales each component of the vector by a scalar value.

scaleAndAdd(vector3, scale)

Adds 2 vectors together after scaling the provided vector by a scalar value.

subtract(vector3)

Subtracts a vector from the current vector.

toString()

Returns a string representation of the vector in x,y,z format.

transformMatrix3(matrix3)

Transforms the vector by a matrix3.

transformMatrix4(matrix4)

Transforms the vector by a matrix4.

transformQuaternion(quaternion)

Transforms the vector by a quaternion.

zero()

Sets each component of the vector to zero.