Manal T.
Manal T.

Reputation: 1

pinch gesture in leap motion (javaScript)

I tried to code gestures to print something when pinch is occurred just between thumb and index .I have problem because the code is print although the pinch does not occur between thumb and index.

ANY HELP :(

<!DOCTYPE html>
<html>
 <script src="//cdnjs.cloudflare.com/ajax/libs/three.js/r67/three.js"></script>
    <script src="//js.leapmotion.com/leap-0.6.2.js"></script>
    <script src="//js.leapmotion.com/leap-plugins-0.1.6.1.js"></script>
    <script src="//js.leapmotion.com/leap.rigged-hand-0.1.4.min.js"></script>

<body>


<script>


Leap.loop({ 
    hand: function(hand){
 //if(hand.pinchStrength == 1&&hand.grabStrength!==1){
    var pincher;
    var closest = 800;
   for(var f = 1; f <= 5; f++){
       if(hand.pinchStrength == 1 && hand.grabStrength!==1){
        current = hand.fingers[f];
        distance = Leap.vec3.distance(hand.thumb.pipPosition,current.pipPosition);
        if(current !== hand.thumb && current == hand.indexFinger && distance < closest  ){ 
            closest = distance;
            pincher = current;  
            document.write("the finger is " + pincher.type +"<br />");
           
            } 
   } break;}
         //document.write("<br />"+"the distance is "closest "<br />");
          
 //}
    }});  
</script>

</body>
</html> 

Upvotes: 0

Views: 575

Answers (2)

abhay
abhay

Reputation: 642

I'm answering this question because If anyone is still searching for a pinch action. my answer will help them.

const PINCH_MIN = 0.5;
let pinchPoint, pinchStrength , oPinchStrength;

 oPinchStrength = pinchStrength;
 pinchStrength = hand.pinchStrength;

  if( oPinchStrength < PINCH_MIN && pinchStrength >= PINCH_MIN)
                {
                  // Pinch Start action
 
                }else if(oPinchStrength > PINCH_MIN && pinchStrength <= PINCH_MIN){
                  // Pinch Stop action

                }

Upvotes: 0

Charles Ward
Charles Ward

Reputation: 1388

You need to decide whether the index finger was the pincher AFTER you finish checking all the fingers. As it stands, your if statement which runs when current == indexFinger will ALWAYS evaluate to true once -- it is the first finger you check.

You can either check which finger current is set to after running the whole loop, or run the loop backward so the index finger is the last finger you check.

Upvotes: 0

Related Questions