예제 #1
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;
  }
}
예제 #2
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;
      }
    }
}
예제 #3
0
void AppListener::onFrame(const Controller& controller) {
    // Get the most recent frame and report some basic information
    const Frame frame = controller.frame();

    ::Sleep(1);

    const HandList&     hands       = frame.hands();
    const FingerList&   fingers     = frame.fingers();
    const ToolList&     tools       = frame.tools();
    const GestureList&  gestures    = frame.gestures();

    if (hands.empty() && fingers.empty() && tools.empty() && gestures.empty())
        return;

#if 0
    std::cout 
        << "Frame id: "     << frame.id()
        << ", timestamp: "  << frame.timestamp()
        << " hands: "       << hands.count()
        << " fingers: "     << fingers.count()
        << " tools: "       << tools.count()
        << " gestures: "    << gestures.count() 
        << std::endl;
#endif
    ofxOscBundle bundle;

    ofxOscMessage alive;
    {
        alive.setAddress("/tuio/2Dcur");
        alive.addStringArg("alive");
    }

    ofxOscMessage fseq;
    {
        fseq.setAddress( "/tuio/2Dcur" );
        fseq.addStringArg( "fseq" );
        fseq.addIntArg(frame.id());
    }

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

        // Check if the hand has any fingers
        const FingerList& fingers = hand.fingers();
        if (!fingers.empty()) {
            for (int i = 0; i < fingers.count(); ++i) {
                const Vector& tipPos = fingers[i].tipPosition();
                const Vector& tipVel = fingers[i].tipVelocity();
                {
#ifdef INIT_BBOX
                    // max/min bbox
                    bboxMax.x = std::max<float>(bboxMax.x, tipPos.x);
                    bboxMax.y = std::max<float>(bboxMax.y, tipPos.y);
                    bboxMax.z = std::max<float>(bboxMax.z, tipPos.z);

                    bboxMin.x = std::min<float>(bboxMin.x, tipPos.x);
                    bboxMin.y = std::min<float>(bboxMin.y, tipPos.y);
                    bboxMin.z = std::min<float>(bboxMin.z, tipPos.z);
#endif
                    Vector tuioPos;
                    tuioPos.x = normalize(tipPos.x, bboxMin.x, bboxMax.x);
                    tuioPos.y = normalize(tipPos.y, bboxMax.y, bboxMin.y);
                    tuioPos.z = normalize(tipPos.z, bboxMin.z, bboxMax.z);

                    // tuio
                    {
                        ofxOscMessage m;
                        m.setAddress( "/tuio/2Dcur" );
                        m.addStringArg("set");
                        m.addIntArg(fingers[i].id());				// id
                        m.addFloatArg(tuioPos.x);	// x
                        m.addFloatArg(tuioPos.y);	// y
                        // TOTO
                        m.addFloatArg(tipVel.x / 400);			// dX
                        m.addFloatArg(tipVel.y / 400);			// dY
                        m.addFloatArg(0);		// maccel
                        bundle.addMessage(m);
                        alive.addIntArg(fingers[i].id());				// add blob to list of ALL active IDs
                    }
                }
            }
#ifdef INIT_BBOX            
            std::cout << "min: " << bboxMin << std::endl;
            std::cout << "max: " << bboxMax << std::endl;
#endif
        }
#if 0
        // Get the hand's sphere radius and palm position
        std::cout << "Hand sphere radius: " << hand.sphereRadius()
            << " mm, palm position: " << hand.palmPosition() << std::endl;
#endif

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

#if 0
        // 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;
#endif
    }

    bundle.addMessage(alive);
    bundle.addMessage(fseq);
    tuioSender.sendBundle(bundle);

    // Get 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 0
    if (!hands.empty() || !gestures.empty()) {
        std::cout << std::endl;
    }
#endif
}
예제 #4
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;

}
예제 #5
0
void AirwritingListener::onFrame(const Controller& controller) {
    // Get the most recent frame and report some basic information
    const Frame frame = controller.frame();
    unsigned long long timestamp = frame.timestamp();
    
    /*
    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;
            sample(finger, timestamp);
            
            /*
            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;
                push(timestamp);
                /*
                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;
    }
    */
    
}
예제 #6
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;
  }
}