Vector3

Objects

Description

class Vector3

Constructor

new Vector3(x, y, z)

Creates a new Vector3 object from the passed x, y, z (floats) coordinates.

A Vector3 is the main object used in 3D geometry.

It can represent etiher the coordinates of a point the space, either a direction.

Parameters

Name Type Description
x number
y number
z number

Members

x : number

y : number

z : number

isNonUniform : boolean

Return true is the vector is non uniform meaning x, y or z are not all the same.

Methods

toString() string

Returns a string with the Vector3 coordinates.

getClassName() string

Returns the string "Vector3"

getHashCode() number

Returns the Vector hash code.

asArray() number[]

Returns a new array with three elements : the coordinates the Vector3.

toArray(array, index) Vector3

Populates the passed array or Float32Array from the passed index with the successive coordinates of the Vector3.

Returns the Vector3.

Parameters

Name Type Description
array FloatArray
optional index number

toQuaternion() Quaternion

Returns a new Quaternion object, computed from the Vector3 coordinates.

addInPlace(otherVector) Vector3

Adds the passed vector to the current Vector3.

Returns the updated Vector3.

Parameters

Name Type Description
otherVector Vector3

add(otherVector) Vector3

Returns a new Vector3, result of the addition the current Vector3 and the passed vector.

Parameters

Name Type Description
otherVector Vector3

addToRef(otherVector, result) Vector3

Adds the current Vector3 to the passed one and stores the result in the vector "result".

Returns the current Vector3.

Parameters

Name Type Description
otherVector Vector3
result Vector3

subtractInPlace(otherVector) Vector3

Subtract the passed vector from the current Vector3.

Returns the updated Vector3.

Parameters

Name Type Description
otherVector Vector3

subtract(otherVector) Vector3

Returns a new Vector3, result of the subtraction of the passed vector from the current Vector3.

Parameters

Name Type Description
otherVector Vector3

subtractToRef(otherVector, result) Vector3

Subtracts the passed vector from the current Vector3 and stores the result in the vector "result".

Returns the current Vector3.

Parameters

Name Type Description
otherVector Vector3
result Vector3

subtractFromFloats(x, y, z) Vector3

Returns a new Vector3 set with the subtraction of the passed floats from the current Vector3 coordinates.

Parameters

Name Type Description
x number
y number
z number

subtractFromFloatsToRef(x, y, z, result) Vector3

Subtracts the passed floats from the current Vector3 coordinates and set the passed vector "result" with this result.

Returns the current Vector3.

Parameters

Name Type Description
x number
y number
z number

negate() Vector3

Returns a new Vector3 set with the current Vector3 negated coordinates.

scaleInPlace(scale) Vector3

Multiplies the Vector3 coordinates by the float "scale".

Returns the updated Vector3.

Parameters

Name Type Description
scale number

scale(scale) Vector3

Returns a new Vector3 set with the current Vector3 coordinates multiplied by the float "scale".

Parameters

Name Type Description
scale number

scaleToRef(scale, result) Vector3

Multiplies the current Vector3 coordinates by the float "scale" and stores the result in the passed vector "result" coordinates.

Returns the current Vector3.

Parameters

Name Type Description
scale number
result Vector3

equals(otherVector) boolean

Boolean : True if the current Vector3 and the passed vector coordinates are strictly equal.

Parameters

Name Type Description
otherVector Vector3

equalsWithEpsilon(otherVector, epsilon) boolean

Boolean : True if the current Vector3 and the passed vector coordinates are distant less than epsilon.

Parameters

Name Type Description
otherVector Vector3
optional epsilon number

equalsToFloats(x, y, z) boolean

Boolean : True if the current Vector3 coordinate equal the passed floats.

Parameters

Name Type Description
x number
y number
z number

multiplyInPlace(otherVector) Vector3

Muliplies the current Vector3 coordinates by the passed ones.

Returns the updated Vector3.

Parameters

Name Type Description
otherVector Vector3

multiply(otherVector) Vector3

Returns a new Vector3, result of the multiplication of the current Vector3 by the passed vector.

Parameters

Name Type Description
otherVector Vector3

multiplyToRef(otherVector, result) Vector3

Multiplies the current Vector3 by the passed one and stores the result in the passed vector "result".

Returns the current Vector3.

Parameters

Name Type Description
otherVector Vector3
result Vector3

multiplyByFloats(x, y, z) Vector3

Returns a new Vector3 set witth the result of the mulliplication of the current Vector3 coordinates by the passed floats.

Parameters

Name Type Description
x number
y number
z number

divide(otherVector) Vector3

Returns a new Vector3 set witth the result of the division of the current Vector3 coordinates by the passed ones.

Parameters

Name Type Description
otherVector Vector3

divideToRef(otherVector, result) Vector3

Divides the current Vector3 coordinates by the passed ones and stores the result in the passed vector "result".

Returns the current Vector3.

Parameters

Name Type Description
otherVector Vector3
result Vector3

MinimizeInPlace(other) Vector3

