Class representing a 4D vector. A 4D vector is an ordered quadruplet of numbers (labeled x, y, z, and w), which can be used to represent a number of things, such as:
(0, 0, 0, 0) to (x, y, z, w) and the direction is also measured from (0, 0, 0, 0) towards (x, y, z, w).
Iterating through a Vector4 instance will yield its components (x, y, z, w) in the corresponding order.
const a = new v3d.Vector4(0, 1, 0, 0);
// no arguments; will be initialised to (0, 0, 0, 1)
const b = new v3d.Vector4();
const d = a.dot(b);
0.0.0.1.Creates a new Vector4.
Read-only flag to check if a given object is of type Vector4.
Alias for z.
Alias for w.
Adds v to this vector.
Adds the scalar value s to this vector's x, y, z and w values.
Adds the multiple of v and s to this vector.
Multiplies this vector by 4x4 matrix m.
The x, y, z and w components of this vector are rounded up to the nearest integer value.
If this vector's x, y, z or w value is greater than the max vector's x, y, z or w value, it is replaced by the corresponding value.
If this vector's x, y, z or w value is less than the min vector's x, y, z or w value, it is replaced by the corresponding value.
If this vector's length is greater than the max value, it is replaced by the max value. If this vector's length is less than the min value, it is replaced by the min value.
If this vector's x, y, z or w values are greater than the max value, they are replaced by the max value. If this vector's x, y, z or w values are less than the min value, they are replaced by the min value.
Returns a new Vector4 with the same x, y, z and w values as this one.
Copies the values of the passed Vector4's x, y, z and w properties to this Vector4.
Divides this vector by scalar s.
Calculates the dot product of this vector and v.
Returns true if the components of this vector and v are strictly equal; false otherwise.
The components of this vector are rounded down to the nearest integer value.
Sets this vector's x value to be array[offset], y value to be array[offset + 1], z value to be array[offset + 2], and w value to be array[offset + 3].
Sets this vector's x, y, z and w values from the attribute.
index — 0, 1, 2, or 3.
If index equals 0 returns the x value.
If index equals 1 returns the y value.
If index equals 2 returns the z value.
If index equals 3 returns the w value.
Computes the Euclidean length (straight-line length) from (0, 0, 0, 0) to (x, y, z, w).
Computes the Manhattan length of this vector.
Computes the square of the Euclidean length (straight-line length) from (0, 0, 0, 0) to (x, y, z, w). If you are comparing the lengths of vectors, you should compare the length squared instead as it is slightly more efficient to calculate.
[0, 1].
Linearly interpolates between this vector and v, where alpha is the percent distance along the line. In particular, if alpha = 0 the result will be equal to the current vector, and if alpha = 1 the results will be equal to v.
[0, 1].
Sets this vector to be the vector linearly interpolated between v1 and v2 where alpha is the percent distance along the line connecting the two vectors. In particular, if alpha = 0 the result will be equal to v1, and if alpha = 1 the results will be equal to v2.
Inverts this vector — i.e. sets x = -x, y = -y, z = -z, and w = -w.
Converts this vector to a unit vector — that is, sets it equal to a vector with the same direction as this one, but length 1.
If this vector's x, y, z or w value is less than v's x, y, z or w value, replace that value with the corresponding max value.
If this vector's x, y, z or w value is greater than v's x, y, z or w value, replace that value with the corresponding min value.
Multiplies this vector by v.
Multiplies this vector by scalar s.
The components of this vector are rounded to the nearest integer value.
The components of this vector are rounded towards zero (up if negative, down if positive) to an integer value.
Sets the x, y, z and w components of this vector.
q — a normalized Quaternion.
Sets the x, y and z components of this vector to the quaternion's axis and w to the angle.
m — a Matrix4 of which the upper left 3x3 matrix is a pure rotation matrix.
Sets the x, y and z to the axis of rotation and w to the angle.
If index equals 0 set x to value.
If index equals 1 set y to value.
If index equals 2 set z to value.
If index equals 3 set w to value.
Sets this vector to a vector with the same direction as this one, but length l.
Sets the x, y, z and w values of this vector both equal to scalar.
Replaces this vector's x value with x.
Replaces this vector's y value with y.
Replaces this vector's z value with z.
Replaces this vector's w value with w.
Subtracts v from this vector.
Subtracts s from this vector's x, y, z and w components.
Returns an array [x, y, z, w], or copies x, y, z and w into the provided array.
Sets each component of this vector to a pseudo-random value between 0 and 1, excluding 1.
For more info on how to obtain the source code of this module see this page.