ofPoint LeapVisualizer::getIndexFingertip(ofxLeapMotion & leap){ vector <Hand> hands = leap.getLeapHands(); Hand hand; if (hands.size() > 0){ for (int h=0; h<hands.size(); h++){ hand = hands[h]; if (hand.isValid()) break; } } // For each finger in the Hand, FingerList fingers = hand.fingers(); for (int f=0; f<fingers.count(); f++) { // Get the current finger, and it's type (index, thumb, etc.); const Finger & finger = fingers[f]; Finger::Type fingerType = finger.type(); if (finger.isValid() && fingerType == Finger::TYPE_INDEX) { return ofPoint(finger.tipPosition().x, finger.tipPosition().y, finger.tipPosition().z); } } cout << "FINGER NOT FOUND" << endl; return ofPoint(-1.0f,-1.0f,-1.0f); }
//-------------------------------------------------------------- void testApp::recordHandXML (Hand & hand, int handIndex){ if (bRecordingThisFrame){ if (hand.isValid()){ int handTagNum = XML.addTag("H"); if( XML.pushTag("H", handTagNum) ){ XML.setValue("INDEX", handIndex, handTagNum); XML.setValue("ID", hand.id(), handTagNum); XML.setValue("TYPE", (hand.isLeft() ? "LEFT" : "RIGHT"), handTagNum); XML.setValue("CONF", hand.confidence(), handTagNum); FingerList fingers = hand.fingers(); for (int f=0; f<fingers.count(); f++){ const Finger & finger = fingers[f]; if (finger.isValid()){ recordFingerXML (finger); } } recordArmXML (hand); XML.popTag(); // pop H(AND) } } } }
//-------------------------------------------------------------- void ofApp::draw(){ string touchStatus; stringstream info; cam.begin(); ofDrawGrid(500, 5, true); light1.enable(); light2.enable(); ofSetColor(255, 215, 0); Frame frame = controller.frame(); for (int i=0; i < frame.hands().count(); i++) { Hand hand = frame.hands()[i]; for (int j = 0; j < hand.fingers().count(); j ++) { if (j == 0) { Finger finger = frame.fingers()[j]; ofSpherePrimitive sphere; sphere.setPosition(finger.tipPosition().x, finger.tipPosition().y, finger.tipPosition().z); sphere.draw(); info << "Finger position x : " << finger.tipPosition().x << " y : " << finger.tipPosition().y << " z : " << finger.tipPosition().z << endl; } } } cam.end(); PointableList pointables = controller.frame().pointables(); InteractionBox iBox = controller.frame().interactionBox(); for (int p = 0; p < pointables.count(); p++) { Pointable pointable = pointables[p]; Vector normalizedPosition = iBox.normalizePoint(pointable.stabilizedTipPosition()); float x = normalizedPosition.x * ofGetWidth(); float y = ofGetHeight() - normalizedPosition.y * ofGetHeight(); if (pointable.touchDistance() > 0 && pointable.touchZone() != Leap::Pointable::ZONE_NONE) { ofSetColor(0, 255, 0); touchStatus = "Hover"; } else if (pointable.touchDistance() <= 0) { ofSetColor(255, 0, 0); touchStatus = "Touch"; } else { ofSetColor(0, 0, 255); touchStatus = "None"; } ofCircle(x, y, 30); info << "Point Number : " << p << endl; info << "Touch distance : " << ofToString(pointable.touchDistance()) << endl; info << "Circle x : " << x << " y : " << y << endl; } ofDrawBitmapString("Touch Status : " + touchStatus, 20, 20); ofDrawBitmapString(info.str(), 20, 40); }
//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); }
bool Detect::getGesture(std::string& ret) { if(false == LeapController->isConnected()) { return false; } HandList HL = LeapController->frame().hands(); Hand hand = HL[0]; FingerList fingers = hand.fingers(); GestureModel * gm = new GestureModel; Leap::Matrix handTransform = hand.basis(); handTransform.origin = hand.palmPosition(); handTransform = handTransform.rigidInverse(); //get gesture data int i = 0; 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); Leap::Vector ori = bone.prevJoint(); Leap::Vector tP = handTransform.transformPoint(ori); gm->GestureData[i][b][0][0] = tP[0]; gm->GestureData[i][b][0][1] = tP[1]; gm->GestureData[i][b][0][2] = tP[2]; tP = handTransform.transformPoint(bone.nextJoint()); gm->GestureData[i][b][1][0] = tP[0]; gm->GestureData[i][b][1][1] = tP[1]; gm->GestureData[i][b][1][2] = tP[2]; tP = handTransform.transformPoint(bone.direction()); gm->GestureData[i][b][2][0] = gm->GestureData[i][b][1][0] - gm->GestureData[i][b][0][0]; gm->GestureData[i][b][2][1] = gm->GestureData[i][b][1][1] - gm->GestureData[i][b][0][1]; gm->GestureData[i][b][2][2] = gm->GestureData[i][b][1][2] - gm->GestureData[i][b][0][2]; } i++; } //compare for (int index = 0; index < GestureList.size(); index++) { if (true == compareGesture(GestureList[index], gm)) { ret = GestureList[index]->GestureName; return true; } } ret = " "; return false; }
//-------------------------------------------------------------- void LeapVisualizer::drawFingers (Hand & hand,ofxLeapMotion & leap){ // For each finger in the Hand, FingerList fingers = hand.fingers(); for (int f=0; f<fingers.count(); f++){ // Get the current finger, and it's type (index, thumb, etc.); const Finger & finger = fingers[f]; if (finger.isValid()){ drawFinger(finger,leap); } //end if finger isValid() } // end for each finger }
void LeapBrowser::updateCursorLocation() { bool is_index_found = false; Frame frame = leap_controller.frame(); HandList hands = frame.hands(); for( int h=0; h < hands.count(); h++ ) { Hand hand = hands[h]; FingerList fingers = hand.fingers(); for( int f=0; f < fingers.count(); f++ ) { Finger finger = fingers[f]; if( finger.type() == Finger::Type::TYPE_INDEX ) { is_index_found = true; Vector position = finger.tipPosition(); cursor_location = math::position(position.x, position.y, position.z) * leap_transform; break; } } if( is_index_found ) { break; } } if( !is_index_found ) { cursor_location = math::position(0,0,0); is_cursor_located = false; } else { is_cursor_located = true; } }
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; }
void SampleListener::onFrame(const Controller& controller) { bool thand, index = false; // Get the most recent frame and report some basic information const Frame frame = controller.frame(); // Receive Hand List HandList hands = frame.hands(); // For all hands for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) { // Get the first hand const Hand hand = *hl; // Only for right hand if( hand.isRight() ) { // Get fingers const FingerList fingers = hand.fingers(); // For all fingers in the list for (FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) { Bone bone; const Finger finger = *fl; // If thamb or Index finger if( finger.type() == Finger::TYPE_THUMB ) { // Receive nided bone bone = finger.bone(Bone::TYPE_DISTAL); m_vThand = bone.center(); thand = true; } else if( finger.type() == Finger::TYPE_INDEX ) { // Receive nided bone bone = finger.bone(Bone::TYPE_DISTAL); m_vIndex = bone.center(); index = true; } } } } bool newState; if( !thand || !index ) { newState = false; } else { float distance = m_vThand.distanceTo(m_vIndex); qDebug () << "Distance: " << distance; if( distance < 40 ) { newState = true; } else { newState = false; } } if( newState != m_bLastState ) { Q_EMIT releySignal( newState ); m_bLastState = newState; } }
int main(int argc, char** argv) { struct sockaddr_in si_other; int s, slen = sizeof(si_other); char buf[BUFLEN]; char message[BUFLEN]; WSADATA wsa; //Initialise winsock printf("\nInitialising Winsock..."); if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) { printf("Failed. Error Code : %d", WSAGetLastError()); exit(EXIT_FAILURE); } printf("Initialised.\n"); //create socket //if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == SOCKET_ERROR) if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) { printf("socket() failed with error code : %d", WSAGetLastError()); exit(EXIT_FAILURE); } char str[INET_ADDRSTRLEN]; //setup address structure memset((char *)&si_other, 0, sizeof(si_other)); si_other.sin_family = AF_INET; si_other.sin_port = htons(PORT); //si_other.sin_addr.S_un.S_addr = inet_pton(AF_INET, SERVER, &(si_other.sin_addr)); inet_pton(AF_INET, SERVER, &(si_other.sin_addr.S_un.S_addr)); /*if (inet_pton(AF_INET, SERVER, &(si_other.sin_addr.S_un.S_addr))) { inet_ntop(AF_INET, &(si_other.sin_addr.S_un.S_addr), str, INET_ADDRSTRLEN); std::cout << ("%s\n", str); }*/ // We catch any exceptions that might occur below -- see the catch statement for more details. try { // First, we create a Hub with our application identifier. Be sure not to use the com.example namespace when // publishing your application. The Hub provides access to one or more Myos. myo::Hub hub("om.example.emg-data-sample"); std::cout << "Attempting to find a Myo..." << std::endl; // Next, we attempt to find a Myo to use. If a Myo is already paired in Myo Connect, this will return that Myo // immediately. // waitForMyo() takes a timeout value in milliseconds. In this case we will try to find a Myo for 10 seconds, and // if that fails, the function will return a null pointer. myo::Myo* myo = hub.waitForMyo(10000); // If waitForMyo() returned a null pointer, we failed to find a Myo, so exit with an error message. if (!myo) { throw std::runtime_error("Unable to find a Myo!"); } // We've found a Myo. std::cout << "Connected to a Myo armband!" << std::endl << std::endl; // Next we enable EMG streaming on the found Myo. myo->setStreamEmg(myo::Myo::streamEmgEnabled); // Create a sample listener and controller for Leap Motion SampleListener listener; Controller controller; // Next we construct an instance of our DeviceListener, so that we can register it with the Hub. DataCollector collector; double timeElasped = 0.000; const double minMax[10] = { 32, 85, 36, 100, 37, 107, 36, 100, 36, 90 }; //T.I.M.R.P // Hub::addListener() takes the address of any object whose class inherits from DeviceListener, and will cause // Hub::run() to send events to all registered device listeners. hub.addListener(&collector); //controller.addListener(listener); if (argc > 1 && strcmp(argv[1], "--bg") == 0) controller.setPolicy(Leap::Controller::POLICY_BACKGROUND_FRAMES); myfile << std::fixed; myfile << std::setprecision(2); // Finally we enter our main loop. while (1) { //collector.tic(); // In each iteration of our main loop, we run the Myo event loop for a set number of milliseconds. // In this case, we wish to update our display 50 times a second, so we run for 1000/20 milliseconds. hub.run(1000 / 100); // After processing events, we call the print() member function we defined above to print out the values we've // obtained from any events that have occurred. collector.print(); int i = 0; int j = 1; int h = 0; double fingDis[5]; 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; // Get fingers const FingerList fingers = hand.fingers(); for (FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) { const Finger finger = *fl; //myfile << " " << hand.palmPosition().distanceTo(finger.tipPosition()); /*myfile << std::string(4, ' ') << fingerNames[finger.type()] << ": " << listener.mapping(hand.palmPosition().distanceTo(finger.tipPosition()), minMax[i + i], minMax[i + j]);*/ fingDis[h] = listener.mapping(hand.palmPosition().distanceTo(finger.tipPosition()), minMax[i + i], minMax[i + j]); //fingDis[h] = hand.palmPosition().distanceTo(finger.tipPosition()); i++; j++; h++; if (i == 5 && j == 6 && h == 5) { string tmp = to_string(fingDis[0]) + " " + to_string(fingDis[1]) + " " + to_string(fingDis[2]) + " " + to_string(fingDis[3]) + " " + to_string(fingDis[4]); //string tmp = to_string('0'); strcpy_s(message, tmp.c_str()); //send message if (sendto(s, message, strlen(message), 0, (struct sockaddr *) &si_other, slen) == SOCKET_ERROR) { printf("sendto() failed with error code : %d", WSAGetLastError()); //exit(EXIT_FAILURE); } std::cout << "Data Sent"; i = 0; j = 1; h = 0; } } } //timeElasped = timeElasped + ((double)(clock() - tictoc_stack.top())) / CLOCKS_PER_SEC; /*myfile << " Time elapsed: " << ((double)(clock() - tictoc_stack.top())) / CLOCKS_PER_SEC;*/ //tictoc_stack.pop(); //myfile << " " << timeElasped << endl; } // If a standard exception occurred, we print out its message and exit. } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; std::cerr << "Press enter to continue."; std::cin.ignore(); return 1; } closesocket(s); WSACleanup(); }
void LeapInput::onFrame(const Controller& controller) { Frame frame = controller.frame(); HandList hands = frame.hands(); this->hands = hands.count(); if(hands.count() == 2) { Hand leftHand = hands.leftmost(); Hand rightHand = hands.rightmost(); leftHandY = leftHand.palmPosition().y; rightHandY = rightHand.palmPosition().y; leftFingers = leftHand.fingers().count(); rightFingers = rightHand.fingers().count(); float threshold = tanf(5* 3.141592f / 180.0f); float maxTan = tanf(45 * 3.141592f / 180.0f); if(leftHand.palmPosition().x != rightHand.palmPosition().x){ float tanValue = fabs((leftHand.palmPosition().y - rightHand.palmPosition().y) / (leftHand.palmPosition().x - rightHand.palmPosition().x)); if(tanValue > threshold){ curve = tanValue / maxTan; if(curve > 1) curve = 1; }else curve = 0; }else curve = 0; } else { leftHandY = rightHandY = 0; } boost = false; GestureList gestureList = frame.gestures(); for(GestureList::const_iterator i = gestureList.begin(); i != gestureList.end(); ++i) { Gesture gesture = *i; if(gesture.state() != Gesture::State::STATE_INVALID) { switch(gesture.type()) { case Gesture::Type::TYPE_SCREEN_TAP: boost = true; break; } } } back = false; if(hands.count() == 2 && leftFingers == 1 && rightFingers == 1 && hands.leftmost().fingers()[0].direction().z > 0 && hands.rightmost().fingers()[0].direction().z > 0) { back = true; } //accelGesture = brakeGesture = false; //GestureList gestureList = frame.gestures(); //for(GestureList::const_iterator i = gestureList.begin(); i != gestureList.end(); ++i) //{ // Gesture gesture = *i; // if(gesture.state() != Gesture::State::STATE_INVALID) // { // if(typeid(gesture) == typeid(MyGesture)) // { // accelGesture = true; // } // // } //} }
void LeapHander::frame(pugi::xml_node &frameNode){ Leap::Frame currentFrame = m_sampleListener.frame(); m_lock.lock(); frameNode.append_attribute("id").set_value(currentFrame.id()); pugi::xml_node handList = frameNode.append_child("hands"); HandList hands = currentFrame.hands(); for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) { // Get the first hand const Hand hand = *hl; pugi::xml_node handNode = handList.append_child("hand"); handNode.append_attribute("id").set_value(hand.id()); std::string handType; if (hand.isLeft()) { handType = "Left"; } else { handType = "Right"; } handNode.append_attribute("type").set_value(handType.c_str()); pugi::xml_node positionNode = handNode.append_child("position"); positionToXml(positionNode, hand.palmPosition()); /*pugi::xml_node normalNode = handNode.append_child("normal"); positionToXml(normalNode, hand.palmNormal()); pugi::xml_node directionNode = handNode.append_child("direction"); positionToXml(directionNode, hand.direction()); pugi::xml_node rotationNode = handNode.append_child("basis"); rotationToXml(rotationNode, hand.basis());*/ //// Get fingers pugi::xml_node fingerList = handNode.append_child("fingers"); const FingerList fingers = hand.fingers(); for (FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) { const Finger finger = *fl; pugi::xml_node fingerNode = fingerList.append_child("finger"); fingerNode.append_attribute("id").set_value(finger.id()); fingerNode.append_attribute("name").set_value(fingerNames[finger.type()].c_str()); pugi::xml_node boneList = fingerNode.append_child("bones"); // Get finger bones for (int b = 0; b < 4; ++b) { Bone::Type boneType = static_cast<Bone::Type>(b); Bone bone = finger.bone(boneType); pugi::xml_node boneNode = boneList.append_child("bone"); boneNode.append_attribute("length").set_value(bone.length()); boneNode.append_attribute("name").set_value(boneNames[boneType].c_str()); pugi::xml_node prevJoint = boneNode.append_child("prevJoint"); positionToXml(prevJoint, bone.prevJoint()); pugi::xml_node nextJoint = boneNode.append_child("nextJoint"); positionToXml(nextJoint, bone.nextJoint()); /*pugi::xml_node rotation = boneNode.append_child("basis"); rotationToXml(rotation, bone.basis());*/ } } } m_lock.unlock(); }
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(); }
void LeapBrowser::drawHands() { Frame frame = leap_controller.frame(); math::vector trans = leap_transform.translation; math::quater rot_quat = leap_transform.rotation; math::vector rot_vect = math::ln( rot_quat ); double angle = rot_vect.length() * 2.0; math::vector axis = ( angle != 0 ? rot_vect / angle : rot_vect ); glMatrixMode( GL_MODELVIEW ); glPushMatrix(); glTranslatef( trans.x(), trans.y(), trans.z() ); if( angle != 0 ) { glRotatef( angle * 180.0 / M_PI, axis.x(), axis.y(), axis.z() ); } HandList hands = frame.hands(); for( HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl ) { const Hand hand = *hl; float joint_radius = 5.0f; float bone_radius = 4.5f; Vector prev_palm_start(0,0,0); Vector prev_palm_end(0,0,0); int f = 0; const FingerList fingers = hand.fingers(); for( FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl, ++f ) { const Finger finger = *fl; Vector curr_palm_start(0,0,0); Vector curr_palm_end(0,0,0); for( int b=0; b < 4; b++ ) { Bone::Type bone_type = static_cast<Bone::Type>( b ); Bone bone = finger.bone( bone_type ); Vector start = bone.prevJoint(); Vector end = bone.nextJoint(); math::position p0( start.x, start.y, start.z ); math::position p1( end.x, end.y, end.z ); if( is_tracking_pose == true && finger.type() == Finger::Type::TYPE_INDEX && b==3 ) { drawing_tool.setColor( 1, 0, 0, 1 ); } else { drawing_tool.setColor( 0.5, 0.7, 0.5, 1 ); } drawing_tool.drawSphere( p1, joint_radius ); drawing_tool.setColor( 0.5, 0.7, 0.5, 1 ); drawing_tool.drawSphere( p0, joint_radius ); drawing_tool.drawCylinder( p0, p1, bone_radius ); // if( b == 0 && fl != fingers.begin() || b == 1 && fl == fingers.begin() ) { curr_palm_start = start; curr_palm_end = end; } } if( f > 1 ) //fl != fingers.begin() ) { drawing_tool.setColor( 0.5, 0.7, 0.5, 1 ); drawing_tool.applyColor(); glBegin( GL_QUADS ); glVertex3f( prev_palm_start.x, prev_palm_start.y, prev_palm_start.z ); glVertex3f( prev_palm_end.x, prev_palm_end.y, prev_palm_end.z ); glVertex3f( curr_palm_end.x, curr_palm_end.y, curr_palm_end.z ); glVertex3f( curr_palm_start.x, curr_palm_start.y, curr_palm_start.z ); glEnd(); } prev_palm_start = curr_palm_start; prev_palm_end = curr_palm_end; } } glPopMatrix(); }
//-------------------------------------------------------------- void LeapVisualizer::drawPalm (Hand & hand,ofxLeapMotion & leap){ // This draws the palm as a gray region. // Collect the palm vertices into an ofMesh. ofMesh palmMesh; int nVertices = 0; float averageBoneWidth = 0; // For each finger, FingerList fingers = hand.fingers(); for (int f=0; f<fingers.count(); f++){ // Get the current finger, and it's type (index, thumb, etc.); const Finger & finger = fingers[f]; if (finger.isValid()){ Finger::Type fingerType = finger.type(); Bone bone; if (fingerType == Finger::TYPE_THUMB){ bone = finger.bone(Bone::TYPE_PROXIMAL); } else { bone = finger.bone(Bone::TYPE_METACARPAL); } // If we've found the bones we want, add their vertices to the mesh. if (bone.isValid()){ float boneLength = bone.length(); if (boneLength > 0){ ofPoint pt0 = leap.getofPoint ( bone.prevJoint()); ofPoint pt1 = leap.getofPoint ( bone.nextJoint()); palmMesh.addVertex(pt0); palmMesh.addVertex(pt1); averageBoneWidth += bone.width(); nVertices += 2; } } } } averageBoneWidth /= (nVertices/2); // Render the palm as a triangle strip surface, // (optionally) bordered by cylinders. if (nVertices > 3){ ofSetColor(ofColor::gray); // Draw the palm as a mesh of triangles. int nPalmMeshVertices = palmMesh.getNumVertices(); for (int i=0; i<(nPalmMeshVertices-2); i++){ palmMesh.addTriangle(i, i+1, i+2); } palmMesh.drawFaces(); // Add optional cylinders. if (!bDrawSimple){ float rad = averageBoneWidth / 2.0; if (nPalmMeshVertices == 10){ for (int i=0; i<4; i++){ ofVec3f p0 = palmMesh.getVertex( i *2); ofVec3f p1 = palmMesh.getVertex((i+1)*2); drawOrientedCylinder (p0, p1, 10); ofDrawSphere(p0, rad); ofDrawSphere(p1, rad); } for (int i=0; i<4; i++){ ofVec3f p0 = palmMesh.getVertex( i *2 + 1); ofVec3f p1 = palmMesh.getVertex((i+1)*2 + 1); drawOrientedCylinder (p0, p1, 10); ofDrawSphere(p0, rad); ofDrawSphere(p1, rad); } } } } }
void m_bang() { Frame frame; t_atom generalInfo[6]; int num_hands, num_tools, num_gestures; frame = dispatcher.frame; num_hands = frame.hands().count(); num_tools = frame.tools().count(); num_gestures = frame.gestures().count(); if(general_flag){ SETFLOAT(&generalInfo[0], (float)frame.id()); SETFLOAT(&generalInfo[1], (float)frame.timestamp()); SETFLOAT(&generalInfo[2], (float)num_hands); SETFLOAT(&generalInfo[3], (float)frame.fingers().count()); SETFLOAT(&generalInfo[4], (float)frame.tools().count()); SETFLOAT(&generalInfo[5], (float)frame.gestures().count()); ToOutList(0, 6, generalInfo); } // tools for(int i = 0; i<num_tools; i++){ Tool tool; tool = frame.tools()[i]; t_atom toolInfo[5]; if(tools_position_flag) { SETFLOAT(&toolInfo[0], i); SETSYMBOL(&toolInfo[1], gensym("direction")); SETFLOAT(&toolInfo[2], tool.direction().x); SETFLOAT(&toolInfo[3], tool.direction().y); SETFLOAT(&toolInfo[4], tool.direction().z); ToOutAnything(1, gensym("tool"), 5, toolInfo); } if(tools_position_flag) { SETFLOAT(&toolInfo[0], i); SETSYMBOL(&toolInfo[1], gensym("position")); SETFLOAT(&toolInfo[2], tool.tipPosition().x); SETFLOAT(&toolInfo[3], tool.tipPosition().y); SETFLOAT(&toolInfo[4], tool.tipPosition().z); ToOutAnything(1, gensym("tool"), 5, toolInfo); } if(tools_velocity_flag){ SETFLOAT(&toolInfo[0], i); SETSYMBOL(&toolInfo[1], gensym("velocity")); SETFLOAT(&toolInfo[2], tool.tipVelocity().x); SETFLOAT(&toolInfo[3], tool.tipVelocity().y); SETFLOAT(&toolInfo[4], tool.tipVelocity().z); ToOutAnything(1, gensym("tool"), 5, toolInfo); } if(tools_size_flag){ SETFLOAT(&toolInfo[0], i); SETSYMBOL(&toolInfo[1], gensym("size")); SETFLOAT(&toolInfo[2], tool.width()); SETFLOAT(&toolInfo[3], tool.length()); ToOutAnything(1, gensym("tool"), 4, toolInfo); } } // hands and fingers for(int i = 0; i<num_hands; i++){ Hand hand; hand = frame.hands()[i]; int num_fingers = hand.fingers().count(); int num_tools = hand.tools().count(); t_atom handInfo[5]; if(hands_direction_flag){ // direction SETFLOAT(&handInfo[0], i); SETSYMBOL(&handInfo[1], gensym("direction")); SETFLOAT(&handInfo[2], hand.direction().x); SETFLOAT(&handInfo[3], hand.direction().y); SETFLOAT(&handInfo[4], hand.direction().z); ToOutAnything(1, gensym("hand"), 5, handInfo); } if(hands_palm_position_flag){ // position SETFLOAT(&handInfo[0], i); SETSYMBOL(&handInfo[1], gensym("palm_position")); SETFLOAT(&handInfo[2], hand.palmPosition().x); SETFLOAT(&handInfo[3], hand.palmPosition().y); SETFLOAT(&handInfo[4], hand.palmPosition().z); ToOutAnything(1, gensym("hand"), 5, handInfo); } if(hands_palm_velocity_flag){ // velocity SETFLOAT(&handInfo[0], i); SETSYMBOL(&handInfo[1], gensym("palm_velocity")); SETFLOAT(&handInfo[2], hand.palmVelocity().x); SETFLOAT(&handInfo[3], hand.palmVelocity().y); SETFLOAT(&handInfo[4], hand.palmVelocity().z); ToOutAnything(1, gensym("hand"), 5, handInfo); } if(hands_palm_normal_flag){ // normal SETFLOAT(&handInfo[0], i); SETSYMBOL(&handInfo[1], gensym("palm_normal")); SETFLOAT(&handInfo[2], hand.palmNormal().x); SETFLOAT(&handInfo[3], hand.palmNormal().y); SETFLOAT(&handInfo[4], hand.palmNormal().z); ToOutAnything(1, gensym("hand"), 5, handInfo); } if(hands_sphere_radius_flag){ // sphere radius SETFLOAT(&handInfo[0], i); SETSYMBOL(&handInfo[1], gensym("sphere_radius")); SETFLOAT(&handInfo[2], hand.sphereRadius()); ToOutAnything(1, gensym("hand"), 3, handInfo); } if(hands_sphere_center_flag){ // sphere center SETFLOAT(&handInfo[0], i); SETSYMBOL(&handInfo[1], gensym("sphere_center")); SETFLOAT(&handInfo[2], hand.sphereCenter().x); SETFLOAT(&handInfo[3], hand.sphereCenter().y); SETFLOAT(&handInfo[4], hand.sphereCenter().z); ToOutAnything(1, gensym("hand"), 5, handInfo); } if(hands_finger_count_flag){ // finger count SETFLOAT(&handInfo[0], i); SETSYMBOL(&handInfo[1], gensym("finger_count")); SETFLOAT(&handInfo[2], num_fingers); ToOutAnything(1, gensym("hand"), 3, handInfo); } if(hands_tool_count_flag){ // tool count SETFLOAT(&handInfo[0], i); SETSYMBOL(&handInfo[1], gensym("tool_count")); SETFLOAT(&handInfo[2], num_tools); ToOutAnything(1, gensym("hand"), 3, handInfo); } for(int j = 0; j<num_fingers; j++){ Finger finger; finger = hand.fingers()[j]; t_atom fingerInfo[7]; if(fingers_direction_flag){ SETFLOAT(&fingerInfo[0], i); // index SETSYMBOL(&fingerInfo[1], gensym("fingers")); SETFLOAT(&fingerInfo[2], j); SETSYMBOL(&fingerInfo[3], gensym("direction")); SETFLOAT(&fingerInfo[4], finger.direction().x); SETFLOAT(&fingerInfo[5], finger.direction().y); SETFLOAT(&fingerInfo[6], finger.direction().z); ToOutAnything(1, gensym("hand"), 7, fingerInfo); } if(fingers_position_flag){ SETFLOAT(&fingerInfo[0], i); // index SETSYMBOL(&fingerInfo[1], gensym("fingers")); SETFLOAT(&fingerInfo[2], j); SETSYMBOL(&fingerInfo[3], gensym("position")); SETFLOAT(&fingerInfo[4], finger.tipPosition().x); SETFLOAT(&fingerInfo[5], finger.tipPosition().y); SETFLOAT(&fingerInfo[6], finger.tipPosition().z); ToOutAnything(1, gensym("hand"), 7, fingerInfo); } if(fingers_velocity_flag){ SETFLOAT(&fingerInfo[0], i); // index SETSYMBOL(&fingerInfo[1], gensym("fingers")); SETFLOAT(&fingerInfo[2], j); SETSYMBOL(&fingerInfo[3], gensym("velocity")); SETFLOAT(&fingerInfo[4], finger.tipVelocity().x); SETFLOAT(&fingerInfo[5], finger.tipVelocity().y); SETFLOAT(&fingerInfo[6], finger.tipVelocity().z); ToOutAnything(1, gensym("hand"), 7, fingerInfo); } if(fingers_size_flag){ SETFLOAT(&fingerInfo[0], i); // index SETSYMBOL(&fingerInfo[1], gensym("fingers")); SETFLOAT(&fingerInfo[2], j); SETSYMBOL(&fingerInfo[3], gensym("size")); SETFLOAT(&fingerInfo[4], finger.width()); SETFLOAT(&fingerInfo[5], finger.length()); ToOutAnything(1, gensym("hand"), 6, fingerInfo); } } } t_atom gestureCountInfo[1]; for(int i = 0;i < num_gestures; i++){ Gesture gesture; gesture = frame.gestures()[i]; //type t_atom gestureTypeInfo[3]; SETFLOAT(&gestureTypeInfo[0], i); SETSYMBOL(&gestureTypeInfo[1], gensym("type")); switch(gesture.type()) { case Gesture::TYPE_INVALID: SETSYMBOL(&gestureTypeInfo[2], gensym("TYPE_INVALID")); break; case Gesture::TYPE_SWIPE: SETSYMBOL(&gestureTypeInfo[2], gensym("TYPE_SWIPE")); break; case Gesture::TYPE_CIRCLE: SETSYMBOL(&gestureTypeInfo[2], gensym("TYPE_CIRCLE")); break; case Gesture::TYPE_SCREEN_TAP: SETSYMBOL(&gestureTypeInfo[2], gensym("TYPE_SCREEN_TAP")); break; case Gesture::TYPE_KEY_TAP: SETSYMBOL(&gestureTypeInfo[2], gensym("TYPE_KEY_TAP")); break; } ToOutList(2, 3, gestureTypeInfo); //state t_atom gestureStateInfo[3]; SETFLOAT(&gestureStateInfo[0], i); SETSYMBOL(&gestureStateInfo[1], gensym("state")); switch(gesture.state()) { case Gesture::STATE_INVALID: SETSYMBOL(&gestureStateInfo[2], gensym("STATE_INVALID")); break; case Gesture::STATE_START: SETSYMBOL(&gestureStateInfo[2], gensym("TYPE_START")); break; case Gesture::STATE_UPDATE: SETSYMBOL(&gestureStateInfo[2], gensym("STATE_UPDATE")); break; case Gesture::STATE_STOP: SETSYMBOL(&gestureStateInfo[2], gensym("TYPE_STOP")); break; } ToOutList(2, 3, gestureStateInfo); t_atom gestureDurationInfo[3]; SETFLOAT(&gestureDurationInfo[0], i); SETSYMBOL(&gestureDurationInfo[1], gensym("duration")); SETFLOAT(&gestureDurationInfo[2], gesture.duration()); ToOutList(2, 3, gestureDurationInfo); t_atom gestureIdInfo[3]; SETFLOAT(&gestureIdInfo[0], i); SETSYMBOL(&gestureIdInfo[1], gensym("id")); SETFLOAT(&gestureIdInfo[2], gesture.id()); ToOutList(2, 3, gestureIdInfo); } }
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 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); }
void QTVS_Leap::HandLogic() { //TODO: Fix this if (hands.count() == 1) { int iHandToFingerShift = hand.isLeft() ? 5 : 0; for (int iFingerCounter = iHandToFingerShift; iFingerCounter <= iHandToFingerShift + 4; iFingerCounter ++) QCoreApplication::postEvent(fingerTraces.at(iFingerCounter), new QHideEvent()); iHandToFingerShift = hand.isLeft() ? 0 : 5; if(ui.checkBox_ShowFingers->isChecked()) { for (int iFingerCounter = iHandToFingerShift; iFingerCounter <= iHandToFingerShift + 4; iFingerCounter ++) QCoreApplication::postEvent(fingerTraces.at(iFingerCounter), new QShowEvent()); } } else if (hands.isEmpty()) { foreach (FingerTraceWindow * fTrace, fingerTraces) QCoreApplication::postEvent(fTrace, new QHideEvent()); // QCoreApplication::postEvent(thumbTrace, new QHideEvent()); // QCoreApplication::postEvent(indexTrace, new QHideEvent()); // QCoreApplication::postEvent(middleTrace, new QHideEvent()); // QCoreApplication::postEvent(ringTrace, new QHideEvent()); // QCoreApplication::postEvent(pinkieTrace, new QHideEvent()); } else { if(ui.checkBox_ShowFingers->isChecked()) { foreach (FingerTraceWindow * fTrace, fingerTraces) QCoreApplication::postEvent(fTrace, new QShowEvent()); } // QCoreApplication::postEvent(thumbTrace, new QShowEvent()); // QCoreApplication::postEvent(indexTrace, new QShowEvent()); // QCoreApplication::postEvent(middleTrace, new QShowEvent()); // QCoreApplication::postEvent(ringTrace, new QShowEvent()); // QCoreApplication::postEvent(pinkieTrace, new QShowEvent()); } for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) { // Get the first hand hand = *hl; //TODO: Perhaps move this to gestures? if (ui.checkBox_Crunch->isChecked()) { if (hands.count() == 2) { // we check if one hand's dragging and the other's closed if (hand.isLeft()) { // if this hand is left, and the other hand (right) is dragging something.. if (debugWindowDrag_Right.left != -1) { debugDisplayString = QString::number(hand.grabStrength()); //pretty much closed if (hand.grabStrength() >= 0.7) { SendMessage(debugWindowHWND_Right, WM_SYSCOMMAND, SC_CLOSE, 0); // DestroyWindow(); } } } else { // if this hand is left, and the other hand (right) is dragging something.. if (debugWindowDrag_Left.left != -1) { //pretty much closed if (hand.grabStrength() >= 0.7) { // DestroyWindow(debugWindowHWND_Left); SendMessage(debugWindowHWND_Left, WM_SYSCOMMAND, SC_CLOSE, 0); } } } } } // 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 // debugDisplayString = QString(", palm position: " + QString(hand.palmPosition().toString().data() )); // debugDisplayString = QString::number(hand.palmPosition().x); //20 // debugDisplayString.append("\n"); // debugDisplayString.append(QString::number(hand.palmPosition().y)); // 5 // debugDisplayString.append("\n"); // debugDisplayString.append(QString::number(hand.palmPosition().z)); // debugDisplayString.append("\n"); // debugDisplayString.append("roll:" + QString::number(normal.roll())); ///-------------------------------------------------- if (debug_extendedFingerCounter != 0 && ui.checkBox_palmMouse->isChecked()) HandCursorPosition(hand.stabilizedPalmPosition()); if (ui.checkBox_HandRollDrag->isChecked()) { if (bDebug_HandRollDrag) { if (normal.roll() > 0.7) { bDebug_HandRollDrag = false; if (debug_extendedFingerCounter != 0) MouseKeyboardEmulation::MouseLeftClickDown(); } } } if (!bDebug_HandRollDrag) { if (normal.roll() < 0.5) { bDebug_HandRollDrag = true; MouseKeyboardEmulation::MouseLeftClickUp(); } } ///----------------------------------------------- debug_extendedFingerCounter = 0; foreach (Finger finger, fingers) { if (finger.isExtended()) debug_extendedFingerCounter++; } // Fist Scrolling if (debug_extendedFingerCounter == 0 && ui.checkBox_palmScroll->isChecked()) { if (fFistPositionY == 0) fFistPositionY = hand.palmPosition().y; if (hand.palmPosition().y > fFistPositionY + 10) { float fDifference = hand.palmPosition().y - fFistPositionY + 10; fDifference /= 10; MouseKeyboardEmulation::MouseWheelUp(fDifference); } else if (hand.palmPosition().y < fFistPositionY - 10) { float fDifference = abs(hand.palmPosition().y - fFistPositionY - 10); fDifference /= 10; MouseKeyboardEmulation::MouseWheelUp(-1 * fDifference); } // debugDisplayString = QString::number(ThumbMiddleDifference_X); //20 // debugDisplayString.append("\n"); // debugDisplayString.append(QString::number(abs(middleFinger.stabilizedTipPosition().y - indexFinger.stabilizedTipPosition().y))); // 5 // debugDisplayString.append("\n"); // debugDisplayString.append(QString::number(debug_extendedFingerCounter)); //works // if(direction.pitch() * RAD_TO_DEG > 30) // MouseKeyboardEmulation::MouseWheelUp((direction.pitch() * RAD_TO_DEG)/10); // if(direction.pitch() * RAD_TO_DEG < 30) // MouseKeyboardEmulation::MouseWheelDown(5); } else { if (fFistPositionY != 0) fFistPositionY = 0; } // 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 fingers = hand.fingers(); FingerLogic(hand.isLeft() ? handLeft : handRight); } }