Updates the current Vector3 with the minimal coordinate values between its and the passed vector ones.

Returns the updated Vector3.

Parameters

Name Type Description
other Vector3

MaximizeInPlace(other) Vector3

Updates the current Vector3 with the maximal coordinate values between its and the passed vector ones.

Returns the updated Vector3.

Parameters

Name Type Description
other Vector3

length() number

Returns the length of the Vector3 (float).

lengthSquared() number

Returns the squared length of the Vector3 (float).

normalize() Vector3

Normalize the current Vector3.

Returns the updated Vector3.

/!\ In place operation.

normalizeToNew() Vector3

Normalize the current Vector3 to a new vector.

@returns the new Vector3.

normalizeToRef(reference) Vector3

Normalize the current Vector3 to the reference.

@returns the updated Vector3.

Parameters

Name Type Description
reference Vector3

clone() Vector3

Returns a new Vector3 copied from the current Vector3.

copyFrom(source) Vector3

Copies the passed vector coordinates to the current Vector3 ones.

Returns the updated Vector3.

Parameters

Name Type Description
source Vector3

copyFromFloats(x, y, z) Vector3

Copies the passed floats to the current Vector3 coordinates.

Returns the updated Vector3.

Parameters

Name Type Description
x number
y number
z number

set(x, y, z) Vector3

Copies the passed floats to the current Vector3 coordinates.

Returns the updated Vector3.

Parameters

Name Type Description
x number
y number
z number

static GetClipFactor(vector0, vector1, axis, size) number

*/

Parameters

Name Type Description
vector0 Vector3
vector1 Vector3
axis Vector3

static FromArray(array, offset) Vector3

Returns a new Vector3 set from the index "offset" of the passed array.

Parameters

Name Type Description
array ArrayLike<number>
optional offset number

static FromFloatArray(array, offset) Vector3

Returns a new Vector3 set from the index "offset" of the passed Float32Array.

This function is deprecated. Use FromArray instead.

Parameters

Name Type Description
array Float32Array
optional offset number

static FromArrayToRef(array, offset, result) void

Sets the passed vector "result" with the element values from the index "offset" of the passed array.

Parameters

Name Type Description
array ArrayLike<number>
offset number
result Vector3

static FromFloatArrayToRef(array, offset, result) void

Sets the passed vector "result" with the element values from the index "offset" of the passed Float32Array.

This function is deprecated. Use FromArrayToRef instead.

Parameters

Name Type Description
array Float32Array
offset number
result Vector3

static FromFloatsToRef(x, y, z, result) void

Sets the passed vector "result" with the passed floats.

Parameters

Name Type Description
x number
y number
z number

static Zero() Vector3

Returns a new Vector3 set to (0.0, 0.0, 0.0).

static One() Vector3

Returns a new Vector3 set to (1.0, 1.0, 1.0).

static Up() Vector3

Returns a new Vector3 set to (0.0, 1.0, 0.0)

static Forward() Vector3

Returns a new Vector3 set to (0.0, 0.0, 1.0)

static Right() Vector3

Returns a new Vector3 set to (1.0, 0.0, 0.0)

static Left() Vector3

Returns a new Vector3 set to (-1.0, 0.0, 0.0)

static TransformCoordinates(vector, transformation) Vector3

Returns a new Vector3 set with the result of the transformation by the passed matrix of the passed vector.

This method computes tranformed coordinates only, not transformed direction vectors.

Parameters

Name Type Description
vector Vector3
transformation Matrix

static TransformCoordinatesToRef(vector, transformation, result) void

Sets the passed vector "result" coordinates with the result of the transformation by the passed matrix of the passed vector.

This method computes tranformed coordinates only, not transformed direction vectors.

Parameters

Name Type Description
vector Vector3
transformation Matrix
result Vector3

static TransformCoordinatesFromFloatsToRef(x, y, z, transformation, result) void

Sets the passed vector "result" coordinates with the result of the transformation by the passed matrix of the passed floats (x, y, z).

This method computes tranformed coordinates only, not transformed direction vectors.

Parameters

Name Type Description
x number
y number
z number
transformation Matrix

static TransformNormal(vector, transformation) Vector3

Returns a new Vector3 set with the result of the normal transformation by the passed matrix of the passed vector.

This methods computes transformed normalized direction vectors only.

Parameters

Name Type Description
vector Vector3
transformation Matrix

static TransformNormalToRef(vector, transformation, result) void

Sets the passed vector "result" with the result of the normal transformation by the passed matrix of the passed vector.

This methods computes transformed normalized direction vectors only.

Parameters

Name Type Description
vector Vector3
transformation Matrix
result Vector3

static TransformNormalFromFloatsToRef(x, y, z, transformation, result) void

Sets the passed vector "result" with the result of the normal transformation by the passed matrix of the passed floats (x, y, z).

This methods computes transformed normalized direction vectors only.

Parameters

Name Type Description
x number
y number
z number
transformation Matrix

