Class: Vec1

Vec1

A 32-bit float wrapped as a single-element vector. May reflect an ESSL float uniform variable.

new Vec1()

Without parameters, initializes the vector to 0.

Members


storage :Float32Array

1-element typed array for coordinate storage.
Type:
  • Float32Array

x :Number

Alias for storage[0];
Type:
  • Number

Methods


add( [u])

Simulates operator +=. Adds another vector to this vector, overwriting the contents with the result.
Parameters:
Name Type Argument Default Description
u Vec1 | Object | Number <optional>
0 Any object (property x), or a numerical value.
Returns:
this
Type
Vec1

addScaled(dt [, u])

Simulates += dt *. Adds another vector, scaled by `dt`, to this vector, overwriting the contents with the result.
Parameters:
Name Type Argument Default Description
dt Number Scaling factor.
u Vec1 | Object | Number <optional>
0 Any object (property x), or a numerical value.
Returns:
this
Type
Vec1

clamp( [minVal] [, maxVal])

Constrains the value of this vector to lie between two further values, elementwise, overwriting the contents with the result.
Parameters:
Name Type Argument Default Description
minVal Vec1 | Object | Number <optional>
0 Specifies the lower end of the range into which to constrain the elements. If a scalar is given, it applies to all channels.
maxVal Vec1 | Object | Number <optional>
1 Specifies the upper end of the range into which to constrain the elements. If a scalar is given, it applies to all channels.
Returns:
this
Type
Vec1

clone()

Creates a copy.
Returns:
A new instance with identical contents.
Type
Vec1

commit(gl, uniformLocation)

Sets the value of the vector to a WebGL float uniform variable.
Parameters:
Name Type Description
gl WebGLRenderingContext rendering context
uniformLocation WebGLUniformLocation location of the uniform variable in the currently used WebGL program

div( [u])

Simulates operator /=. Divides, elementwise, this vector with another vector, or scalar, overwriting the contents with the result.
Parameters:
Name Type Argument Default Description
u Vec1 | Object | Number <optional>
1 Any object (property x), or a numerical value.
Returns:
this
Type
Vec1

dot( [u])

Computes the dot product with another vector.
Parameters:
Name Type Argument Default Description
u Vec1 | Object | Number <optional>
0 Any object (property x), or a numerical value.
Returns:
Type
Number

lengthOfVec2(b)

Computes the length of a two-element vector, and stores the result.
Parameters:
Name Type Description
b Vec2 The vector whose length must be stored.
Returns:
this

lengthOfVec3(b)

Computes the length of a three-element vector, and stores the result.
Parameters:
Name Type Description
b Vec3 The vector whose length must be stored.
Returns:
this

lengthOfVec4(b)

Computes the length of a four-element vector, and stores the result.
Parameters:
Name Type Description
b Vec4 The vector whose length must be stored.
Returns:
this

minus( [u])

Simulates operator -. Subtracts the parameter vector from this vector, and returns the result in a new instance.
Parameters:
Name Type Argument Default Description
u Vec1 | Object | Number <optional>
0 Any object (property x), or a numerical value.
Returns:
the difference of the two vectors
Type
Vec1

mul( [u])

Simulates operator *=. Multiplies this vector with another vector elementwise, or scalar, overwriting the contents with the result.
Parameters:
Name Type Argument Default Description
u Vec1 | Object | Number <optional>
1 Any object (property x), or a numerical value.
Returns:
this
Type
Vec1

over( [u])

Simulates operator /. Divides, elementwise, this vector with another vector, or scalar, and returns the result in a new instance.
Parameters:
Name Type Argument Default Description
u Vec1 | Object | Number <optional>
1 Any object (property x), or a numerical value.
Returns:
the elementwise product of the two vectors
Type
Vec1

plus( [u])

Simulates operator +. Adds this vector and the parameter vector, and returns the result in a new instance.
Parameters:
Name Type Argument Default Description
u Vec1 | Object | Number <optional>
0 Any object (property x), or a numerical value.
Returns:
the sum of the two vectors
Type
Vec1

set( [u])

Simulates operator =. Sets the coordinates from another vector, or number values. Without parameters, sets (0, 0, 0, 1).
Parameters:
Name Type Argument Default Description
u Vec1 | Object | Number <optional>
0 Any object (property x), or a numerical value.
Returns:
this
Type
Vec1

setClamped(b [, minVal] [, maxVal])

