API Docs for: 0.5.5
Show:

kick.math.Vec4 Class

Defined in: kick/math/Vec4.js:14
Module: kick.math

Vec4 - 4 Dimensional Vector
Note: To perform vec3 functions on vec4, simply call the vec3 functions

Item Index

Methods

Methods

add

(
  • out
  • a
  • b
)
kick.math.Vec4 static

Adds two vec4's

Parameters:

Returns:

array

(
  • count
  • ref
)
kick.math.Vec3 static

Create a continuous array in memory mapped to vec4.

Example

Parameters:

  • count Number

    Number of vec 3 to be layout in memory

  • ref Object

    Optional, if set a memory reference is set to ref.mem

Returns:

kick.math.Vec3:

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
)
kick.math.Vec4 static

Creates a new vec4 initialized with values from an existing vector

Parameters:

Returns:

kick.math.Vec4:

a new 4D vector

copy

(
  • out
  • a
)
kick.math.Vec4 static

Copy the values from one vec4 to another

Parameters:

Returns:

create

() kick.math.Vec4 static

Creates a new, empty vec4

Returns:

kick.math.Vec4:

New vec4

distance

(
  • a
  • b
)
Number static

Calculates the euclidian distance between two vec4's

Parameters:

Returns:

Number:

distance between a and b

divide

(
  • out
  • a
  • b
)
kick.math.Vec4 static

Divides two vec4's

Parameters:

Returns:

dot

(
  • a
  • b
)
Number static

Calculates the dot product of two vec4's

Parameters:

Returns:

Number:

dot product of a and b

equal

(
  • vec
  • vec2
  • epsilon
)
Boolean static

Test to see if vectors are equal (difference is less than epsilon)

Parameters:

Returns:

Boolean:

true if two vectors are equals

forEach

(
  • a
  • stride
  • offset
  • count
  • fn
  • [arg]
)
Array static

Perform some operation over an array of vec4s.

Parameters:

  • a Array

    the array of vectors to iterate over

  • stride Number

    Number of elements between the start of each vec4. If 0 assumes tightly packed

  • offset Number

    Number of elements to skip at the beginning of the array

  • count Number

    Number of vec2s to iterate over. If 0 iterates over entire array

  • fn Function

    Function to call for each vector in the array

  • [arg] Object optional

    additional argument to pass to fn

Returns:

Array:

a

fromValues

(
  • x
  • y
  • z
  • w
)
kick.math.Vec4 static

Creates a new vec4 initialized with the given values

Parameters:

  • x Number

    X component

  • y Number

    Y component

  • z Number

    Z component

  • w Number

    W component

Returns:

kick.math.Vec4:

a new 4D vector

length

(
  • a
)
Number static

Calculates the length of a vec4

Parameters:

Returns:

Number:

length of a

lerp

(
  • out
  • a
  • b
  • t
)
kick.math.Vec4 static

Performs a linear interpolation between two vec4's

Parameters:

Returns:

max

(
  • out
  • a
  • b
)
kick.math.Vec4 static

Returns the maximum of two vec4's

Parameters:

Returns:

min

(
  • out
  • a
  • b
)
kick.math.Vec4 static

Returns the minimum of two vec4's

Parameters:

Returns:

multiply

(
  • out
  • a
  • b
)
kick.math.Vec4 static

Multiplies two vec4's

Parameters:

Returns:

negate

(
  • out
  • a
)
kick.math.Vec4 static

Negates the components of a Vec4

Parameters:

Returns:

normalize

(
  • out
  • a
)
kick.math.Vec4 static

Normalize a vec4

Parameters:

Returns:

scale

(
  • out
  • a
  • b
)
kick.math.Vec4 static

Scales a vec4 by a scalar number

Parameters:

Returns:

set

(
  • out
  • x
  • y
  • z
  • w
)
kick.math.Vec4 static

Set the components of a vec4 to the given values

Parameters:

  • out kick.math.Vec4

    the receiving vector

  • x Number

    X component

  • y Number

    Y component

  • z Number

    Z component

  • w Number

    W component

Returns:

squaredDistance

(
  • a
  • b
)
Number static

Calculates the squared euclidian distance between two vec4's

Parameters:

Returns:

Number:

squared distance between a and b

squaredLength

(
  • a
)
Number static

Calculates the squared length of a vec4

Parameters:

Returns:

Number:

squared length of a

str

(
  • vec
)
String static

Returns a string representation of a vector

Parameters:

Returns:

String:

string representation of vec

subtract

(
  • out
  • a
  • b
)
kick.math.Vec4 static

Subtracts two vec4's

Parameters:

Returns:

transformMat4

(
  • out
  • a
  • m
)
kick.math.Vec4 static

Transforms the vec4 with a mat4.

Parameters:

Returns:

transformQuat

(
  • out
  • a
  • q
)
kick.math.Vec4 static

Transforms the vec4 with a quat

Parameters:

Returns:

wrapArray

(
  • array
)
Array_kick.math.Vec4 static

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:

Array_kick.math.Vec4:

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]);
}