2016-10-08 4 views
0

スワイプジェスチャーの方向を「上/下」と「右/左」だけ検出したいと思います。 手を伸ばすと、動きを飛ばして動きを検出して、スワイプジェスチャーを実行してはなりません。 どうすれば作れますか?うるう動作がスワイプジェスチャーを検出しないようにする方法

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

答えて

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)); 
+0

ありがとうございます。しかし、それはまだ前方/後方ジェスチャーを検出します。私はより正確に検出したい。私は、もし(isHorizo​​ntal && isNotForward)であれば(!isHorizo​​ntal && isNotForward){ ... } 他{ ... }この のようなコードを追加し、私は間違ったコードを作成しましたか? – pjh

+0

方向ベクトルの成分を比較すると、やや粗末なものになります。方向が他の軸よりも1軸に沿っていることだけがわかります。したがって、前方に約45度も水平または垂直と見なすことができます。それより小さい角度に制限したい場合は、方向ベクトルを直接(つまり、AngleTo()関数またはドットプロダクトを使用して)軸と比較することができます。 –

関連する問題