Fast. Constrains a value to lie between two further values, elementwise, storing the result in this vector.
Parameters:
Name Type Argument Default Description
b Vec1 The value to constrain.
minVal Vec1 | Object | Number <optional>
0 Specifies the lower end of the range into which to constrain the elements. If a scalar is given, it applies to all channels.
maxVal Vec1 | Object | Number <optional>
1 Specifies the upper end of the range into which to constrain the elements. If a scalar is given, it applies to all channels.
Returns:
this
Type
Vec1

setDifference(b, c)

Fast. Subtracts the second argument vector from the first one, storing the result in this vector.
Parameters:
Name Type Description
b Vec1 Minuend.
c Vec1 Subtrahend.
Returns:
this
Type
Vec1

setDotProductOfVec2s(b, c)

Computes the dot product of two two-element vectors, and stores the result.
Parameters:
Name Type Description
b Vec3 Operand 1.
c Vec3 Operand 2.
Returns:
this

setDotProductOfVec3s(b, c)

Computes the dot product of two three-element vectors, and stores the result.
Parameters:
Name Type Description
b Vec3 Operand 1.
c Vec3 Operand 2.
Returns:
this

setDotProductOfVec4s(b, c)

Computes the dot product of two three-element vectors, and stores the result.
Parameters:
Name Type Description
b Vec3 Operand 1.
c Vec3 Operand 2.
Returns:
this

setLengthOfVec2(b)

Computes the length of a two-element vector, and stores the result.
Parameters:
Name Type Description
b Vec2 The vector whose length must be stored.
Returns:
this

setLengthOfVec3(b)

Computes the length of a three-element vector, and stores the result.
Parameters:
Name Type Description
b Vec3 The vector whose length must be stored.
Returns:
this

setLengthOfVec4(b)

Computes the length of a four-element vector, and stores the result.
Parameters:
Name Type Description
b Vec4 The vector whose length must be stored.
Returns:
this

setProduct(b, c)

Fast. Multiplies, elementwise, the two argument vectors, storing the result in this vector.
Parameters:
Name Type Description
b Vec1 Factor 1.
c Vec1 Factor 2.
Returns:
this
Type
Vec1

setQuotient(b, c)

Fast. Divides, elementwise, the two argument vectors, storing the result in this vector.
Parameters:
Name Type Description
b Vec1 Dividend.
c Vec1 Divisor.
Returns:
this
Type
Vec1

setRandom( [minVal] [, maxVal])

Fill the vector with random values that to lie between two further values, elementwise.
Parameters:
Name Type Argument Default Description
minVal Vec1 | Object | Number <optional>
0 Specifies the lower end of the random range. If a scalar is given, it applies to all channels.
maxVal Vec1 | Object | Number <optional>
1 Specifies the upper end of the random range. If a scalar is given, it applies to all channels.
Returns:
this
Type
Vec1

setScaled(a, s)

Fast. Scales the vector by a scalar.
Parameters:
Name Type Description
a Vec1 Vector to scale.
s Number Scale factor.
Returns:
this
Type
Vec1

setScaledByInverse(a, s)

Fast. Scales the vector by the reciprocal of scalar.
Parameters:
Name Type Description
a Vec1 Vector to scale.
s Number Scale factor inverse.
Returns:
this
Type
Vec1

setSum(b, c)

Fast. Adds the two argument vectors, storing the result in this vector.
Parameters:
Name Type Description
b Vec1 Term 1.
c Vec1 Term 2.
Returns:
this
Type
Vec1

sub( [u])

Simulates operator -=. Subtracts another vector from this vector, overwriting the contents with the result.
Parameters:
Name Type Argument Default Description
u Vec1 | Object | Number <optional>
0 Any object (property x), or a numerical value.
Returns:
this
Type
Vec1

times( [u])

Simulates operator *. Multiplies this vector with another vector elementwise, or scalar, and returns the result in a new instance.
Parameters:
Name Type Argument Default Description
u Vec1 | Object | Number <optional>
1 Any object (property x), or a numerical value.
Returns:
the elementwise product of the two vectors
Type
Vec1

<static> random( [minVal] [, maxVal])

Return a new Vec1 with random values that to lie between two values, elementwise.
Parameters:
Name Type Argument Default Description
minVal Vec1 | Object | Number <optional>
0 Specifies the lower end of the random range. If a scalar is given, it applies to all channels.
maxVal Vec1 | Object | Number <optional>
1 Specifies the upper end of the random range. If a scalar is given, it applies to all channels.
Returns:
this
Type
Vec1