Constructor
new Vector4(xopt, yopt, zopt, wopt)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x | Number | <optional> | 0 | the x value of this vector. |
y | Number | <optional> | 0 | the y value of this vector. |
z | Number | <optional> | 0 | the z value of this vector. |
w | Number | <optional> | 1 | the w value of this vector. |
Methods
add(v) → {t3d.Vector4}
Adds v to this vector.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- t3d.
Vector4
applyMatrix4(m) → {t3d.Vector4}
Multiplies this vector by 4 x 4 m.
Parameters:
Name | Type | Description |
---|---|---|
m | t3d. |
Returns:
- Type:
- t3d.
Vector4
clone() → {t3d.Vector4}
Returns a new Vector4 with the same x, y, z and w values as this one.
Returns:
- Type:
- t3d.
Vector4
copy(v) → {t3d.Vector4}
Copies the values of the passed Vector4's x, y, z and w properties to this Vector4.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- t3d.
Vector4
dot(v) → {t3d.Vector4}
Calculates the dot product of this vector and v.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- t3d.
Vector4
equals(v) → {Boolean}
Checks for strict equality of this vector and v.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- Boolean
fromArray(array, offsetopt, denormalizeopt) → {t3d.Vector4}
Sets this vector's x value to be array[ offset + 0 ], y value to be array[ offset + 1 ] z value to be array[ offset + 2 ] and w value to be array[ offset + 3 ].
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
array | Array.<Number> | the source array. | ||
offset | Number | <optional> | 0 | offset into the array. |
denormalize | Boolean | <optional> | false | if true, denormalize the values, and array should be a typed array. |
Returns:
- Type:
- t3d.
Vector4
getLength() → {Number}
Computes the Euclidean length (straight-line length) from (0, 0, 0, 0) to (x, y, z, w).
Returns:
- Type:
- Number
getLengthSquared() → {Number}
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.
Returns:
- Type:
- Number
getManhattanLength() → {Number}
Computes the Manhattan length from (0, 0, 0, 0) to (x, y, z, w).
Returns:
- Type:
- Number
lerpVectors(v1, v2, ratio) → {t3d.Vector4}
Sets this vector to be the vector linearly interpolated between v1 and v2 where ratio is the percent distance along the line connecting the two vectors - ratio = 0 will be v1, and ratio = 1 will be v2.
Parameters:
Name | Type | Description |
---|---|---|
v1 | t3d. | the starting Vector4. |
v2 | t3d. | Vector4 to interpolate towards. |
ratio | Number | interpolation factor, typically in the closed interval [0, 1]. |
Returns:
- Type:
- t3d.
Vector4
multiply(v) → {t3d.Vector4}
Multiplies this vector by v.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- t3d.
Vector4
multiplyScalar(scalar) → {t3d.Vector4}
Multiplies this vector by scalar s.
Parameters:
Name | Type | Description |
---|---|---|
scalar | Number |
Returns:
- Type:
- t3d.
Vector4
normalize() → {t3d.Vector4}
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.
Returns:
- Type:
- t3d.
Vector4
set(x, y, z, w) → {t3d.Vector4}
Sets the x, y, z and w components of this vector.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x | Number | 0 | |
y | Number | 0 | |
z | Number | 0 | |
w | Number | 1 |
Returns:
- Type:
- t3d.
Vector4
subVectors(a, b) → {t3d.Vector4}
Sets this vector to a - b.
Parameters:
Name | Type | Description |
---|---|---|
a | t3d. | |
b | t3d. |
Returns:
- Type:
- t3d.
Vector4
toArray(arrayopt, offsetopt, normalizeopt) → {Array.<Number>}
Returns an array [x, y, z, w], or copies x, y, z and w into the provided array.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
array | Array.<Number> | <optional> | array to store this vector to. If this is not provided, a new array will be created. | |
offset | Number | <optional> | 0 | offset into the array. |
normalize | Boolean | <optional> | false | if true, normalize the values, and array should be a typed array. |
Returns:
- Type:
- Array.<Number>