Constructor
new Vector3(xopt, yopt, zopt)
Create a 3D vector
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
x | number | <optional> | 0 | |
y | number | <optional> | 0 | |
z | number | <optional> | 0 |
- Source
const a = vec3(1, 2, 3);
const b = a.add(vec3(0, 1, 0)).normalize();Members
x
Properties| Type | Description |
|---|---|
| number | X axis location |
- Source
y
Properties| Type | Description |
|---|---|
| number | Y axis location |
- Source
z
Properties| Type | Description |
|---|---|
| number | Z axis location |
- Source
Methods
abs() → {Vector3}
Returns a new vector with the absolute value of each component
- Source
- Type:
- Vector3
add(v) → {Vector3}
Returns a copy of this vector plus the vector passed in
| Name | Type | Description |
|---|---|---|
v | Vector3 |
- Source
- Type:
- Vector3
clampLength(lengthopt) → {Vector3}
Returns a new vector clamped to the length passed in
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
length | number | <optional> | 1 |
- Source
- Type:
- Vector3
copy() → {Vector3}
Returns a new vector that is a copy of this
- Source
- Type:
- Vector3
cross(v) → {Vector3}
Returns a vector at right angles to both this and the one passed in
| Name | Type | Description |
|---|---|---|
v | Vector3 |
- Source
- Type:
- Vector3
distance(v) → {number}
Returns the distance from this vector to the vector passed in
| Name | Type | Description |
|---|---|---|
v | Vector3 |
- Source
- Type:
- number
distanceSquared(v) → {number}
Returns the distance squared from this vector to the vector passed in
| Name | Type | Description |
|---|---|---|
v | Vector3 |
- Source
- Type:
- number
divide(v) → {Vector3}
Returns a copy of this vector divided by the vector passed in
| Name | Type | Description |
|---|---|---|
v | Vector3 |
- Source
- Type:
- Vector3
dot(v) → {number}
Returns the dot product of this vector and the vector passed in
| Name | Type | Description |
|---|---|---|
v | Vector3 |
- Source
- Type:
- number
floor() → {Vector3}
Returns a new vector with each component floored
- Source
- Type:
- Vector3
isValid() → {boolean}
Checks if this is a valid vector
- Source
- Type:
- boolean
length() → {number}
Returns the length of this vector
- Source
- Type:
- number
lengthSquared() → {number}
Returns the length of this vector squared
- Source
- Type:
- number
lerp(v, percent) → {Vector3}
Returns a new vector interpolated between this and the vector passed in, percent is clamped to 0-1
| Name | Type | Description |
|---|---|---|
v | Vector3 | |
percent | number |
- Source
- Type:
- Vector3
multiply(v) → {Vector3}
Returns a copy of this vector times the vector passed in
| Name | Type | Description |
|---|---|---|
v | Vector3 |
- Source
- Type:
- Vector3
normalize(lengthopt) → {Vector3}
Returns a new vector in the same direction with the length passed in, zero stays zero
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
length | number | <optional> | 1 |
- Source
- Type:
- Vector3
reflect(normal, restitutionopt) → {Vector3}
Returns a copy of this vector reflected by a surface normal
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
normal | Vector3 | Surface normal, should be normalized | ||
restitution | number | <optional> | 1 | How much to bounce, 1 is a perfect bounce, 0 slides along the surface |
- Source
- Type:
- Vector3
rotate(axis, angle) → {Vector3}
Returns a new vector turned around an axis, counter clockwise when the axis points at you
| Name | Type | Description |
|---|---|---|
axis | Vector3 | Unit length |
angle | number | Radians |
- Source
- Type:
- Vector3
rotateX(angle) → {Vector3}
Returns a new vector turned around the X axis, the way a positive pitch in rotation3D turns things
| Name | Type | Description |
|---|---|---|
angle | number | Radians |
- Source
- Type:
- Vector3
rotateY(angle) → {Vector3}
Returns a new vector turned around the Y axis, the way a positive yaw in rotation3D turns things
| Name | Type | Description |
|---|---|---|
angle | number | Radians |
- Source
- Type:
- Vector3
rotateZ(angle) → {Vector3}
Returns a new vector turned around the Z axis, the way a positive roll in rotation3D turns things
| Name | Type | Description |
|---|---|---|
angle | number | Radians |
- Source
- Type:
- Vector3
round() → {Vector3}
Returns a new vector with each component rounded
- Source
- Type:
- Vector3
scale(s) → {Vector3}
Returns a copy of this vector scaled by the number passed in
| Name | Type | Description |
|---|---|---|
s | number |
- Source
- Type:
- Vector3
set(xopt, yopt, zopt) → {Vector3}
Sets values of this vector and returns self
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
x | number | <optional> | 0 | |
y | number | <optional> | 0 | |
z | number | <optional> | 0 |
- Source
- Type:
- Vector3
setFrom(v) → {Vector3}
Copies the values of another vector into this one and returns self
| Name | Type | Description |
|---|---|---|
v | Vector3 |
- Source
- Type:
- Vector3
snap(grid) → {Vector3}
Returns a new vector snapped down to a grid, grid is the number of steps per unit like Vector2.snap
| Name | Type | Description |
|---|---|---|
grid | number | Snap steps per unit, 2 snaps to halves |
- Source
- Type:
- Vector3
subtract(v) → {Vector3}
Returns a copy of this vector minus the vector passed in
| Name | Type | Description |
|---|---|---|
v | Vector3 |
- Source
- Type:
- Vector3
toString(digitsopt) → {string}
Returns a string representation of this vector for debugging
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
digits | number | <optional> | 3 | Number of digits to display |
- Source
- Type:
- string
transform(matrix) → {Vector3}
Returns this point transformed by a matrix, translation included
| Name | Type | Description |
|---|---|---|
matrix | Matrix4 |
- Source
- Type:
- Vector3
transformDirection(matrix) → {Vector3}
Returns this direction transformed by a matrix, rotation and scale only
| Name | Type | Description |
|---|---|---|
matrix | Matrix4 |
- Source
- Type:
- Vector3