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 Leap::LeapListener::onFrame( const Controller& controller ) { Frame frame = controller.frame(); HandList hands = frame.hands(); Leap::DirectionDetector::Direction direction; //bool handExtended; Hand leftHand; Hand rightHand; //jurik //takin just first gesture (gestures are defined for each finger) Gesture gesture = frame.gestures()[0]; if ( arMode ) { for ( int i=0; i< hands.count(); ++i ) { if ( hands[i].isRight() ) { rightHand = hands[i]; } else { leftHand = hands[i]; } } leapActions->updateARHands( leftHand,rightHand ); } else { for ( int i=0; i< hands.count(); ++i ) { if ( hands[i].isRight() ) { direction = Leap::DirectionDetector::getPalmDirection( hands[i] ); //using cameramanipulator //leapActions->changeViewAngle( direction ); //using pickhandler class leapActions->rotateAruco( direction ); if ( gesture.type() == Gesture::TYPE_KEY_TAP ) { leapActions->scaleNodes( true ); } } else { direction = Leap::DirectionDetector::getPalmDirection( hands[i] ); //leapActions.changeViewAngle( direction ); leapActions->scaleEdges( direction ); if ( gesture.type() == Gesture::TYPE_KEY_TAP ) { leapActions->scaleNodes( false ); } /*handExtended = Leap::FingerPositionDetector::isHandExtended( hands[i] ); if ( handExtended ) { leapActions->startMovingForward(); } else { leapActions->stopMovingForward(); }*/ } } } //std::cout << "id: " << frame.id(); /* const GestureList gestures = frame.gestures(); for (int g = 0; g < gestures.count(); ++g) { Gesture gesture = gestures[g]; HandList hands = gesture.hands(); Hand firstHand = hands[0]; switch (gesture.type()) { case Gesture::TYPE_CIRCLE: { leapActions->zoomGraph(gesture); break; } case Gesture::TYPE_SWIPE: { if(firstHand.isRight()){ if(leapActions->isCameraMoving) leapActions->moveCamera(gesture); else leapActions->rotateGraph(gesture); } break; } case Gesture::TYPE_KEY_TAP: { if(firstHand.isLeft()) leapActions->onKeyTap(gesture); break; } case Gesture::TYPE_SCREEN_TAP: { leapActions->onScreenTap(gesture); break; } default: qDebug() << "Unknown gesture type."; break; } }*/ }
//metodo en bucle que actualiza la informacion de frecuencia, volumen y handsGl void leapMotion::onFrame(const Controller& controller) { const Frame frame = controller.frame(); int j = 0; float mejor = 1000; float mejorVol = 1000; int nada=-1000; Vector vNada = Vector(nada,nada,nada); Matrix mNada = Matrix(vNada,vNada,vNada); HandList hands = frame.hands(); numManos = hands.count(); for(int i=0; i<numManos; i++){ palma[i] = hands[i].palmPosition(); //anchuraPalmas[i] = hands[i].palmWidth(); direccionMano[i] = hands[i].basis(); float distVol=palma[i].y; if((palma[i].x/50)<-4 && (palma[i].x/50)>-7 && distVol<=mejorVol) mejorVol=distVol; //if(distVol<=mejorVol) mejorVol=distVol; for (int f = 0; f < hands[i].fingers().count(); f++) { Finger finger = hands[i].fingers()[f]; for (int b = 0; b < 4; b++) { Bone bone = finger.bone(static_cast<Leap::Bone::Type>(b)); handsGl[i*20+f*4+b]=bone.nextJoint(); float dist=sqrt(pow(4.125-(handsGl[i*20+f*4+b].x/50),2)+pow((-0.75)-(handsGl[i*20+f*4+b].z/50),2)); if(dist<=mejor) mejor=dist; centroHuesos[i*20+f*4+b]=bone.nextJoint(); direccionHuesos[i*20+f*4+b]=bone.basis(); longitudHuesos[i*20+f*4+b]=bone.length(); anchuraHuesos[i*20+f*4+b]=bone.width()/2; } } } for(int i=numManos*20;i<40;i++) handsGl[i] = vNada; for(int i=numManos; i<2; i++) palma[i] = vNada; //for(int i=numManos; i<2; i++) anchuraPalmas[i] = 0; for(int i=numManos; i<2; i++) direccionMano[i] = mNada; for(int i=numManos*20; i<40; i++) direccionHuesos[i] = mNada; for(int i=numManos*20; i<40; i++) centroHuesos[i] = vNada; for(int i=numManos*20; i<40; i++) longitudHuesos[i] = 0; for(int i=numManos*20; i<40; i++) anchuraHuesos[i] = 0; if(mejor<=0.1) freq=7902.13; //se supone que al tocar la antena del theremin, se produce una frecuencia de sonido muy alta else if(mejor<=5){ freq=4000*(1-mejor/5); } else freq=0; if(mejorVol>=250 && mejorVol<=350) volumen=1*((mejorVol-250)/100); else if(mejorVol<250) volumen=0; else volumen=1; }
void LeapListener::onFrame(const Controller &controller){ const Frame frame = controller.frame(); HandList hands = frame.hands(); std::vector<HandModel> myhands; BoneModel mybone; HandModel myhand; //printf("frame: %d\n", frame.id()); float scale = 0.025; float disp = 3.5f; bool record = true; for (int i = 0; i < hands.count(); i++){ FingerList fingers = hands[i].fingers(); myhand.bones.clear(); myhand.references.clear(); Vector handPosition = hands[i].palmPosition(); handPosition *= scale; handPosition.y -= disp; Vector wrist = hands[i].wristPosition(); wrist *= scale; wrist.y -= disp; myhand.palmPosition = handPosition; myhand.palmNormal = hands[i].palmNormal(); myhand.direction = hands[i].direction(); for (int j = 0; j < fingers.count(); j++){ Bone bone; Bone::Type boneType; Vector currentPosition = fingers[j].tipPosition(); currentPosition *= scale; currentPosition.y -= disp; Vector lastPosition = m_lastFrame.finger(fingers[j].id()).tipPosition(); lastPosition *= scale; lastPosition.y -= disp; Vector diff = currentPosition - lastPosition; //printf("%f, %f, %f\n", abs(diff.x), abs(diff.y), abs(diff.z)); //if (abs(diff.x) > 0.2 || abs(diff.y) > 0.2 || abs(diff.z) > 0.2) record = false; if (abs(diff.x) < 0.0001 || abs(diff.y) < 0.0001 || abs(diff.z) < 0.0001) record = false; for (int k = 0; k < 4; k++){ boneType = static_cast<Bone::Type>(k); bone = fingers[j].bone(boneType); if (fingers[j].type() == Finger::Type::TYPE_THUMB && k == 0) continue; Vector prevPos = bone.prevJoint(); prevPos *= scale; prevPos.y -= disp; Vector nextPos = bone.nextJoint(); nextPos *= scale; nextPos.y -= disp; mybone.direction = nextPos - prevPos; mybone.position = (prevPos + nextPos) / 2; mybone.prevJoint = prevPos; mybone.nextJoint = nextPos; mybone.length = bone.length() * scale; if (boneType == Bone::Type::TYPE_PROXIMAL){ if (fingers[j].type() == Finger::Type::TYPE_THUMB){ myhand.thumb = prevPos; //myhand.references.push_back(nextPos); } else{ myhand.references.push_back(prevPos); } } myhand.bones.push_back(mybone); } } myhand.base = myhand.references[3] - myhand.references[0]; Vector disp = myhand.base.normalized() * 0.3f; myhand.references[3] += disp; myhand.references[0] -= disp; //for (int i = 1; i < 5; i++){ // printf("%f\n", myhand.references[i - 1].distanceTo(myhand.references[i])); //} myhands.push_back(myhand); } if (record){ m_hands.clear(); for (int i = 0; i < myhands.size(); i++){ m_hands.push_back(myhands[i]); } } m_lastFrame = frame; }
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 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); } }