//callback function void glListener::onFrame(const Controller& controller){ /*memset(pitches, 0,sizeof(pitches)); memset(rolls, 0,sizeof(rolls)); memset(yaws, 0,sizeof(yaws));*/ //Get the most recent frame and report some basic information const Frame frame = controller.frame(); if(!frame.hands().empty()) { //get the first hand const Hand hand = frame.hands()[0]; //wrist pitches[0] = hand.palmNormal().pitch(); rolls[0] = hand.palmNormal().roll(); yaws[0] = hand.palmNormal().yaw(); /*pitches[0] = hand.direction().pitch(); rolls[0] = hand.direction().roll(); yaws[0] = hand.direction().yaw();*/ //check if the hand has any fingers const FingerList fingers = hand.fingers(); //如果检测到手指且手指的数目等于5 if (!fingers.empty() && fingers.count() == 5) { /*for(int i = 0; i < fingers.count(); i++) { }*/ //Thumb yaws[2] = -fingers.leftmost().direction().pitch(); //Index yaws[5] = -fingers[2].direction().pitch(); //Middle yaws[8]= -fingers[0].direction().pitch(); //Ring yaws[11]= -fingers[1].direction().pitch(); //Little yaws[14]= -fingers.rightmost().direction().pitch(); float temp = 0; //if index is at the right of ring if(fingers[2].tipPosition().x > fingers[1].tipPosition().x) { //swap the pitch angle of index and ring temp = yaws[5]; yaws[5] = yaws[11]; yaws[11] = temp; } } } pModel->animation(pitches,rolls,yaws); }
void LeapController::onFrame(const Controller& controller) { //console() << "Leap: onFrame" << std::endl; // Get the most recent frame and report some basic information const Frame frame = controller.frame(); /* console() << "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().empty()) { const FingerList fingers = frame.fingers(); for(int k = 0; k < fingers.count(); k++){ if (!fingers.empty()){ // Calculate the hand's average finger tip position for (int i = 0; i < fingers.count(); ++i) { ci::Vec2f currentFingerPos(fingers[i].tipPosition().x, fingers[i].tipPosition().z*-1.0); fingerPositions[i] = currentFingerPos; ci::Vec2f currentFingerVel(fingers[i].tipVelocity().x, (fingers[i].tipVelocity().z)); fingerVelocities[i] = currentFingerVel; } avgPos = fingers[0].tipPosition(); numActiveFingers = fingers.count(); hasFingers = true; } else{ hasFingers = false; } } /* // Get the first hand const Hand hand = frame.hands()[0]; // Check if the hand has any fingers const FingerList fingers = hand.fingers(); if (!fingers.empty()){ // Calculate the hand's average finger tip position for (int i = 0; i < fingers.count(); ++i) { ci::Vec2f currentFingerPos(fingers[i].tipPosition().x, fingers[i].tipPosition().y); fingerPositions[i] = currentFingerPos; ci::Vec2f currentFingerVel(fingers[i].tipVelocity().x, (fingers[i].tipVelocity().y*-1.0)); fingerVelocities[i] = currentFingerVel; } avgPos = fingers[0].tipPosition(); numActiveFingers = fingers.count(); //console() << "Hand has " << fingers.count() << " fingers, average finger tip position" << avgPos << std::endl; hasFingers = true; } else{ hasFingers = false; } */ /* // Get the hand's sphere radius and palm position console() << "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 console() << "Hand pitch: " << direction.pitch() * RAD_TO_DEG << " degrees, " << "roll: " << normal.roll() * RAD_TO_DEG << " degrees, " << "yaw: " << direction.yaw() * RAD_TO_DEG << " degrees" << std::endl; */ } else{ hasFingers = false; } /* // 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; } console() << "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; console() << "Swipe id: " << gesture.id() << ", state: " << gesture.state() << ", direction: " << swipe.direction() << ", speed: " << swipe.speed() << std::endl; break; } case Gesture::TYPE_KEY_TAP: { KeyTapGesture tap = gesture; console() << "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; console() << "Screen Tap id: " << gesture.id() << ", state: " << gesture.state() << ", position: " << screentap.position() << ", direction: " << screentap.direction()<< std::endl; break; } default: console() << "Unknown gesture type." << std::endl; break; } } if (!frame.hands().empty() || !gestures.empty()) { console() << std::endl; }*/ }