VectorΒΆ

Vector mathematics in leap.js uses the glMatrix JavaScript library. The glMatrix library is included in the leap.js library, so you do not need to include a separate copy. You can read the documentation for the glMatrix library at http://glmatrix.net/docs/2.2.0/.

A vector in the JavaScript API (and the glmatrix library) is represented by a 3-element array of numbers rather than a specific Vector class. The first element is the x-coordinate, the second is the y-coordinate and the last is the z-coordinate. The glmatrix library defines the vec3 namespace to contain its functions for 3-dimensional vectors. For example, given a Leap Motion Hand() object, you can compute the cross product between the hand direction and the palm normal with the following code:

var crossProduct = Leap.vec3.create();
var direction = hand.direction;
var normal = hand.palmNormal;

Leap.vec3.cross(crossProduct, direction, normal);