本文整理汇总了C++中Hand::fingers方法的典型用法代码示例。如果您正苦于以下问题:C++ Hand::fingers方法的具体用法?C++ Hand::fingers怎么用?C++ Hand::fingers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hand
的用法示例。
在下文中一共展示了Hand::fingers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getIndexFingertip
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);
}
示例2: recordHandXML
//--------------------------------------------------------------
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)
}
}
}
}
示例3: draw
//--------------------------------------------------------------
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);
}
示例4: onFrame
//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);
}
示例5: getGesture
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;
}
示例6: drawFingers
//--------------------------------------------------------------
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
}
示例7: updateCursorLocation
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;
}
}
示例8: onFrame
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;
//.........这里部分代码省略.........
示例9: onFrame
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;
}
}
示例10: main
//.........这里部分代码省略.........
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();
}
示例11: onFrame
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;
// }
//
// }
//}
}
示例12: frame
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();
}
示例13: update
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();
}
示例14: drawHands
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();
}
示例15: drawPalm
//--------------------------------------------------------------
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);
}
}
}
}
}