Constructor
new Vector4(x, y, z, w)
Creates a new vector.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x |
Number | 0 | The x component. The default is 0. |
y |
Number | 0 | The y component. The default is 0. |
z |
Number | 0 | The z component. The default is 0. |
w |
Number | 1 | The w component. The default is 1. |
- Source:
Members
(static) one
A Vector4 with its x, y, z and w components equal to zero.
- Source:
(static) unitW
A unit Vector4 along the w axis.
- Source:
(static) unitX
A unit Vector4 along the x axis.
- Source:
(static) unitY
A unit Vector4 along the y axis.
- Source:
(static) unitZ
A unit Vector4 along the z axis.
- Source:
(static) zero
A Vector4 with its x, y, z and w components equal to zero.
- Source:
Methods
add(vector) → {Vector4}
Adds the components of another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector4 | The vector to add. |
- Source:
Returns:
The vector.
- Type
- Vector4
addScalar(s) → {Vector4}
Adds a scalar to the x, y, z and w components of the vector.
Parameters:
Name | Type | Description |
---|---|---|
s |
Number | The scalar to add. |
- Source:
Returns:
The vector.
- Type
- Vector4
addValues(x, y, z, w) → {Vector4}
Adds a value to each component of the vector.
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | The value to add to the x component. |
y |
Number | The value to add to the y component. |
z |
Number | The value to add to the z component. |
w |
Number | The value to add to the w component. |
- Source:
Returns:
The vector.
- Type
- Vector4
addVectors(u, v) → {Vector4}
Sets the vector to the addition of two vectors.
Parameters:
Name | Type | Description |
---|---|---|
u |
Vector4 | The first vector. |
v |
Vector4 | The second vector. |
- Source:
Returns:
The vector.
- Type
- Vector4
clone() → {Vector4}
Creates a clone of the vector.
- Source:
Returns:
The cloned vector.
- Type
- Vector4
copy(vector) → {Vector4}
Copies the components of another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector4 | The vector to copy. |
- Source:
Returns:
The vector.
- Type
- Vector4
distanceTo(vector) → {Number}
Calculates the distance to another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector4 | The vector to calculate the distance to. |
- Source:
Returns:
The distance.
- Type
- Number
distanceToSquared(vector) → {Number}
Calculates the squared distance to another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector4 | The vector to calculate the squared distance to. |
- Source:
Returns:
The squared distance.
- Type
- Number
divideScalar(s) → {Vector4}
Divides the components of the vector by a scalar.
Parameters:
Name | Type | Description |
---|---|---|
s |
Number | The scalar to divide. |
- Source:
Returns:
The vector.
- Type
- Vector4
dot(vector) → {Number}
Calculates the dot product with another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector4 | The vector to calculate the dot product with. |
- Source:
Returns:
The dot product.
- Type
- Number
equals(vector) → {Boolean}
Compares if the components of the vector are equal to the components of another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector4 | The vector to compare the components to. |
- Source:
Returns:
A value indicating whether all the components are equal.
- Type
- Boolean
length() → {Number}
Calculates the length of the vector.
- Source:
Returns:
The length.
- Type
- Number
lengthSquared() → {Number}
Calculates the squared length of the vector.
- Source:
Returns:
The squared length.
- Type
- Number
lerpVectors(u, v, t) → {Vector4}
Sets the vector to the interpolation of two other vectors.
Parameters:
Name | Type | Description |
---|---|---|
u |
Vector4 | The first vector of the interpolation. |
v |
Vector4 | The second vector of the interpolation. |
t |
Number | The interpolation value. |
- Source:
Returns:
The vector.
- Type
- Vector4
multiplyScalar(s) → {Vector4}
Multiplies the components of the vector by a scalar.
Parameters:
Name | Type | Description |
---|---|---|
s |
Number | The scalar to multiply. |
- Source:
Returns:
The vector.
- Type
- Vector4
negate() → {Vector4}
Negates the components of the vector.
- Source:
Returns:
The vector.
- Type
- Vector4
negateVector(vector) → {Vector4}
Sets the components to the negation of another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector4 | The vector to negate. |
- Source:
Returns:
The vector.
- Type
- Vector4
normalize() → {Vector4}
Normalizes the vector.
When the vector length is 0, it does nothing.
- Source:
Returns:
The vector.
- Type
- Vector4
set(x, y, z, w) → {Vector4}
Sets the x, y, z and w components of the vector.
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | The x component. |
y |
Number | The y component. |
z |
Number | The z component. |
w |
Number | The w component. |
- Source:
Returns:
The vector.
- Type
- Vector4
setW(value) → {Vector4}
Sets the w component of the vector.
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | The w component. |
- Source:
Returns:
The vector.
- Type
- Vector4
setX(value) → {Vector4}
Sets the x component of the vector.
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | The x component. |
- Source:
Returns:
The vector.
- Type
- Vector4
setY(value) → {Vector4}
Sets the y component of the vector.
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | The y component. |
- Source:
Returns:
The vector.
- Type
- Vector4
setZ(value) → {Vector4}
Sets the z component of the vector.
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | The z component. |
- Source:
Returns:
The vector.
- Type
- Vector4
subtract(vector) → {Vector4}
Subtracts the components of another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector4 | The vector to subtract. |
- Source:
Returns:
The vector.
- Type
- Vector4
subtractScalar(s) → {Vector4}
Subtracts a scalar from the x, y, z and w components of the vector.
Parameters:
Name | Type | Description |
---|---|---|
s |
Number | The scalar to subtract. |
- Source:
Returns:
The vector.
- Type
- Vector4
subtractValues(x, y, z, w) → {Vector4}
Subtracts a value from each component of the vector.
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | The value to subtract from the x component. |
y |
Number | The value to subtract from the y component. |
z |
Number | The value to subtract from the z component. |
w |
Number | The value to subtract from the w component. |
- Source:
Returns:
The vector.
- Type
- Vector4
subtractVectors(u, v) → {Vector4}
Sets the vector to the difference of two vectors.
Parameters:
Name | Type | Description |
---|---|---|
u |
Vector4 | The first vector. |
v |
Vector4 | The second vector. |
- Source:
Returns:
The vector.
- Type
- Vector4
transform(matrix4) → {Vector4}
Transforms the vector by applying a Matrix4 to it.
Parameters:
Name | Type | Description |
---|---|---|
matrix4 |
Matrix4 | The transform matrix. |
- Source:
Returns:
The vector.
- Type
- Vector4
transformVector(vector, matrix3) → {Vector4}
Sets the vector to the components of another vector transformed by a matrix.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector4 | The vector to transform. |
matrix3 |
Matrix4 | The transform matrix. |
- Source:
Returns:
The vector.
- Type
- Vector4