/*----------------------------------------------------------------------------------------------------*/
void Gestures::update() {
    Frame frame = mController.frame(0);
    GestureList gestures = frame.gestures();
    int gestureCount = gestures.count();

    for ( int i = 0 ; i < gestureCount ; i++ ) {
        sendGesture(gestures[i]);
    }
}
void MyListener::onFrame(const Controller& controller) 
{
    const Frame frame = controller.frame();
    const GestureList gestures = frame.gestures();
    HandList hands = frame.hands();
    
    for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) {
        const Hand hand = *hl;
        // Smoothing and stabilization is performed in order to make this 
        // value more suitable for interaction with 2D content. The stabilized 
        // position lags behind the palm position by a variable amount, 
        // depending primarily on the speed of movement.
        Vector position = hand.stabilizedPalmPosition();

        if (m_positionChanged)
            m_positionChanged(position[0], position[1], position[2], 
                              frame.fingers().extended().count(), 
                              hand.direction(),
                              hand.palmVelocity());

        if (m_pinch)
            m_pinch(hand.pinchStrength());

        if (m_grab)
            m_grab(hand.grabStrength());
    }

    for (int g = 0; g < gestures.count(); ++g) {
        Gesture gesture = gestures[g];
        switch (gesture.type()) {
        case Gesture::TYPE_KEY_TAP:
        case Gesture::TYPE_SCREEN_TAP:
            if (m_tapped)
                m_tapped();
            break;
        case Gesture::TYPE_SWIPE:
            break;
        }
    }
}
Exemple #3
0
void LeapHands::onFrame(const Controller& controller) 
{
	//Game::Instance()->PrintFloat("Hand children: ", childrenMap.size());	
	std::map<string, BoneData> tempBoneData;
	HandList hands = controller.frame().hands();
	int handId = 0;

	hands[0].fingers()[(int) Finger::Type::TYPE_THUMB];

	for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) {
		// Get the first hand
		const Hand hand = *hl;
		// Get fingers
		const FingerList fingers = hand.fingers();
		int fingerId = 0;
		bool firstFinger = true;
		Finger previousFinger;

		stringstream ass;
		ass << "Arm: 0 Hand: " << handId;
		tempBoneData[ass.str()] = BoneData(ass.str(), LeapToGlVec3(hand.arm().wristPosition()), LeapToGlVec3(hand.arm().elbowPosition()), true);
		ass.clear();

		glm::vec3 thumbBone = LeapToGlVec3(hand.fingers()[Finger::Type::TYPE_THUMB].bone(Bone::Type::TYPE_DISTAL).nextJoint());
		glm::vec3 indexBone = LeapToGlVec3(hand.fingers()[Finger::Type::TYPE_INDEX].bone(Bone::Type::TYPE_DISTAL).nextJoint());
		pinchDist = glm::length(thumbBone - indexBone);
		if (pinchDist < 5.0f)
		{
			pinch = true;
		}
		else
		{
			pinch = false;
		}

		for (FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) {
			const Finger finger = *fl;

			// Get finger bones
			for (int b = 0; b < 4; ++b) {
				Bone::Type boneType = static_cast<Bone::Type>(b);
				Bone bone = finger.bone(boneType);
				stringstream ss;
				ss << "Hand: " << handId << " Finger: " << fingerId << " Bone: " << b;
				tempBoneData[ss.str()] = BoneData(ss.str(), LeapToGlVec3(bone.prevJoint()), LeapToGlVec3(bone.nextJoint()), true);


			}
			// Draw some other bits of the hand
			if (!firstFinger)
			{
				for (int b = 0; b < 2; ++b)
				{
					stringstream ss;
					ss << "Hand: " << handId << "Finger: " << (fingerId - 1) << "Finger: " << (fingerId) << " Bone: " << b;
					Bone startBone = previousFinger.bone(static_cast<Bone::Type>(b));
					Bone endBone = finger.bone(static_cast<Bone::Type>(b));
					if ((b == 1) && (fingerId == 1))
					{
						tempBoneData[ss.str()] = BoneData(ss.str(), LeapToGlVec3(startBone.nextJoint()), LeapToGlVec3(endBone.prevJoint()), false);
					}
					else
					{
						tempBoneData[ss.str()] = BoneData(ss.str(), LeapToGlVec3(startBone.prevJoint()), LeapToGlVec3(endBone.prevJoint()), false);
					}
				}
			}

			const GestureList gestures = controller.frame().gestures();
			for (int g = 0; g < gestures.count(); ++g) 
			{
				Gesture gesture = gestures[g];

				switch (gesture.type())
				{
					case Gesture::TYPE_CIRCLE:
					{
						CircleGesture circle = gesture;
						if (gesture.durationSeconds() > 1)
						{
							if (circle.pointable().direction().angleTo(circle.normal()) <= PI / 2) {
								
								spawn = vehicle;
							}
							else {
								spawn = model;
							}
						}
					}
				}
			}

			previousFinger = finger;
			firstFinger = false;
			++fingerId;
		}
		++handId;
	}	
	EnterCriticalSection(&criticalSection);
	trackedHands = handId;
	map<string, BoneData>::iterator it = tempBoneData.begin();
	boneData = tempBoneData;
	LeaveCriticalSection(&criticalSection);
}
Exemple #4
0
void SampleListener::onFrame(const Controller& controller) {
  // Get the most recent frame and report some basic information
  const Frame frame = controller.frame();
  std::cout << "Frame id: " << frame.id()
            << ", timestamp: " << frame.timestamp()
            << ", hands: " << frame.hands().count()
            << ", fingers: " << frame.fingers().count()
            << ", tools: " << frame.tools().count()
            << ", gestures: " << frame.gestures().count() << std::endl;

  if (!frame.hands().isEmpty()) {
    // Get the first hand
    const Hand hand = frame.hands()[0];

    // Check if the hand has any fingers
    const FingerList fingers = hand.fingers();
    if (!fingers.isEmpty()) {
      // Calculate the hand's average finger tip position
      Vector avgPos;
      for (int i = 0; i < fingers.count(); ++i) {
        avgPos += fingers[i].tipPosition();
      }
      avgPos /= (float)fingers.count();
      std::cout << "Hand has " << fingers.count()
                << " fingers, average finger tip position" << avgPos << std::endl;
    }

    // Get the hand's sphere radius and palm position
    std::cout << "Hand sphere radius: " << hand.sphereRadius()
              << " mm, palm position: " << hand.palmPosition() << std::endl;

    // Get the hand's normal vector and direction
    const Vector normal = hand.palmNormal();
    const Vector direction = hand.direction();

    // Calculate the hand's pitch, roll, and yaw angles
    std::cout << "Hand pitch: " << direction.pitch() * RAD_TO_DEG << " degrees, "
              << "roll: " << normal.roll() * RAD_TO_DEG << " degrees, "
              << "yaw: " << direction.yaw() * RAD_TO_DEG << " degrees" << std::endl;
  }

  // Get gestures
  const GestureList gestures = frame.gestures();
  for (int g = 0; g < gestures.count(); ++g) {
    Gesture gesture = gestures[g];

    switch (gesture.type()) {
      case Gesture::TYPE_CIRCLE:
      {
        CircleGesture circle = gesture;
        std::string clockwiseness;

        if (circle.pointable().direction().angleTo(circle.normal()) <= PI/4) {
          clockwiseness = "clockwise";
        } else {
          clockwiseness = "counterclockwise";
        }

        // Calculate angle swept since last frame
        float sweptAngle = 0;
        if (circle.state() != Gesture::STATE_START) {
          CircleGesture previousUpdate = CircleGesture(controller.frame(1).gesture(circle.id()));
          sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * PI;
        }
        std::cout << "Circle id: " << gesture.id()
                  << ", state: " << gesture.state()
                  << ", progress: " << circle.progress()
                  << ", radius: " << circle.radius()
                  << ", angle " << sweptAngle * RAD_TO_DEG
                  <<  ", " << clockwiseness << std::endl;
        break;
      }
      case Gesture::TYPE_SWIPE:
      {
        SwipeGesture swipe = gesture;
        std::cout << "Swipe id: " << gesture.id()
          << ", state: " << gesture.state()
          << ", direction: " << swipe.direction()
          << ", speed: " << swipe.speed() << std::endl;
        break;
      }
      case Gesture::TYPE_KEY_TAP:
      {
        KeyTapGesture tap = gesture;
        std::cout << "Key Tap id: " << gesture.id()
          << ", state: " << gesture.state()
          << ", position: " << tap.position()
          << ", direction: " << tap.direction()<< std::endl;
        break;
      }
      case Gesture::TYPE_SCREEN_TAP:
      {
        ScreenTapGesture screentap = gesture;
        std::cout << "Screen Tap id: " << gesture.id()
        << ", state: " << gesture.state()
        << ", position: " << screentap.position()
        << ", direction: " << screentap.direction()<< std::endl;
        break;
      }
      default:
        std::cout << "Unknown gesture type." << std::endl;
        break;
    }
  }

  if (!frame.hands().isEmpty() || !gestures.isEmpty()) {
    std::cout << std::endl;
  }
}
void LeapListener::onFrame(const Controller & controller) {
    // Get the most recent frame and report some basic information
    const Frame frame = controller.frame();
    std::cout << "Frame id: " << frame.id()
    << ", timestamp: " << frame.timestamp()
    << ", hands: " << frame.hands().count()
    << ", extended fingers: " << frame.fingers().extended().count()
    << ", tools: " << frame.tools().count()
    << ", gestures: " << frame.gestures().count() << std::endl;

    HandList hands = frame.hands();
    for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) {
        // Get the first hand
        const Hand hand = *hl;
        std::string handType = hand.isLeft() ? "Left hand" : "Right hand";
        std::cout << std::string(2, ' ') << handType << ", id: " << hand.id()
        << ", palm position: " << hand.palmPosition() << std::endl;
        // Get the hand's normal vector and direction
        const Vector normal = hand.palmNormal();
        const Vector direction = hand.direction();

        // Calculate the hand's pitch, roll, and yaw angles
        std::cout << std::string(2, ' ') <<  "pitch: " << direction.pitch() * RAD_TO_DEG << " degrees, "
        << "roll: " << normal.roll() * RAD_TO_DEG << " degrees, "
        << "yaw: " << direction.yaw() * RAD_TO_DEG << " degrees" << std::endl;

        // Get the Arm bone
        Arm arm = hand.arm();
        std::cout << std::string(2, ' ') <<  "Arm direction: " << arm.direction()
        << " wrist position: " << arm.wristPosition()
        << " elbow position: " << arm.elbowPosition() << std::endl;

        // Get fingers
        const FingerList fingers = hand.fingers();
        for (FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) {
            const Finger finger = *fl;
            std::cout << std::string(4, ' ') <<  fingerNames[finger.type()]
            << " finger, id: " << finger.id()
            << ", length: " << finger.length()
            << "mm, width: " << finger.width() << std::endl;

            // Get finger bones
            for (int b = 0; b < 4; ++b) {
                Bone::Type boneType = static_cast<Bone::Type>(b);
                Bone bone = finger.bone(boneType);
                std::cout << std::string(6, ' ') <<  boneNames[boneType]
                << " bone, start: " << bone.prevJoint()
                << ", end: " << bone.nextJoint()
                << ", direction: " << bone.direction() << std::endl;
            }
        }
    }

    // Get tools
    const ToolList tools = frame.tools();
    for (ToolList::const_iterator tl = tools.begin(); tl != tools.end(); ++tl) {
        const Tool tool = *tl;
        std::cout << std::string(2, ' ') <<  "Tool, id: " << tool.id()
        << ", position: " << tool.tipPosition()
        << ", direction: " << tool.direction() << std::endl;
    }

    // Get gestures
    const GestureList gestures = frame.gestures();
    for (int g = 0; g < gestures.count(); ++g) {
        Gesture gesture = gestures[g];

        switch (gesture.type()) {
            case Gesture::TYPE_CIRCLE: {
                CircleGesture circle = gesture;
                std::string clockwiseness;

                if (circle.pointable().direction().angleTo(circle.normal()) <= PI/2) {
                    clockwiseness = "clockwise";
                } else {
                    clockwiseness = "counterclockwise";
                }

                // Calculate angle swept since last frame
                float sweptAngle = 0;
                if (circle.state() != Gesture::STATE_START) {
                    CircleGesture previousUpdate = CircleGesture(controller.frame(1).gesture(circle.id()));
                    sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * PI;
                }
                std::cout << std::string(2, ' ')
                << "Circle id: " << gesture.id()
                << ", state: " << stateNames[gesture.state()]
                << ", progress: " << circle.progress()
                << ", radius: " << circle.radius()
                << ", angle " << sweptAngle * RAD_TO_DEG
                <<  ", " << clockwiseness << std::endl;
                break;
            }
            case Gesture::TYPE_SWIPE: {
                SwipeGesture swipe = gesture;
                std::cout << std::string(2, ' ')
                << "Swipe id: " << gesture.id()
                << ", state: " << stateNames[gesture.state()]
                << ", direction: " << swipe.direction()
                << ", speed: " << swipe.speed() << std::endl;
                break;
            }
            case Gesture::TYPE_KEY_TAP: {
                KeyTapGesture tap = gesture;
                std::cout << std::string(2, ' ')
                << "Key Tap id: " << gesture.id()
                << ", state: " << stateNames[gesture.state()]
                << ", position: " << tap.position()
                << ", direction: " << tap.direction()<< std::endl;
                break;
            }
            case Gesture::TYPE_SCREEN_TAP: {
                ScreenTapGesture screentap = gesture;
                std::cout << std::string(2, ' ')
                << "Screen Tap id: " << gesture.id()
                << ", state: " << stateNames[gesture.state()]
                << ", position: " << screentap.position()
                << ", direction: " << screentap.direction() << std::endl;
                break;
            }
            default:
                std::cout << std::string(2, ' ')  << "Unknown gesture type." << std::endl;
                break;
        }
    }

    if (!frame.hands().isEmpty() || !gestures.isEmpty())
        std::cout << std::endl;
}
Exemple #6
0
void SampleListener::onFrame(const Controller& controller)
{
  // This function needs to be broken up, it's way too long
  const Frame frame = controller.frame();
  //int currid = 1;

  //check if we already processed this frame
  if (frame.id() == this->lastFrameID)
    return;
  this->lastFrameID = frame.id();

  //stop activity if we've not been used for ACTIVETIMEOUT
  if ((ACTIVETIMEOUT + this->lastEvent) < time(0) && this->active)
  {
    std::cout << "auto deactivated" << std::endl;
    this->active = false;
  }

  if (frame.fingers().count() == 2)
  {
    GestureList gestures = frame.gestures();
    for (int it = 0; it < gestures.count(); ++it)
    {
      if (gestures[it].type() != Gesture::TYPE_KEY_TAP)
        continue;
      if ((this->lastToggle + TOGGLE_FRAME_LIMIT) > frame.id()) //avoid detecting the same tap twice
        continue;
      KeyTapGesture gesture = gestures[it];
      Vector v = gesture.direction();
      this->active = !this->active;
      this->lastToggle = frame.id();
      this->lastEvent = time(0);
      std::cout << (this->active ? "activated" : "deactivated") << std::endl;
      break; //make sure we don't accidentally use the same list twice
    }
  }

  if (!this->active)
    return;

  if (frame.fingers().count() == 1 & side != 2)
  {
    PointableList pointables = frame.pointables();
    InteractionBox iBox = frame.interactionBox();
    for (int p = 0; p < pointables.count(); ++p)
    {
      Pointable pointable = pointables[p];
      Vector normalizedPosition = iBox.normalizePoint(pointable.stabilizedTipPosition());
      float distance = pointable.touchDistance();
      float x = normalizedPosition.x * (Mouse->w_width+250);
      float y = (Mouse->w_height + 250) - normalizedPosition.y * (Mouse->w_height + 250);
      if (side == 0)
      {
        Mouse->move((int)x, (int)y);
        pressedDelay = 0;
      }
      if (distance < 0)
      {
        clickcount++;
        side = 1;
        if (clickcount > sensibility)
        {
          if (pressstate == 0)
          {
            Mouse->leftPress();
            pressstate = 1;
          }
          else
          {
            if (clickcount >= 30)
            {
              if (rclick == 0)
                Mouse->move((int)x,(int)y);
              std::cout << "move side: "<< side << std::endl;
              clickcount = 20;
            }
          }
        }
      }
      else if (side == 1)
      {
        Mouse->leftRelease();
        std::cout << "released side: " << side << std::endl;
        side = 0;
        pressstate = 0;
        pressedDelay = 0;
        clickcount = 0;
        rclick = 0;
      }
    }
    this->lastEvent = time(0);
  }
  else if (frame.fingers().count() > 1 & side != 1)
  {
    clickcount = 0;
    std::cout << "active side: " << side << std::endl;
    // Get gestures
    const GestureList gestures = frame.gestures();
    for (int g = 0; g < gestures.count(); ++g)
    {
      Gesture gesture = gestures[g];
        switch (gesture.type())
        {
          case Gesture::TYPE_CIRCLE :
          {
            CircleGesture circle = gesture;
            if (gesture.state() == 3 & circle.progress() > 1)
            {
              side = 0;
              rclick = 1;
              Mouse->rightPress();
              Mouse->rightRelease();
            }
            break;
          }
          case Gesture::TYPE_SWIPE :
          {
            side = 2;
            SwipeGesture swipe = gesture;
            Vector d = swipe.direction();
            //  std::cout << "Swipe id: " << d(1) << std::endl;
            if (d[1] > 0.8)
            {
              this->mystate = 1; //up
              // std::cout << "wheel up " <<std::endl;
            }
            else if (d[1] < -0.8)
            {
              this->mystate = 2; //down
              //std::cout << "wheel down " <<std::endl;
            }
            if (swipe.state() == 3)
            {
              if (this->mystate == 1)
              {
                side = 0;
                this->mystate = 0;
                Mouse->wheelUp();
              }
              else if (this->mystate == 2)
              {
                side = 0;
                this->mystate = 0;
                Mouse->wheelDown();
              }
            }
            break;
          }

          default:
          //std::cout << "Unknown gesture type." << std::endl;
          break;
        }
    }
    this->lastEvent = time(0);
  }
}
Exemple #7
0
void QLeapEventListener::onFrame(const Controller & controller)
{
    const Frame frame = controller.frame();
    // Get gestures
    const GestureList gestures = frame.gestures();
    for (int g = 0; g < gestures.count(); ++g) {
      Gesture gesture = gestures[g];

      switch (gesture.type()) {
        case Gesture::TYPE_CIRCLE:
        {
          CircleGesture circle = gesture;
          std::string clockwiseness;

          if (circle.pointable().direction().angleTo(circle.normal()) <= PI/4) {
            clockwiseness = "clockwise";
          } else {
            clockwiseness = "counterclockwise";
          }

          // Calculate angle swept since last frame
          float sweptAngle = 0;
          if (circle.state() != Gesture::STATE_START) {
            CircleGesture previousUpdate = CircleGesture(controller.frame(1).gesture(circle.id()));
            sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * PI;
          }
          std::cout << "Circle id: " << gesture.id()
                    << ", state: " << gesture.state()
                    << ", progress: " << circle.progress()
                    << ", radius: " << circle.radius()
                    << ", angle " << sweptAngle * RAD_TO_DEG
                    <<  ", " << clockwiseness << std::endl;
          break;
        }
        case Gesture::TYPE_SWIPE:
        {
          SwipeGesture swipe = gesture;
          std::cout << "Swipe id: " << gesture.id()
            << ", state: " << gesture.state()
            << ", direction: " << swipe.direction()
            << ", speed: " << swipe.speed() << std::endl;
          onSwipe(swipe);
          break;
        }
        case Gesture::TYPE_KEY_TAP:
        {
          KeyTapGesture tap = gesture;
          std::cout << "Key Tap id: " << gesture.id()
            << ", state: " << gesture.state()
            << ", position: " << tap.position()
            << ", direction: " << tap.direction()<< std::endl;
          break;
        }
        case Gesture::TYPE_SCREEN_TAP:
        {
          ScreenTapGesture screentap = gesture;
          std::cout << "Screen Tap id: " << gesture.id()
          << ", state: " << gesture.state()
          << ", position: " << screentap.position()
          << ", direction: " << screentap.direction()<< std::endl;
          break;
        }
        default:
          std::cout << "Unknown gesture type." << std::endl;
          break;
      }
    }
}
Exemple #8
0
void SampleListener::onFrame(const Controller& controller) {
	//tictoc_stack.push(clock());
	// Get the most recent frame and report some basic information
	const Frame frame = controller.frame();

	HandList hands = frame.hands();
	for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) {
		// Get the first hand
		const Hand hand = *hl;
		std::string handType = hand.isLeft() ? "Left hand" : "Right hand";
		
		const Vector normal = hand.palmNormal();
		const Vector direction = hand.direction();

		// Get the Arm bone
		Arm arm = hand.arm();

		// Get fingers
		const FingerList fingers = hand.fingers();
		for (FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) {
			const Finger finger = *fl;
	
			myfile << std::string(4, ' ') << fingerNames[finger.type()]
				<< ": " << hand.palmPosition().distanceTo(finger.tipPosition());

			// Get finger bones
			for (int b = 0; b < 4; ++b) {
				Bone::Type boneType = static_cast<Bone::Type>(b);
				Bone bone = finger.bone(boneType);
			}
		}
	}

	// Get tools
	const ToolList tools = frame.tools();
	for (ToolList::const_iterator tl = tools.begin(); tl != tools.end(); ++tl) {
		const Tool tool = *tl;
	}

	// Get gestures
	const GestureList gestures = frame.gestures();
	for (int g = 0; g < gestures.count(); ++g) {
		Gesture gesture = gestures[g];

		switch (gesture.type()) {
		case Gesture::TYPE_CIRCLE:
		{
			CircleGesture circle = gesture;
			std::string clockwiseness;

			if (circle.pointable().direction().angleTo(circle.normal()) <= PI / 2) {
				clockwiseness = "clockwise";
			}
			else {
				clockwiseness = "counterclockwise";
			}

			// Calculate angle swept since last frame
			float sweptAngle = 0;
			if (circle.state() != Gesture::STATE_START) {
				CircleGesture previousUpdate = CircleGesture(controller.frame(1).gesture(circle.id()));
				sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * PI;
			}
			break;
		}
		case Gesture::TYPE_SWIPE:
		{
			SwipeGesture swipe = gesture;
			break;
		}
		case Gesture::TYPE_KEY_TAP:
		{
			KeyTapGesture tap = gesture;
			break;
		}
		case Gesture::TYPE_SCREEN_TAP:
		{
			ScreenTapGesture screentap = gesture;
			break;
		}
		default:
			break;
		}
	}

	if (!frame.hands().isEmpty() || !gestures.isEmpty()) {
		std::cout << std::endl;
	}
	myfile << " Time elapsed: "
		<< ((double)(clock() - tictoc_stack.top())) / CLOCKS_PER_SEC;
	tictoc_stack.pop();
	myfile << endl;

}
void LeapController::update() {   
    hands = leap.getLeapHands();
    
    if(leap.isFrameNew() && hands.size()){
        
        for(int i = 0; i < hands.size(); i++){
            
            Hand hand = hands[i];
            
            if (handsPrevious.size() == hands.size() && hand.fingers().count() == 3){
                
                float dx =  hand.palmPosition().x - handsPrevious[i].palmPosition().x;
                float dy =  hand.palmPosition().z - handsPrevious[i].palmPosition().z;
                float dz = -hand.palmPosition().y + handsPrevious[i].palmPosition().y;
                int numFingers = hands[i].fingers().count();
                
//                horizontalPan = (numFingers == 2);
                horizontalPan = false;
                verticalPan = true;
                
                pan(dx,dy,dz);
            }
        }
    }
    
    Frame frame = controller.frame();
    GestureList gestures =  framePrevious.isValid()       ?
    frame.gestures(framePrevious) :
    frame.gestures();
    framePrevious = frame;
    
    for (size_t i=0; i < gestures.count(); i++) {
        if (gestures[i].type() == Gesture::TYPE_SCREEN_TAP) {
            ScreenTapGesture tap = gestures[i];
            static GestureEventArgs args;
            args.pos = ofVec3f(tap.position().x, tap.position().y, tap.position().z);
            ofNotifyEvent(onTapScreen, args, this);
        } else if (gestures[i].type() == Gesture::TYPE_KEY_TAP) {
            KeyTapGesture tap = gestures[i];
            static GestureEventArgs args;
            args.pos = ofVec3f(tap.position().x, tap.position().y, tap.position().z);
            ofNotifyEvent(onTapDown, args, this);
            
            //cout << "LEAP TAP GESTURE AT: " << pos << endl;
        
        } else if (gestures[i].type() == Gesture::TYPE_SWIPE) {
            SwipeGesture swipe = gestures[i];
            Vector diff = 0.004f*(swipe.position() - swipe.startPosition());
            static GestureEventArgs args;
            args.pos = ofVec3f(swipe.position().x, swipe.position().y, swipe.position().z);
            args.startPos = ofVec3f(swipe.startPosition().x, swipe.startPosition().y, swipe.startPosition().z);
            args.state = swipe.state();
            ofNotifyEvent(onSwipe, args, this);
            
            //cout << "LEAP SWIPE GESTURE" << endl;
        
        } else if (gestures[i].type() == Gesture::TYPE_CIRCLE) {
            CircleGesture circle = gestures[i];
            float progress = circle.progress();
            
            if (progress >= 1.0f) {
                double curAngle = 6.5;
                
                //cout << "LEAP CIRCLE GESTURE" << endl;
            }
            static GestureEventArgs args;
            args.pos = ofVec3f(circle.center().x, circle.center().y, circle.center().z);
            args.normal = ofVec3f(circle.normal().x, circle.normal().y, circle.normal().z);
            args.progress = circle.progress();
            ofNotifyEvent(onCircle, args, this);
        }
    }
    
    handsPrevious = hands;
    
	leap.markFrameAsOld();
    
    SceneController::update();
}
Exemple #10
0
void QTVS_Leap::LeapGestureLogic()
{

  for (int g = 0; g < gestures.count(); ++g) {
    Gesture gesture = gestures[g];

    switch (gesture.type()) {
    case Gesture::TYPE_CIRCLE:
    {
//        emit Listener_Gesture(gesture, gesture.type());
      CircleGesture circle = gesture;
      std::string clockwiseness;

      if (circle.pointable().direction().angleTo(circle.normal()) <= PI / 2) {
        clockwiseness = "clockwise";

        // MouseKeyboardEmulation::MouseWheelDown(5);

      } else {
        clockwiseness = "counterclockwise";

        // MouseKeyboardEmulation::MouseWheelUp(5);
      }

      // Calculate angle swept since last frame
      float sweptAngle = 0;
      if (circle.state() != Gesture::STATE_START) {
        CircleGesture previousUpdate = CircleGesture(controller.frame(1).gesture(circle.id()));
        sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * PI;
      }
      std::cout << std::string(2, ' ')
                << "Circle id: " << gesture.id()
                << ", state: " << stateNames[gesture.state()]
                << ", progress: " << circle.progress()
                << ", radius: " << circle.radius()
                << ", angle " << sweptAngle * RAD_TO_DEG
                <<  ", " << clockwiseness << std::endl;
      break;
    }
    case Gesture::TYPE_SWIPE:
    {
      SwipeGesture swipe = gesture;
      //            debugDisplayString = "";
      // debugDisplayString.append("Swipe id: " + QString::number(gesture.id()));
      // debugDisplayString.append( ", state: " + QString(stateNames[gesture.state()].data()));
      // debugDisplayString.append( ", direction: " + QString(swipe.direction().toString().data()));
      // debugDisplayString.append( ", speed: " + QString::number(swipe.speed()));
      std::cout << std::string(2, ' ')
                << "Swipe id: " << gesture.id()
                << ", state: " << stateNames[gesture.state()]
                << ", direction: " << swipe.direction()
                << ", speed: " << swipe.speed() << std::endl;
      break;
    }
    case Gesture::TYPE_KEY_TAP:
    {
      KeyTapGesture tap = gesture;
//        std::cout << std::string(2, ' ')
      //debugDisplayString = "";
      // debugDisplayString.append("Key Tap id: " + QString::number(gesture.id()));
      // debugDisplayString.append( ", state: " + QString(stateNames[gesture.state()].data()));
      //debugDisplayString.append( ", position: " + QString(tap.position().toString().data()));
      // debugDisplayString.append( ", direction: " + QString(tap.direction().toString().data()));
      break;
    }
    case Gesture::TYPE_SCREEN_TAP:
    {
      ScreenTapGesture screentap = gesture;
      std::cout << std::string(2, ' ')
                << "Screen Tap id: " << gesture.id()
                << ", state: " << stateNames[gesture.state()]
                << ", position: " << screentap.position()
                << ", direction: " << screentap.direction() << std::endl;
      break;
    }
    default:
      std::cout << std::string(2, ' ')  << "Unknown gesture type." << std::endl;
      break;
    }
  }

  if (!frame.hands().isEmpty() || !gestures.isEmpty()) {
    std::cout << std::endl;
  }
}