2014-10-22 81 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