如何使跳跃动作不检测滑动手势

时间:2016-10-08 05:42:54

标签: leap-motion

我只想检测滑动手势方向"向上/向下"和"右/左"。 当我向前伸展双手时,飞跃运动不应该检测到该动作以轻扫手势。 我怎么能做到?

    String swipeDirection;

    GestureList gestures = frame.gestures();
    for(int i=0; i<gestures.count(); i++){
        Gesture gesture = gestures.get(i);

        if(gesture.type()==gesture.type().TYPE_SWIPE){
            SwipeGesture swipeGesture = new SwipeGesture(gesture);
            boolean isHorizontal = Math.abs(swipeGesture.direction().get(0))>Math.abs(swipeGesture.direction().get(1));
            if(isHorizontal){
                if(swipeGesture.direction().get(0)>0){
                    swipeDirection = "right";
                }else{
                    swipeDirection="left";
                }
            }else{
                if(swipeGesture.direction().get(1)>0){
                    swipeDirection="up";
                }else{
                    swipeDirection = "down";
                }
            }
            System.out.println("direction: "+swipeDirection + " hand: "+frame.hands().get(0).isLeft()
                    +", duration: "+swipeGesture.durationSeconds());
        }
    }
}
}

1 个答案:

答案 0 :(得分:0)

您希望确保方向指向x轴或y轴而不是z轴。因此,与计算滑动方向是否为水平的方式类似,您需要检查它是否向前/向后:

boolean isNotForward = Math.abs(swipeGesture.direction().get(0)) >
                       Math.abs(swipeGesture.direction().get(2)) || 
                       Math.abs(swipeGesture.direction().get(1)) >
                       Math.abs(swipeGesture.direction().get(2));