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; }
mat4 toMat4( const Leap::Matrix& m ) { mat4 mat; Leap::FloatArray a = m.toArray4x4(); for ( size_t x = 0; x < 4; ++x ) { for ( size_t y = 0; y < 4; ++y ) { mat[ x ][ y ] = a[ y * 4 + x ]; } } return mat; }
mat3 toMat3( const Leap::Matrix& m ) { mat3 mat; Leap::FloatArray a = m.toArray3x3(); for ( size_t x = 0; x < 3; ++x ) { for ( size_t y = 0; y < 3; ++y ) { mat[ x ][ y ] = a[ y * 3 + x ]; } } return mat; }
Matrix44f toMatrix44f( const Leap::Matrix& m ) { Matrix44f mtx; Leap::FloatArray a = m.toArray4x4(); for ( size_t i = 0; i < 4; ++i ) { size_t j = i * 4; Vec4f row( a[ j + 0 ], a[ j + 1 ], a[ j + 2 ], a[ j + 3 ] ); mtx.setRow( i, row ); } return mtx; }
Matrix33f toMatrix33f( const Leap::Matrix& m ) { Matrix33f mtx; Leap::FloatArray a = m.toArray3x3(); for ( size_t i = 0; i < 3; ++i ) { size_t j = i * 3; Vec3f row( a[ j + 0 ], a[ j + 1 ], a[ j + 2 ] ); mtx.setRow( i, row ); } return mtx; }