Constructor
new Vec(data, offset, end)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
data |
Array.<number> | The array behind the vector, storing the components | |
offset |
number | 0 | The index of the array with the first component |
end |
number | 3 | The index of the array with the last component |
Example
// create a vector (0,0,0,0) and do few operations
const position = Vec.from(0,0);
postion.add(otherVec).multiplyScalar(3.4);
const magenta = Vec.fromHex(0xff00ffff, 8);
const yellow = Vec.fromHex("#ffff00");
magenta.vec(); // [255, 0, 255, 255]
magenta.color(); // [1, 0, 1, 1]
Members
a :number
The "a" component of the vector.
b :number
The "b" component of the vector.
dimension
Dimension of the vector. Should be 4 in most cases.
g :number
The "g" component of the vector.
r :number
The "r" component of the vector.
w :number
The "w" component of the vector.
x :number
The "x" component of the vector.
y :number
The "y" component of the vector.
z :number
The "z" component of the vector.
Methods
add(vec) :Core.Vec
Add the values of the components of the given vector to this vector.
Parameters:
Name | Type | Description |
---|---|---|
vec |
The vec to add |
Returns:
The ref to this
clone() :Core.Vec
Clones the current vector.
This is not a deep copy if the components are not numbers, but references they will have the same reference.
Returns:
The cloned vector
color() :Array.<number>
Gets the array of components behind the vector after normalizing colors bigger than 1 by dividing them with 255.
Returns:
The normalized array of components
divide(f) :Core.Vec
Divides a single value from all components of this vector.
Parameters:
Name | Type | Description |
---|---|---|
f |
The number to divide the components |
Returns:
The ref to this
multiply(vec) :Core.Vec
Multiplies the values of the components of the given vector to this vector.
Parameters:
Name | Type | Description |
---|---|---|
vec |
The vec to multiply |
Returns:
The ref to this
multiplyScalar(f) :Core.Vec
Multiplies a single value to all components of this vector.
Parameters:
Name | Type | Description |
---|---|---|
f |
The number to multiply |
Returns:
The ref to this
setTo(vec) :Core.Vec
Sets the vectors components equal to an others vectors components.
Parameters:
Name | Type | Description |
---|---|---|
vec |
Core.Vec | The vec to mirror |
Returns:
- A reference to the own vector.
setXYZ(x, y, z, w) :Core.Vec
Set the individual components of this vector.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x |
The x component to set | ||
y |
The y component to set | ||
z |
0 | The z component to set | |
w |
0 | The w component to set |
Returns:
The ref to this
subtract(vec) :Core.Vec
Subtracts the values of the components of the given vector from this vector.
Parameters:
Name | Type | Description |
---|---|---|
vec |
The vec to subtract |
Returns:
The ref to this
vec() :Array.<number>
Gets the array of components behind the vector.
Returns:
The array of components
(static) from(x, y, z, w) :Core.Vec
Crates a Vec object given by all components (x,y,z,w)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x |
number | the x component of the vector | |
y |
number | the y comp... | |
z |
number | 0 | the z ... |
w |
number | 0 | ... |
Returns:
- The created object
(static) fromHex(num, bit) :Core.Vec
Creates a Vec object from a given number. Typically used for specifying hex colors.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
num |
number | The value of the vector, formatted in a single number (see hex colors -> 0xff00ff) | |
bit |
number | 8 | The number of bits per component |
Returns:
- The created vector