Pergunta

I am making leap motion application.

I can detect when fingers come up in the sensor, but I can't detect when all fingers disappear.

Is there any way to tell the moment all fingers disappear like mouseout event for mouse?

Foi útil?

Solução

There is no event when pointables objets (fingers or tools) disappear, but to handle this you can keep the previous frame, or information about the previous frame, and check if fingers were in the device area.

var lastNbFingers = 0;

// Setup Leap loop with frame callback function
var controllerOptions = {enableGestures: true};
Leap.loop(controllerOptions, function(frame)
{
  var nbFingers = 0; // Cpt for all fingers from all hands in the current frame
  var fingerRemoved = false; // are all the fingers just removed from device area ?

  // how many fingers in our scene
  for (var h = 0; h < frame.hands.length; ++h)
  {
    var hand = frame.hands[h];
    nbFingers += hand.fingers.length;
  }

  if (nbFingers > 0)   // there are fingers
    lastNbFingers = nbFingers;
  else if (lastNbFingers > 0)  // there is no finger on current frame, but some on previous frame
    {
      lastNbFingers = 0;
      fingerRemoved = true;   
    }
   if (fingerRemoved)
      // do some stuff

});
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top