So the Leap Motion controller has just been released and I thought I might as well post some code that Todd Gayley and I wrote to connect the Leap Motion and all of its functionality to Mathematica!
Here are the setup instructions:
-
(If you haven’t already) download and install the leap motion
software from leapmotion.com/setup -
Download the leap motion SDK off their developer page.
-
Connect the Leap Motion to your computer.
-
Find the file “LeapJava.jar” inside of the Leap SDK (It should be under lib.)
-
Open Mathematica and paste this in:
Needs["JLink`"];
ReinstallJava[CommandLine -> "java",
JVMArguments ->
"-Djava.library.path=[path to directory CONTAINING LeapJava.jar]"];
Now put the path to “LeapJava.jar” in the indicated position, and remember this is the path to the directory containing LeapJava.jar, not the path to LeapJava.jar itself and run the code.
- Now paste this in:
AddToClassPath["[path to LeapJava.jar]"];
Replace the indicated area with the path to LeapJava.jar itself and run it.
- To setup the controller, run this:
controller = JavaNew["com.leapmotion.leap.Controller"]
You should now be fully connected and ready to go! To see if it is working you can run:
Methods[controller]
and it should return a list of all the methods under the controller.
The main method you want to look at is frame[] which contains all of the information about what is going on.
To see the methods under frame[] run this:
Methods[controller@frame[]]
From here you should be able to figure things out like this:
controller@frame[]@fingers@count[]
which should count the visible fingers in the scene.
Also in a final note I want mention that I was having problems accessing the fingers with this:
controller@frame[]@finger[finger number]
and so you may want to try:
controller@frame[]@fingers[]@get[finger number]
instead. The same goes for palms.
Well, if you write anything cool using this please post it back up here along with any questions you have.
(I am going to try to post some of the code I have written with this soon
)
