4
$\begingroup$

Building on this thread (where I cannot add anything anymore somehow) and with this nice answer I kind of got swipe detection to work, but it is not very responsive. How to improve (in the sense of making it more robust, sensitive) this code?

   (* this is the directory where LeapSDK is *)
    $leapdir = 
      FileNameJoin[{$UserBaseDirectory, "Applications", 
        "LeapDeveloperKit"}];
    If[FileExistsQ[$leapdir], Needs["JLink`"];
      Block[{nativelibs}, 
       With[{(*the location of the developer kit:*)
         lmlib = FileNameJoin[{$leapdir, "LeapSDK", "lib"}]}, 
        nativelibs = 
         FileNameJoin[{lmlib, 
           Switch[$SystemID, "Windows-x86-64", "x64", "Windows", "x86"]}];
        (*now start Java*)
        JLink`ReinstallJava[
         JLink`ClassPath -> FileNameJoin[{lmlib, "LeapJava.jar"}], 
         JLink`JVMArguments -> 
          "-Djava.library.path=\"" <> nativelibs <> "\""]]]];

    controller = JavaNew["com.leapmotion.leap.Controller"];
    LoadJavaClass["com.leapmotion.leap.Gesture$Type"];
    If[Not[controller@isGestureEnabled[Gesture$Type`TYPEUSWIPE]],
      controller@enableGesture[Gesture$Type`TYPEUSWIPE]
      ];
    controller@isGestureEnabled[Gesture$Type`TYPEUSWIPE];
    gesturePrint[controller_] := Module[{gesture},
      gesture = controller@frame[]@gestures[]@get[0];
      If[(gesture@type[]@name[]) === "TYPE_SWIPE",
       swipe = JavaNew["com.leapmotion.leap.SwipeGesture", gesture];

       {swipe@state[]@toString[],
        (swipe@position[]@#) & /@ {getX[], getY[], getZ[]},
        (swipe@direction[]@#) & /@ {getX[], getY[], getZ[]},
        swipe@speed[]
        }]]
    ud = .05;
    Dynamic[gesturePrint[controller], UpdateInterval -> 0.1]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.