2014-10-22 116 views
0

我一直在使用2个库直到现在我的飞跃项目作为一个bodge,因为它们都允许不同的功能,独特(更好地实现)到彼此。不过,我想只是使用一个库作为多个导致问题。闰盘 - 处理 - 滑动手势方向?

基本上我使用迈克尔豪雅的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()); 

} 
} 

我试着gesture.direction()枉然希望它可能工作,但方向不是一个公认的功能。

任何帮助非常感谢!提前致谢!将

回答

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

只是为了将来的参考,希望这可以帮助别人出去!

+0

您好,我是[捐献的图书馆]的开发人员(https://developer.leapmotion.com/gallery/category/processing)。我注意到,自然需要滑动方向。所以我会用这个功能来实现和更新库。之后,我会在这里通知你一个简短的评论。 – 2015-05-27 06:36:46

0

首先,您可以直接在Processing中使用Leap Motion库。

其次,需要获取手势对象作为SwipeGesture的一个实例中,以访问方向()函数:

SwipeGesture swipe = SwipeGesture(gesture); 

的手势基类只定义功能/公共属性的所有姿势。这就是它在Leap Motion API中的工作原理。它可能在您使用的包装库中以相同的方式工作。

+0

感谢您的回复,我知道我可以直接访问跳跃运动库。 (我有点不确定如何做到这一点)我可能会很厚,但我真的不能解决如何在我的代码中实现它,你能帮我把它与上面的代码集成吗? – 2014-10-23 08:32:47

+0

抱歉忽略我的最后一条评论我设法让它工作,并从中获取滑动方向但是现在我的问题是swipe.direction()返回一个Vector,并且当我尝试将它存储在一个PVector中以获取它的x坐标时不工作和错误说'不能转换矢量为PVector',我试图导入java.utils并将其存储在一个矢量然而,当我这样做,我得到'不能转换矢量为矢量' – 2014-10-23 08:49:28

+0

再次:忽略上面的评论,我现在有已解决我将在下面发布代码,感谢您指引我朝着正确的方向发展! – 2014-10-23 09:18:18