Java 跳跃动作-处理-滑动手势方向?

Java 跳跃动作-处理-滑动手势方向?,java,processing,gesture,leap-motion,Java,Processing,Gesture,Leap Motion,到目前为止,我一直在使用两个库来完成我的leap motion项目,因为它们都允许使用不同的函数,并且彼此实现得更好。但是,我只想使用一个库,因为多个库会导致问题 基本上,我使用的是Michael Heuer的Leap Motion,我需要使用这个库,因为它是目前我能找到的唯一一个可以设置优化hmd和比例因子的库 手势实现如下所示,有没有办法从中获得滑动方向 void onInit(final Controller controller) { controller.enableGesture

到目前为止,我一直在使用两个库来完成我的leap motion项目,因为它们都允许使用不同的函数,并且彼此实现得更好。但是,我只想使用一个库,因为多个库会导致问题

基本上,我使用的是Michael Heuer的Leap Motion,我需要使用这个库,因为它是目前我能找到的唯一一个可以设置优化hmd和比例因子的库

手势实现如下所示,有没有办法从中获得滑动方向

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()); 

 }
}
我尝试了手势。方向,但徒劳地希望它能起作用,但方向不是公认的功能


非常感谢您的帮助!提前谢谢!将

首先,您可以在处理过程中直接使用Leap运动库

其次,您需要将手势对象作为SwipeGesture的实例,以便访问方向功能:

SwipeGesture swipe = SwipeGesture(gesture);
手势基类仅定义所有手势通用的函数/属性。这就是它在Leap Motion API中的工作原理;它在您正在使用的包装器库中的工作方式可能与此相同

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());
}

仅供将来参考,希望这能帮助其他人

感谢您的回复,知道我可以直接访问leap motion库非常有用。我有点不确定如何做到这一点,我可能很笨,但我真的无法在我的代码中实现它,你能帮我把它和上面的代码整合起来吗?对不起,忽略我的上一条评论,我设法让它工作,并从中获得滑动方向,但我的问题是,现在swipe.direction返回一个向量,当我试图将它存储在PVector中以获取x坐标时,它显然不工作,错误是“无法转换”Vector to PVector',我尝试导入java.utils并将其存储在Vector中,但当我这样做时,我再次得到“无法将Vector转换为Vector”:忽略上面的注释,我现在已解决问题,我将在下面发布代码,感谢您为我指出了正确的方向!您好,我是的开发者。我注意到,对滑动方向的需求是自然的。因此,我将使用该功能实现并更新库。之后,我会在这里通知你一个简短的评论。