本文整理汇总了C++中Finger::tipPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Finger::tipPosition方法的具体用法?C++ Finger::tipPosition怎么用?C++ Finger::tipPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Finger
的用法示例。
在下文中一共展示了Finger::tipPosition方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: sample
void AirwritingListener::sample(const Finger &finger, unsigned long long timestamp) {
if (finger.type() == FINGER_INDEX) {
if ((sampling) && (timestamp - lastTimestamp > GESTURE_TAP_MIN_TIMESTAMP_DELTA)) {
float x = finger.tipPosition().x;
float y = finger.tipPosition().y;
float z = finger.tipPosition().z;
if ((y > FINGER_Y_MIN) && (y < FINGER_Y_MAX)) {
if ((fabs(x) < FINGER_X_MAX) && (fabs(z) < FINGER_Z_MAX)) {
Canvas::getInstance()->setPixel(x / FINGER_X_MAX, z / FINGER_Z_MAX, y / 10);
}
}
}
}
}
示例3: drawFinger
//--------------------------------------------------------------
void LeapVisualizer::drawFinger (const Finger & finger,ofxLeapMotion & leap){
if (finger.isValid()){
// For every bone (i.e. phalange) in the finger,
for (int b=0; b<4; b++) {
// Get each bone;
Bone::Type boneType = static_cast<Bone::Type>(b);
Bone bone = finger.bone(boneType);
if (bone.isValid()){
// Don't consider zero-length bones, such as the Thumb's metacarpal.
if (bone.length() > 0){
drawBone (finger, bone,leap);
} // end if boneLength
} // end if bone isValid()
} // end for each bone
if (bDrawSimple){
// Draw the fingertip, which is an extra point within the last phalange.
ofSetColor(ofColor::white);
ofPoint fingerTipPt = leap.getofPoint ( finger.tipPosition() );
ofDrawSphere(fingerTipPt, finger.width() * 0.05);
}
}
}
示例4: recordFingerXML
//--------------------------------------------------------------
void testApp::recordFingerXML (const Finger & finger){
if (bRecordingThisFrame){
if (finger.isValid()){
Finger::Type fingerType = finger.type();
int fingerTagNum = XML.addTag("F");
if( XML.pushTag("F", fingerTagNum) ){
XML.setValue("TYPE", (int)fingerType, fingerTagNum);
XML.setValue("WIDTH", finger.width(), fingerTagNum);
// Add in the fingerTip point as its own point.
ofPoint fingerTipPt = leap.getofPoint ( finger.tipPosition() );
int tipTagNum = XML.addTag("T");
XML.setValue("T:X", fingerTipPt.x, tipTagNum);
XML.setValue("T:Y", fingerTipPt.y, tipTagNum);
XML.setValue("T:Z", fingerTipPt.z, tipTagNum);
// For every bone (i.e. phalange) in the finger,
for (int b=0; b<4; b++) {
// Get each bone;
Bone::Type boneType = static_cast<Bone::Type>(b);
Bone bone = finger.bone(boneType);
if (bone.isValid()){
// Don't consider zero-length bones, such as the Thumb's metacarpal.
if (bone.length() > 0){
recordBoneXML (finger, bone);
} // end if boneLength
} // end if bone isValid()
} // end for each bone
XML.popTag(); // pop F(INGER)
}
} //end if finger isValid()
}
}
示例5: 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;
}
}
示例6: m_bang
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);
//.........这里部分代码省略.........
示例7: 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();
}
示例8: FingerLogic
void QTVS_Leap::FingerLogic(handIndex hIndex)
{
if (ui.checkBox_gesturesParangus->isChecked())
ParangusGestureLogic();
if (ui.checkBox_gesturesLeap->isChecked())
LeapGestureLogic();
//DEBUG: Atm we cancel
// return;
// 0 -> 4 = left hand
// 5 -> 9 = right hand
// So lets use a shift and no redundant code
int iHandToFingerShift = 0;
if (hIndex == handRight)
iHandToFingerShift += 5;
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;
Leap::Vector position = finger.stabilizedTipPosition();
// Convert Leap::Vector position to Screen Coords
QPoint screenPosition = FingerCursorPosition(position);
// Lerp coords for smoothness if required
int xCoord = lerp(fingerTraces.at(finger.type() + iHandToFingerShift)->geometry().left(), screenPosition.x(), dMouseLerpValue);
int yCoord = lerp(fingerTraces.at(finger.type() + iHandToFingerShift)->geometry().top(), screenPosition.y(), dMouseLerpValue);
// Qt Doesn't allow different threads to overwride gui locations.
// Therefore, the usage of events are well, used.
// This updates visual finger representation to correct location
QMoveEvent *tEvent = new QMoveEvent(QPoint(xCoord, yCoord), fingerTraces.at(finger.type() + iHandToFingerShift)->pos());
QCoreApplication::postEvent(fingerTraces.at(finger.type() + iHandToFingerShift), tEvent);
// Z axis does NOT use stabilized position.
// Stabilized position is generally used for X/Y movement (2D display)
// Therefore Z is updated quite poorely. So we used unStabalized position instead
// Setup position limits (manual testing for values
position = finger.tipPosition();
float zFinger = position.z < 0 ? 0 : position.z > 200 ? 200 : position.z;
// Convert to percentages
// trim lowerend of percentages
zFinger /= 200;
if (zFinger < 0.1) zFinger = 0.1;
if (hIndex == handLeft)
{
if(ui.checkBox_FingerDragsWindows->isChecked())
{
// We're on index finger and its close to screen / center of Z-plane on leap motion
if (finger.type() == leapIndex && zFinger < 0.12)
{
POINT pt;
pt.x = screenPosition.x();
pt.y = screenPosition.y();
// if our rect was reset
// Therefore, we just started to drag
if (debugWindowDrag_Left.left == -1)
{
// Find window under point
// Find window's dimmensions
// Find difference between player's finger coords and window's coords
debugWindowHWND_Left = GetRealParent(WindowFromPoint(pt));
// Set it as active window if need be.
if(debugWindowHWND_Left != GetForegroundWindow() && ui.checkBox_DragSetsActive->isChecked())
{
SetForegroundWindow(debugWindowHWND_Left);
// Backup incase SetForegroundWindow fails
// TODO: Perhaps replace in future? since foreground window DOES faile occasionally.
// SetWindowPos(debugWindowHWND_Left,HWND_TOPMOST,0,0,0,0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
}
// Restore window if maximized Section
WINDOWPLACEMENT wndpl = { sizeof(WINDOWPLACEMENT) };
GetWindowPlacement(debugWindowHWND_Left, &wndpl);
// Determine if window is maximized to begin with
if (wndpl.showCmd == SW_MAXIMIZE)
{
// Setup the restore command and send it
wndpl.showCmd = SW_RESTORE;
SetWindowPlacement(debugWindowHWND_Left, &wndpl);
// Center restored window around player's fingers
int iTempWindowWidth = wndpl.rcNormalPosition.right - wndpl.rcNormalPosition.left;
int iTempWindowHeight = wndpl.rcNormalPosition.bottom - wndpl.rcNormalPosition.top;
MoveWindow(debugWindowHWND_Left, pt.x - iTempWindowWidth / 2, pt.y - iTempWindowHeight / 2,
iTempWindowWidth, iTempWindowHeight, true);
}
//.........这里部分代码省略.........