static CatmullRom(value1, value2, value3, value4, amount) Vector3

Returns a new Vector3 located for "amount" on the CatmullRom interpolation spline defined by the vectors "value1", "value2", "value3", "value4".

Parameters

Name Type Description
value1 Vector3
value2 Vector3
value3 Vector3
value4 Vector3

static Clamp(value, min, max) Vector3

Returns a new Vector3 set with the coordinates of "value", if the vector "value" is in the cube defined by the vectors "min" and "max".

If a coordinate value of "value" is lower than one of the "min" coordinate, then this "value" coordinate is set with the "min" one.

If a coordinate value of "value" is greater than one of the "max" coordinate, then this "value" coordinate is set with the "max" one.

Parameters

Name Type Description
value Vector3
min Vector3
max Vector3

static Hermite(value1, tangent1, value2, tangent2, amount) Vector3

Returns a new Vector3 located for "amount" (float) on the Hermite interpolation spline defined by the vectors "value1", "tangent1", "value2", "tangent2".

Parameters

Name Type Description
value1 Vector3
tangent1 Vector3
value2 Vector3
tangent2 Vector3

static Lerp(start, end, amount) Vector3

Returns a new Vector3 located for "amount" (float) on the linear interpolation between the vectors "start" and "end".

Parameters

Name Type Description
start Vector3
end Vector3
amount number

static LerpToRef(start, end, amount, result) void

Sets the passed vector "result" with the result of the linear interpolation from the vector "start" for "amount" to the vector "end".

Parameters

Name Type Description
start Vector3
end Vector3
amount number

static Dot(left, right) number

Returns the dot product (float) between the vectors "left" and "right".

Parameters

Name Type Description
left Vector3
right Vector3

static Cross(left, right) Vector3

Returns a new Vector3 as the cross product of the vectors "left" and "right".

The cross product is then orthogonal to both "left" and "right".

Parameters

Name Type Description
left Vector3
right Vector3

static CrossToRef(left, right, result) void

Sets the passed vector "result" with the cross product of "left" and "right".

The cross product is then orthogonal to both "left" and "right".

Parameters

Name Type Description
left Vector3
right Vector3
result Vector3

static Normalize(vector) Vector3

Returns a new Vector3 as the normalization of the passed vector.

Parameters

Name Type Description
vector Vector3

static NormalizeToRef(vector, result) void

Sets the passed vector "result" with the normalization of the passed first vector.

Parameters

Name Type Description
vector Vector3
result Vector3

static Project(vector, world, transform, viewport) Vector3

Parameters

Name Type Description
vector Vector3
world Matrix
transform Matrix

static UnprojectFromTransform(source, viewportWidth, viewportHeight, world, transform) Vector3

Parameters

Name Type Description
source Vector3
viewportWidth number
viewportHeight number
world Matrix

static Unproject(source, viewportWidth, viewportHeight, world, view, projection) Vector3

Parameters

Name Type Description
source Vector3
viewportWidth number
viewportHeight number
world Matrix
view Matrix

static UnprojectToRef(source, viewportWidth, viewportHeight, world, view, projection, result) void

Parameters

Name Type Description
source Vector3
viewportWidth number
viewportHeight number
world Matrix
view Matrix
projection Matrix

static UnprojectFloatsToRef(sourceX, sourceY, sourceZ, viewportWidth, viewportHeight, world, view, projection, result) void

Parameters

Name Type Description
sourceX float
sourceY float
sourceZ float
viewportWidth number
viewportHeight number
world Matrix
view Matrix
projection Matrix

static Minimize(left, right) Vector3

Parameters

Name Type Description
left Vector3
right Vector3

static Maximize(left, right) Vector3

Parameters

Name Type Description
left Vector3
right Vector3

static Distance(value1, value2) number

Returns the distance (float) between the vectors "value1" and "value2".

Parameters

Name Type Description
value1 Vector3
value2 Vector3

static DistanceSquared(value1, value2) number

Returns the squared distance (float) between the vectors "value1" and "value2".

Parameters

Name Type Description
value1 Vector3
value2 Vector3

static Center(value1, value2) Vector3

Returns a new Vector3 located at the center between "value1" and "value2".

Parameters

Name Type Description
value1 Vector3
value2 Vector3

static RotationFromAxis(axis1, axis2, axis3) Vector3

Given three orthogonal normalized left-handed oriented Vector3 axis in space (target system),

RotationFromAxis() returns the rotation Euler angles (ex : rotation.x, rotation.y, rotation.z) to apply

to something in order to rotate it from its local system to the given target system.

Note : axis1, axis2 and axis3 are normalized during this operation.

Returns a new Vector3.

Parameters

Name Type Description
axis1 Vector3
axis2 Vector3
axis3 Vector3

static RotationFromAxisToRef(axis1, axis2, axis3, ref) void

The same than RotationFromAxis but updates the passed ref Vector3 parameter instead of returning a new Vector3.

Parameters

Name Type Description
axis1 Vector3
axis2 Vector3
axis3 Vector3