vec4
ClassA four dimensional vector.
- Available on all platforms
A four dimensional vector. Vectors can only store finite numbers in the range Number.MIN_VALUE to Number.MAX_VALUE.
Index
Properties
Methods
- add
- addInPlace
- angleTo
- clampLength
- clampLengthInPlace
- clone
- copyFrom
- distance
- distanceSquared
- div
- divInPlace
- dot
- equal
- fill
- lerp
- lerpInPlace
- max
- min
- moveTowards
- moveTowardsInPlace
- mult
- multInPlace
- normalize
- normalizeInPlace
- one
- project
- projectInPlace
- projectOnPlane
- projectOnPlaneInPlace
- reflect
- reflectInPlace
- scale
- scaleInPlace
- setRGBA
- setXYZW
- sub
- subInPlace
- toString
- uniformScale
- uniformScaleInPlace
- zero
Example
// Lightens and darkens a color with vec4 methods
//@input Asset.Material material
//@input vec4 myColor = {1,0,0,1} {"widget":"color"}
//@input float value
script.material.mainColor = script.myColor.uniformScale(script.value);
Constructors
Constructor
new vec4(
x,y,z,w):vec4
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
z | number |
w | number |
Returns
vec4
Properties
a
a:
number
Alternate name for the w component.
b
b:
number
Alternate name for the z component.
g
g:
number
Alternate name for the y component.
length
length:
number
Returns the length of the vector.
lengthSquared
lengthSquared:
number
Returns the squared length of the vector.
r
r:
number
Alternate name for the x component.
w
w:
number
w component of the vec4.
x
x:
number
x component of the vec4.
y
y:
number
y component of the vec4.
z
z:
number
z component of the vec4.
Methods
add()
add(
vec):vec4
Returns the vector plus vec.
Parameters
| Parameter | Type |
|---|---|
vec | vec4 |
Returns
vec4
addInPlace()
addInPlace(
vec):void
Adds vec to this vector in place.
Parameters
| Parameter | Type |
|---|---|
vec | vec4 |
Returns
void
angleTo()
angleTo(
vec):number
Returns the angle between the vector and vec.
Parameters
| Parameter | Type |
|---|---|
vec | vec4 |
Returns
number
clampLength()
clampLength(
length):vec4
Returns a copy of the vector with its length clamped to length.
Parameters
| Parameter | Type |
|---|---|
length | number |
Returns
vec4
clampLengthInPlace()
clampLengthInPlace(
length):void
Clamps this vector's length to length in place.
Parameters
| Parameter | Type |
|---|---|
length | number |
Returns
void
clone()
clone():
vec4
Returns a copy of this vector.
Returns
vec4
copyFrom()
copyFrom(
source):void
Copies matching components from the source vector, leaving other destination components untouched. For example, copying a vec3 into a vec4 will update x, y, and z but leave w unchanged.
Parameters
Returns
void
distance()
distance(
vec):number
Returns the distance between the vector and the vector vec.
Parameters
| Parameter | Type |
|---|---|
vec | vec4 |
Returns
number
distanceSquared()
distanceSquared(
vec):number
Like distance(), but returns the squared distance between vectors.
Parameters
| Parameter | Type |
|---|---|
vec | vec4 |
Returns
number
div()
div(
vec):vec4
Returns the division of the vector by the vector vec.
Parameters
| Parameter | Type |
|---|---|
vec | vec4 |
Returns
vec4
divInPlace()
divInPlace(
vec):void
Divides this vector by vec component-wise in place.
Parameters
| Parameter | Type |
|---|---|
vec | vec4 |
Returns
void
dot()
dot(
vec):number
Returns the dot product of the vector and vec.
Parameters
| Parameter | Type |
|---|---|
vec | vec4 |
Returns
number
equal()
equal(
vec):boolean
Returns whether this is equal to vec.
Parameters
| Parameter | Type |
|---|---|
vec | vec4 |
Returns
boolean
fill()
fill(
scalar):void
Sets the x, y, z, and w components of this vector to scalar.
Parameters
| Parameter | Type |
|---|---|
scalar | number |
Returns
void
lerp()
staticlerp(from,to,t):vec4
Linearly interpolates between the two vectors from and to by the factor t.
Parameters
| Parameter | Type |
|---|---|
from | vec4 |
to | vec4 |
t | number |
Returns
vec4
lerpInPlace()
lerpInPlace(
target,t):void
Linearly interpolates this vector towards target by factor t in place.
Parameters
| Parameter | Type |
|---|---|
target | vec4 |
t | number |
Returns
void
max()
staticmax(a,b):vec4
Returns a new vector containing the largest value of each component in the two vectors.
Parameters
| Parameter | Type |
|---|---|
a | vec4 |
b | vec4 |
Returns
vec4
min()
staticmin(a,b):vec4
Returns a new vector containing the smallest value of each component in the two vectors.
Parameters
| Parameter | Type |
|---|---|
a | vec4 |
b | vec4 |
Returns
vec4
moveTowards()
moveTowards(
target,step):vec4
Returns a copy of the vector moved towards the point point by the amount magnitude.
Parameters
| Parameter | Type |
|---|---|
target | vec4 |
step | number |
Returns
vec4
moveTowardsInPlace()
moveTowardsInPlace(
point,magnitude):void
Moves this vector towards point by magnitude in place.
Parameters
| Parameter | Type |
|---|---|
point | vec4 |
magnitude | number |
Returns
void
mult()
mult(
vec):vec4
Returns the component-wise multiplication product of the vector and vec.
Parameters
| Parameter | Type |
|---|---|
vec | vec4 |
Returns
vec4
multInPlace()
multInPlace(
vec):void
Multiplies this vector by vec component-wise in place.
Parameters
| Parameter | Type |
|---|---|
vec | vec4 |
Returns
void
normalize()
normalize():
vec4
Returns a copy of the vector with its length scaled to 1.
Returns
vec4
normalizeInPlace()
normalizeInPlace():
void
Scales this vector's length to 1 in place.
Returns
void
one()
staticone():vec4
Returns the vector (1, 1, 1, 1).
Returns
vec4
project()
project(
onto):vec4
Returns a copy of the vector projected onto the vector onto.
Parameters
| Parameter | Type |
|---|---|
onto | vec4 |
Returns
vec4
projectInPlace()
projectInPlace(
onto):void
Projects this vector onto the vector onto in place.
Parameters
| Parameter | Type |
|---|---|
onto | vec4 |
Returns
void
projectOnPlane()
projectOnPlane(
planeNormal):vec4
Projects the vector onto the plane defined by planeNormal.
Parameters
| Parameter | Type |
|---|---|
planeNormal | vec4 |
Returns
vec4
projectOnPlaneInPlace()
projectOnPlaneInPlace(
planeNormal):void
Projects this vector onto the plane defined by planeNormal in place.
Parameters
| Parameter | Type |
|---|---|
planeNormal | vec4 |
Returns
void
reflect()
reflect(
planeNormal):vec4
Returns a copy of the vector reflected across the plane defined by planeNormal.
Parameters
| Parameter | Type |
|---|---|
planeNormal | vec4 |
Returns
vec4
reflectInPlace()
reflectInPlace(
planeNormal):void
Reflects this vector across the plane defined by planeNormal in place.
Parameters
| Parameter | Type |
|---|---|
planeNormal | vec4 |
Returns
void
scale()
scale(
vec):vec4
Returns the component-wise multiplication product of the vector and vec.
Parameters
| Parameter | Type |
|---|---|
vec | vec4 |
Returns
vec4
scaleInPlace()
scaleInPlace(
vec):void
Multiplies this vector by vec component-wise in place.
Parameters
| Parameter | Type |
|---|---|
vec | vec4 |
Returns
void
setRGBA()
setRGBA(
r?,g?,b?,a?):void
Alternative to setXYZW. Sets the x, y, z and w components of this vector. Omit parameters or pass null or undefined to leave a component unchanged.
Parameters
| Parameter | Type |
|---|---|
r? | number |
g? | number |
b? | number |
a? | number |
Returns
void
setXYZW()
setXYZW(
x?,y?,z?,w?):void
Sets the x, y, z, and w components of this vector. Omit parameters or pass null or undefined to leave a component unchanged.
Parameters
| Parameter | Type |
|---|---|
x? | number |
y? | number |
z? | number |
w? | number |
Returns
void
sub()
sub(
vec):vec4
Returns the vector minus vec.
Parameters
| Parameter | Type |
|---|---|
vec | vec4 |
Returns
vec4
subInPlace()
subInPlace(
vec):void
Subtracts vec from this vector in place.
Parameters
| Parameter | Type |
|---|---|
vec | vec4 |
Returns
void
toString()
toString():
string
Returns a string representation of the vector.
Returns
string
uniformScale()
uniformScale(
scale):vec4
Multiplies the components of this vector by scale.
Parameters
| Parameter | Type |
|---|---|
scale | number |
Returns
vec4
uniformScaleInPlace()
uniformScaleInPlace(
scale):void
Multiplies the components of this vector by scale in place.
Parameters
| Parameter | Type |
|---|---|
scale | number |
Returns
void
zero()
staticzero():vec4
Returns the vector (0, 0, 0, 0).
Returns
vec4