I'm working on a high-level API for the Leap Motion. It's written in Java and contains at the moment only basics to track hands. E.g.:
public class Simple implements PointMotionListener {
public static void main(String[] args) throws Exception {
// Load native libraries at runtime.
// Initialize Leap Motion and handle all input.
LeapApp.init();
// Your application ...
new Simple();
System.in.read();
// Shutdown.
LeapApp.destroy();
}
public Simple() {
// Add new MotionListener to all hands (past and future).
LeapApp.getMotionRegistry().addPointMotionListener(this);
}
// Listen to events:
@Override
public void pointMoved(PointEvent event) {
// X/Y-coordinates of the hand on the screen
System.out.println("[" + event.getX() + ";" + event.getY() + ";"
+ event.getZ() + "]");
}
@Override
public void pointDragged(PointEvent event) {
}
}
Default setting: Fullscreen. Listen to one hand and tracks dynamically on one side of the controller. (Hand moved left into the controller -> left. Hand moved right into the controller -> right). But it's all optional ...
LeapApp.init();
// Use default user settings to track the hand:
LeapApp.setMode(Mode.INTERACTION_BOX);
// Listen to two hands
LeapApp.setMaximumHandNumber(2);
// Change application size
LeapApp.setDisplayWidth(800);
LeapApp.setDisplayHeight(800);
There is also a improved "Touch Zone"-Listener.
public void zoneChanged(PointEvent pointEvent) {
event.isInZone(Zone.BACK); // Hand is somewhere back.
// Hand is somewhere back on the right side of the "TrackingBox":
event.isInZone(Zone.BACK, Zone.RIGHT);
if(event.enteredViewPort()) { // New Hand detected
// One-to-One Mapping:
int handId = event.getSource().id();
Hand hand = LeapApp.getController().frame().hand(handId);
// Define your own "InteractionBox":
event.getSource().setTrackingBox(...);
}
}
You can track your Hand wherever you want. Define a Box (millimeter) and place it somewhere. Every hand has his own TrackingBox.
If you want to try the AWT MouseListener call "myFrame.addWindowAdapter(LeapApp.getAndSetupAWTMouseListener())". [Only very limited support]
Proof of concept:
AWTPointer: 1 hand - Click the Button and take over the Mouse. Exit: Alt + F4.
Slick2D: 2 hand - Drag the blue Rectangle to resize the orange Rectangle. Move with both hands to the opposite side of the screen. Exit: Alt + F4.
Swing: 1 hand - Move your hand. Find the TrackingBox. Exit: Alt + F4.
PS: There is no documentation because this is only a preview. If you use linux or mac, put your native libraries into the native folder. EclipseProject: Source + Sample. More information is available on my german blog ruzman.de.