LeapJS
LeapJS is a Javascript library that provides the functionality and object structure of the Leap API to assist developers who are working with the Leap Motion in a browser environment.
Including
Include Leap.js for debugging and access to "private" variables:
<script src="Leap.js"></script>
Include Leap.min.js for deployed applications to reduce load times:
<script src="Leap.min.js"></script>
Tutorial
// Create a controller to connect to the Leap Motion
myController = new Leap.Controller("ws://localhost:6437/");
// Create a listener
myListener = new Leap.Listener();
// Listener.onFrame is called each time a frame is received
myListener.onFrame = function(controller){
var frame = controller.frame();
var hands = frame.hands();
var pointables = frame.pointables();
var gestures = frame.gestures();
// Awesome code goes here
}
// Add the listener to the controller
myController.addListener(myListener);
// Enable the screenTap gesture
myController.enableGesture("screenTap", true);
// Listener.onConnect is called when the connection is open
myListener.onConnect = function(controller){
// Calibrate the screen
calibrate = new Leap.Calibrate(controller);
calibrate.onComplete = function(screen){
// Save the screen
// Or access it later with myController.calibratedScreens()[0]
}
}
Whats new? Gestures!
- Gesture.Type
- "circle"
- "keyTap"
- "screenTap"
- "swipe"
- CircleGesture : Gesture
- KeyTapGesture : Gesture
- ScreenTapGesture : Gesture
- SwipeGesture : Gesture
- Controller
- void enableGesture( string type, Bool enable )
- Bool isGestureEnabled( string type )
- Frame
- GestureList gestures()
- GestureList gestures( Frame sinceFrame )
Whats new? Calibration!
- Calibrate
- Calibrate( Controller controller )
- virtual void onComplete( Screen screen )
- Screen
- Screen()
- float distanceToPoint( Vector point )
- { position : Vector, distance : float } intersect( Pointable pointable, Bool normalize )
- { position : Vector, distance : float } intersect( Vector position, Vector direction, Bool normalize )
- { position : Vector, distance : float } project( Pointable pointable, Bool normalize )
- { position : Vector, distance : float } project( Vector position, Bool normalize )
- Vector normal()
- void offset()
- Bool isValid()
- static Screen invalid()