Leap Motion: Swipe Gesture direction?

Basically I am using Leap Motion by Michael Heuer ( I need to use this library because it is currently the only library I can find that allows me to set optimize hmd and also scale factor).

The gesture implementation is as below, is there a way to get the swipe direction from this?

void onInit(final Controller controller)
{
  controller.enableGesture(Gesture.Type.TYPE_SWIPE);
  // enable top mounted policy
  controller.setPolicyFlags(Controller.PolicyFlag.POLICY_OPTIMIZE_HMD);
}

void onFrame(final Controller controller)
{
  Frame frame = controller.frame();
  for (Gesture gesture : frame.gestures())
  {
      if ("TYPE_SWIPE".equals(gesture.type().toString()) && "STATE_START".equals(gesture.state().toString())) {
    }

    println("gesture " + gesture + " id " + gesture.id() + " type " + gesture.type() + " state " + gesture.state() + " duration " + gesture.duration() + " durationSeconds " + gesture.durationSeconds()); 

 }
}

I tried gesture.direction() in the vain hope it might work but direction is not a recognized function.

Any help is much appreciated! Thanks in advance! Will

Answers

  • Found solution to my problem so thought would post here, hopefully will help someone in future!

    import com.leapmotion.leap.Controller;
    import com.leapmotion.leap.Frame;
    import com.leapmotion.leap.Gesture;
    import com.leapmotion.leap.Hand;
    import com.leapmotion.leap.HandList;
    import com.leapmotion.leap.processing.LeapMotion;
    import com.leapmotion.leap.SwipeGesture;
    import com.leapmotion.leap.Vector;
    
    LeapMotion leapMotion;
    
    void setup()
    {
      size(16 * 50, 9 * 50);
      background(20);
    
      leapMotion = new LeapMotion(this);
    }
    
    void draw()
    {
      fill(20);
      rect(0, 0, width, height);
    }
    
    void onInit(final Controller controller)
    {
      controller.enableGesture(Gesture.Type.TYPE_SWIPE);
      // enable top mounted policy
      //controller.setPolicyFlags(Controller.PolicyFlag.POLICY_OPTIMIZE_HMD);
    }
    
    void onFrame(final Controller controller)
    {
      Frame frame = controller.frame();
      for (Gesture gesture : frame.gestures())
      {
    
     if(gesture.type() == Gesture.Type.TYPE_SWIPE) {
        SwipeGesture swipeGesture = new SwipeGesture(gesture);
    
        Vector swipeVector  = swipeGesture.direction();
        println("swipeVector : " + swipeVector);
    
        float swipeDirection = swipeVector.getX();
        println(swipeDirection);
       }
    }
    
      HandList hands = frame.hands();
      //println(hands.count());
    }
    
Sign In or Register to comment.