kick.math.Vec4 Class
Vec4 - 4 Dimensional Vector
Note: To perform vec3 functions on vec4, simply call the vec3 functions
Item Index
Methods
- add static
- array static
- clone static
- copy static
- create static
- distance static
- divide static
- dot static
- equal static
- forEach static
- fromValues static
- length static
- lerp static
- max static
- min static
- multiply static
- negate static
- normalize static
- scale static
- set static
- squaredDistance static
- squaredLength static
- str static
- subtract static
- transformMat4 static
- transformQuat static
- wrapArray static
Methods
add
-
out
-
a
-
b
Adds two vec4's
Parameters:
-
out
kick.math.Vec4the receiving vector
-
a
kick.math.Vec4the first operand
-
b
kick.math.Vec4the second operand
Returns:
out
array
-
count
-
ref
Create a continuous array in memory mapped to vec4.
Example
Parameters:
-
count
NumberNumber of vec 3 to be layout in memory
-
ref
ObjectOptional, if set a memory reference is set to ref.mem
Returns:
New vec3
Example:
var ref = {};
var v = kick.math.Vec4.array(2,ref);
v[1][1] = 1;
ref.mem[5] == v[1][1];
Will be layout like this:
[vec4][vec4] = [0][1][2][3][4][5][6][7]
clone
-
a
Creates a new vec4 initialized with values from an existing vector
Parameters:
-
a
kick.math.Vec4vector to clone
Returns:
a new 4D vector
copy
-
out
-
a
Copy the values from one vec4 to another
Parameters:
-
out
kick.math.Vec4the receiving vector
-
a
kick.math.Vec4the source vector
Returns:
out
distance
-
a
-
b
Calculates the euclidian distance between two vec4's
Parameters:
-
a
kick.math.Vec4the first operand
-
b
kick.math.Vec4the second operand
Returns:
distance between a and b
divide
-
out
-
a
-
b
Divides two vec4's
Parameters:
-
out
kick.math.Vec4the receiving vector
-
a
kick.math.Vec4the first operand
-
b
kick.math.Vec4the second operand
Returns:
out
dot
-
a
-
b
Calculates the dot product of two vec4's
Parameters:
-
a
kick.math.Vec4the first operand
-
b
kick.math.Vec4the second operand
Returns:
dot product of a and b
equal
-
vec
-
vec2
-
epsilon
Test to see if vectors are equal (difference is less than epsilon)
Parameters:
-
vec
kick.math.Vec4first operand
-
vec2
kick.math.Vec4second operand
-
epsilon
NumberOptional - default value is
Returns:
true if two vectors are equals
forEach
-
a
-
stride
-
offset
-
count
-
fn
-
[arg]
Perform some operation over an array of vec4s.
Parameters:
-
a
Arraythe array of vectors to iterate over
-
stride
NumberNumber of elements between the start of each vec4. If 0 assumes tightly packed
-
offset
NumberNumber of elements to skip at the beginning of the array
-
count
NumberNumber of vec2s to iterate over. If 0 iterates over entire array
-
fn
FunctionFunction to call for each vector in the array
-
[arg]
Object optionaladditional argument to pass to fn
Returns:
a
fromValues
-
x
-
y
-
z
-
w
Creates a new vec4 initialized with the given values
Parameters:
-
x
NumberX component
-
y
NumberY component
-
z
NumberZ component
-
w
NumberW component
Returns:
a new 4D vector
length
-
a
Calculates the length of a vec4
Parameters:
-
a
kick.math.Vec4vector to calculate length of
Returns:
length of a
lerp
-
out
-
a
-
b
-
t
Performs a linear interpolation between two vec4's
Parameters:
-
out
kick.math.Vec4the receiving vector
-
a
kick.math.Vec4the first operand
-
b
kick.math.Vec4the second operand
-
t
Numberinterpolation amount between the two inputs
Returns:
out
max
-
out
-
a
-
b
Returns the maximum of two vec4's
Parameters:
-
out
kick.math.Vec4the receiving vector
-
a
kick.math.Vec4the first operand
-
b
kick.math.Vec4the second operand
Returns:
out
min
-
out
-
a
-
b
Returns the minimum of two vec4's
Parameters:
-
out
kick.math.Vec4the receiving vector
-
a
kick.math.Vec4the first operand
-
b
kick.math.Vec4the second operand
Returns:
out
multiply
-
out
-
a
-
b
Multiplies two vec4's
Parameters:
-
out
kick.math.Vec4the receiving vector
-
a
kick.math.Vec4the first operand
-
b
kick.math.Vec4the second operand
Returns:
out
negate
-
out
-
a
Negates the components of a Vec4
Parameters:
-
out
kick.math.Vec4the receiving vector
-
a
kick.math.Vec4vector to negate
Returns:
out
normalize
-
out
-
a
Normalize a vec4
Parameters:
-
out
kick.math.Vec4the receiving vector
-
a
kick.math.Vec4vector to normalize
Returns:
out
scale
-
out
-
a
-
b
Scales a vec4 by a scalar number
Parameters:
-
out
kick.math.Vec4the receiving vector
-
a
kick.math.Vec4the vector to scale
-
b
Numberamount to scale the vector by
Returns:
out
set
-
out
-
x
-
y
-
z
-
w
Set the components of a vec4 to the given values
Parameters:
-
out
kick.math.Vec4the receiving vector
-
x
NumberX component
-
y
NumberY component
-
z
NumberZ component
-
w
NumberW component
Returns:
out
squaredDistance
-
a
-
b
Calculates the squared euclidian distance between two vec4's
Parameters:
-
a
kick.math.Vec4the first operand
-
b
kick.math.Vec4the second operand
Returns:
squared distance between a and b
squaredLength
-
a
Calculates the squared length of a vec4
Parameters:
-
a
kick.math.Vec4vector to calculate squared length of
Returns:
squared length of a
str
-
vec
Returns a string representation of a vector
Parameters:
-
vec
kick.math.Vec4vec4 to represent as a string
Returns:
string representation of vec
subtract
-
out
-
a
-
b
Subtracts two vec4's
Parameters:
-
out
kick.math.Vec4the receiving vector
-
a
kick.math.Vec4the first operand
-
b
kick.math.Vec4the second operand
Returns:
out
transformMat4
-
out
-
a
-
m
Transforms the vec4 with a mat4.
Parameters:
-
out
kick.math.Vec4the receiving vector
-
a
kick.math.Vec4the vector to transform
-
m
kick.math.Mat4matrix to transform with
Returns:
out
transformQuat
-
out
-
a
-
q
Transforms the vec4 with a quat
Parameters:
-
out
kick.math.Vec4the receiving vector
-
a
kick.math.Vec4the vector to transform
-
q
kick.math.Quatquaternion to transform with
Returns:
out
wrapArray
-
array
Wraps a Float32Array with multiple vec4 arrays. For instance if you have colors defined in a single
Float32Array, but need to do vector operations on the elements of the array, instead of copying data out of the
Float32Array, wrapArray will give you access to the same data.
Example:
Parameters:
-
array
Float32Array
Returns:
Example:
function averageColor(float32arrayColor){
var sum = vec4.create(),
wrappedArray = vec4.wrapArray(float32arrayColor),
weigth = 1.0/wrappedArray;
for (var i=0;i < wrappedArray.length;i++){
vec4.add(sum,wrappedArray[i]);
}
return vec4.multiply(sum, sum, [weight, weight, weight, weight]);
}