本文整理汇总了C++中leap::Hand::fingers方法的典型用法代码示例。如果您正苦于以下问题:C++ Hand::fingers方法的具体用法?C++ Hand::fingers怎么用?C++ Hand::fingers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类leap::Hand
的用法示例。
在下文中一共展示了Hand::fingers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawHands
void HandController::drawHands() {
glPushMatrix();
glTranslatef(translation_);
glScalef(scale_, scale_, scale_);
Leap::Frame frame = controller_.frame();
for (int h = 0; h < frame.hands().count(); ++h) {
Leap::Hand hand = frame.hands()[h];
for (int f = 0; f < hand.fingers().count(); ++f) {
Leap::Finger finger = hand.fingers()[f];
// Draw first joint inside hand.
Leap::Bone mcp = finger.bone(Leap::Bone::Type::TYPE_METACARPAL);
drawJoint(mcp.prevJoint());
for (int b = 0; b < 4; ++b) {
Leap::Bone bone = finger.bone(static_cast<Leap::Bone::Type>(b));
drawJoint(bone.nextJoint());
drawBone(bone);
}
}
}
glPopMatrix();
}
示例2: memset
void eleap::eleap_t::impl_t::onFrame(const Leap::Controller& controller)
{
const Leap::Frame frame = controller.frame();
if (frame.isValid())
{
// send the known hands in this frame, this will handle hands coming and going
const Leap::HandList hands = frame.hands();
{
unsigned long long time_encoded = (0&0xffffffff)<<8 | (DATA_KNOWN_HANDS&0xff);
float *f;
unsigned char *dp;
piw::data_nb_t d = ctx_.allocate_host(time_encoded,INT32_MAX,INT32_MIN,0,BCTVTYPE_INT,sizeof(int32_t),&dp,hands.count(),&f);
memset(f,0,hands.count()*sizeof(int32_t));
*dp = 0;
for(int i = 0; i < hands.count(); ++i)
{
const Leap::Hand hand = hands[i];
if(hand.isValid() && hand.fingers().count() > 1)
{
((int32_t *)f)[i] = hand.id();
}
}
enqueue_fast(d,1);
}
// handle the actual data for the detected hands
for(int i = 0; i < hands.count(); ++i)
{
const Leap::Hand hand = hands[i];
if(hand.isValid() && hand.fingers().count() > 1)
{
unsigned long long time_encoded = (hand.id()&0xffffffff)<<8 | (DATA_PALM_POSITION&0xff);
const Leap::Vector palm_pos = hand.palmPosition();
float *f;
unsigned char *dp;
piw::data_nb_t d = ctx_.allocate_host(time_encoded,600,-600,0,BCTVTYPE_FLOAT,sizeof(float),&dp,3,&f);
memset(f,0,3*sizeof(float));
*dp = 0;
f[0] = piw::normalise(600,-600,0,palm_pos.x);
f[1] = piw::normalise(600,-600,0,palm_pos.y);
f[2] = piw::normalise(600,-600,0,palm_pos.z);
enqueue_fast(d,1);
}
}
}
}
示例3: onFrame
void Quickstart::onFrame(const Leap::Controller &controller) {
// returns the most recent frame. older frames can be accessed by passing in
// a "history" parameter to retrieve an older frame, up to about 60
// (exact number subject to change)
const Leap::Frame frame = controller.frame();
// do nothing unless hands are detected
if (frame.hands().empty())
return;
// first detected hand
const Leap::Hand firstHand = frame.hands()[0];
// first pointable object (finger or tool)
const Leap::PointableList pointables = firstHand.pointables();
if (pointables.empty()) return;
const Leap::Pointable firstPointable = pointables[0];
// print velocity on the X axis
cout << "Pointable X velocity: " << firstPointable.tipVelocity()[0] << endl;
const Leap::FingerList fingers = firstHand.fingers();
if (fingers.empty()) return;
for (int i = 0; i < fingers.count(); i++) {
const Leap::Finger finger = fingers[i];
std::cout << "Detected finger " << i << " at position (" <<
finger.tipPosition().x << ", " <<
finger.tipPosition().y << ", " <<
finger.tipPosition().z << ")" << std::endl;
}
}
示例4: get_finger_positions
fdata get_finger_positions()
{
Leap::Frame frame = control.frame();
Leap::FingerList fingers = frame.fingers();
Leap::ToolList tools = frame.tools();
Leap::HandList hands = frame.hands();
//std::vector<std::pair<cl_float4, int>> positions;
fdata hand_data;
int p = 0;
for(int i=0; i<40; i++)
{
hand_data.fingers[i] = 0.0f;
}
///will explode if more than 2
for(int i=0; i<hands.count(); i++)
{
const Leap::Hand hand = hands[i];
Leap::FingerList h_fingers = hand.fingers();
float grab_strength = hand.grabStrength();
hand_data.grab_confidence[i] = grab_strength;
for(int j=0; j<h_fingers.count(); j++)
{
const Leap::Finger finger = h_fingers[j];
float mfingerposx = finger.tipPosition().x;
float mfingerposy = finger.tipPosition().y;
float mfingerposz = finger.tipPosition().z;
//cl_float4 ps = {mfingerposx, mfingerposy, mfingerposz, 0.0f};
//cl_float4 ps = {mfingerposx, mfingerposy, mfingerposz, 0.0f};
int id = finger.id();
hand_data.fingers[p++] = mfingerposx;
hand_data.fingers[p++] = mfingerposy;
hand_data.fingers[p++] = mfingerposz;
hand_data.fingers[p++] = 0.0f;
//positions.push_back(std::pair<cl_float4, int>(ps, id));
}
}
return hand_data;
}
示例5: modeDumpDebugInfo
// This controller mode just dumps out a bunch of the Leap Motion device data, which can then be
// analyzed for other use.
void LLLMImpl::modeDumpDebugInfo(Leap::HandList & hands)
{
S32 numHands = hands.count();
if (numHands == 1)
{
// Get the first hand
Leap::Hand hand = hands[0];
// Check if the hand has any fingers
Leap::FingerList finger_list = hand.fingers();
S32 num_fingers = finger_list.count();
if (num_fingers >= 1)
{ // Calculate the hand's average finger tip position
Leap::Vector pos(0, 0, 0);
Leap::Vector direction(0, 0, 0);
for (size_t i = 0; i < num_fingers; ++i)
{
Leap::Finger finger = finger_list[i];
pos += finger.tipPosition();
direction += finger.direction();
// Lots of log spam
LL_INFOS("LeapMotion") << "Finger " << i << " string is " << finger.toString() << LL_ENDL;
}
pos = Leap::Vector(pos.x/num_fingers, pos.y/num_fingers, pos.z/num_fingers);
direction = Leap::Vector(direction.x/num_fingers, direction.y/num_fingers, direction.z/num_fingers);
LL_INFOS("LeapMotion") << "Hand has " << num_fingers << " fingers with average tip position"
<< " (" << pos.x << ", " << pos.y << ", " << pos.z << ")"
<< " direction (" << direction.x << ", " << direction.y << ", " << direction.z << ")"
<< LL_ENDL;
}
Leap::Vector palm_pos = hand.palmPosition();
Leap::Vector palm_normal = hand.palmNormal();
LL_INFOS("LeapMotion") << "Palm pos " << palm_pos.x
<< ", " << palm_pos.y
<< ", " << palm_pos.z
<< ". Normal: " << palm_normal.x
<< ", " << palm_normal.y
<< ", " << palm_normal.z
<< LL_ENDL;
F32 ball_radius = (F32) hand.sphereRadius();
Leap::Vector ball_center = hand.sphereCenter();
LL_INFOS("LeapMotion") << "Ball pos " << ball_center.x
<< ", " << ball_center.y
<< ", " << ball_center.z
<< ", radius " << ball_radius
<< LL_ENDL;
} // dump_out_data
}
示例6: prepareDataClone
GestureFrame LMRecorder::prepareDataClone(const Leap::Frame frame, double timestamp)
{
GestureFrame outputFrame;
outputFrame.setTimestamp(timestamp);
Leap::HandList handsInFrame = frame.hands();
for(int handIndex=0; handIndex<handsInFrame.count(); handIndex++)
{
Leap::Hand currHand = handsInFrame[handIndex];
//create GestureHand
GestureHand gestureHand(
currHand.id(),
Vertex(currHand.palmPosition().x, currHand.palmPosition().y, currHand.palmPosition().z),
Vertex(0, 0, 0/*currHand.stabilizedPalmPosition().x, currHand.stabilizedPalmPosition().y, currHand.stabilizedPalmPosition().z*/),
Vertex(currHand.palmNormal().x, currHand.palmNormal().y, currHand.palmNormal().z),
Vertex(currHand.direction().x, currHand.direction().y, currHand.direction().z)
);
gestureHand.setOrderValue(currHand.palmPosition().x);
Vertex planeNormalVec = gestureHand.getDirection().crossProduct(gestureHand.getPalmNormal()).getNormalized();
Leap::FingerList fingersInCurrHand = currHand.fingers();
for (int fingerIndex=0; fingerIndex<fingersInCurrHand.count(); fingerIndex++)
{
Leap::Finger currFinger = fingersInCurrHand[fingerIndex];
Leap::Vector leapFingerTipPos = currFinger.tipPosition();
Vertex fingerTipPos(leapFingerTipPos.x, leapFingerTipPos.y, leapFingerTipPos.z);
float distance = getPointDistanceFromPlane(fingerTipPos, gestureHand.getPalmPosition(), planeNormalVec);
//create GestureFinger
GestureFinger gestureFinger(
currFinger.id(),
fingerTipPos,
Vertex(currFinger.stabilizedTipPosition().x, currFinger.stabilizedTipPosition().y, currFinger.stabilizedTipPosition(). z),
Vertex(currFinger.direction().x, currFinger.direction().y, currFinger.direction().z),
currFinger.length(),
currFinger.width()
);
gestureFinger.setOrderValue(distance);
gestureHand.addFinger(gestureFinger);
}
gestureHand.sortFingers();
outputFrame.addHand(gestureHand);
}
outputFrame.sortHands();
}
示例7: leapMenuClosed
void MenuController::leapMenuClosed(const Leap::Controller& controller, const Leap::Frame& frame)
{
Leap::GestureList gestures = frame.gestures();
for (const Leap::Gesture& g : gestures) {
if (g.type() == Leap::Gesture::TYPE_CIRCLE) {
Leap::CircleGesture circle(g);
bool xyPlane = abs(circle.normal().dot(Leap::Vector(0, 0, 1))) > 0.8f;
if (circle.progress() > 1.0f && xyPlane && circle.radius() > 35.0f) {
Leap::Hand hand = circle.hands().frontmost();
Leap::FingerList fingers = hand.fingers();
if (fingers[1].isValid()) {
pointer_ = fingers[1];
} else if (fingers[2].isValid()) {
pointer_ = fingers[2];
}
bool main = pointer_.isValid() && fingers.extended().count() <= 2;
bool secondary = fingers[Leap::Finger::TYPE_INDEX].isExtended() &&
fingers[Leap::Finger::TYPE_THUMB].isExtended() &&
fingers[Leap::Finger::TYPE_MIDDLE].isExtended() && fingers.extended().count() == 3;
if (main) {
leap_state_ = LeapState::triggered_main;
} else if (secondary && MainController::getInstance().focusLayer() && MainController::getInstance().focusLayer()->contextMenu()) {
leap_state_ = LeapState::triggered_context;
}
}
}
}
}
示例8: onFrame
void SampleListener::onFrame(const Leap::Controller& controller) {
// Get the most recent frame and report some basic information
const Leap::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;
Leap::HandList hands = frame.hands();
for (Leap::HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) {
// Get the first hand
const Leap::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 Leap::Vector normal = hand.palmNormal();
const Leap::Vector direction = hand.direction();
// Calculate the hand's pitch, roll, and yaw angles
std::cout << std::string(2, ' ') << "pitch: " << direction.pitch() * Leap::RAD_TO_DEG << " degrees, "
<< "roll: " << normal.roll() * Leap::RAD_TO_DEG << " degrees, "
<< "yaw: " << direction.yaw() * Leap::RAD_TO_DEG << " degrees" << std::endl;
// Get the Arm bone
Leap::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 Leap::FingerList fingers = hand.fingers();
for (Leap::FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) {
const Leap::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) {
Leap::Bone::Type boneType = static_cast<Leap::Bone::Type>(b);
Leap::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 Leap::ToolList tools = frame.tools();
for (Leap::ToolList::const_iterator tl = tools.begin(); tl != tools.end(); ++tl) {
const Leap::Tool tool = *tl;
std::cout << std::string(2, ' ') << "Tool, id: " << tool.id()
<< ", position: " << tool.tipPosition()
<< ", direction: " << tool.direction() << std::endl;
}
// Get gestures
const Leap::GestureList gestures = frame.gestures();
for (int g = 0; g < gestures.count(); ++g) {
Leap::Gesture gesture = gestures[g];
switch (gesture.type()) {
case Leap::Gesture::TYPE_CIRCLE:
{
Leap::CircleGesture circle = gesture;
std::string clockwiseness;
if (circle.pointable().direction().angleTo(circle.normal()) <= Leap::PI/2) {
clockwiseness = "clockwise";
} else {
clockwiseness = "counterclockwise";
}
// Calculate angle swept since last frame
float sweptAngle = 0;
if (circle.state() != Leap::Gesture::STATE_START) {
Leap::CircleGesture previousUpdate = Leap::CircleGesture(controller.frame(1).gesture(circle.id()));
sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * Leap::PI;
}
std::cout << std::string(2, ' ')
<< "Circle id: " << gesture.id()
<< ", state: " << stateNames[gesture.state()]
<< ", progress: " << circle.progress()
<< ", radius: " << circle.radius()
<< ", angle " << sweptAngle * Leap::RAD_TO_DEG
<< ", " << clockwiseness << std::endl;
break;
}
case Leap::Gesture::TYPE_SWIPE:
{
Leap::SwipeGesture swipe = gesture;
std::cout << std::string(2, ' ')
<< "Swipe id: " << gesture.id()
<< ", state: " << stateNames[gesture.state()]
//.........这里部分代码省略.........
示例9: pos
// This mode tries to move the avatar and camera in Second Life. It's pretty rough and needs a lot of work
void LLLMImpl::modeMoveAndCamTest1(Leap::HandList & hands)
{
S32 numHands = hands.count();
if (numHands == 1)
{
// Get the first hand
Leap::Hand hand = hands[0];
// Check if the hand has any fingers
Leap::FingerList finger_list = hand.fingers();
S32 num_fingers = finger_list.count();
F32 orbit_rate = 0.f;
Leap::Vector pos(0, 0, 0);
for (size_t i = 0; i < num_fingers; ++i)
{
Leap::Finger finger = finger_list[i];
pos += finger.tipPosition();
}
pos = Leap::Vector(pos.x/num_fingers, pos.y/num_fingers, pos.z/num_fingers);
if (num_fingers == 1)
{ // 1 finger - move avatar
if (pos.x < -LM_DEAD_ZONE)
{ // Move left
gAgent.moveLeftNudge(1.f);
}
else if (pos.x > LM_DEAD_ZONE)
{
gAgent.moveLeftNudge(-1.f);
}
/*
if (pos.z < -LM_DEAD_ZONE)
{
gAgent.moveAtNudge(1.f);
}
else if (pos.z > LM_DEAD_ZONE)
{
gAgent.moveAtNudge(-1.f);
} */
if (pos.y < -LM_DEAD_ZONE)
{
gAgent.moveYaw(-1.f);
}
else if (pos.y > LM_DEAD_ZONE)
{
gAgent.moveYaw(1.f);
}
} // end 1 finger
else if (num_fingers == 2)
{ // 2 fingers - move camera around
// X values run from about -170 to +170
if (pos.x < -LM_DEAD_ZONE)
{ // Camera rotate left
gAgentCamera.unlockView();
orbit_rate = (llabs(pos.x) - LM_DEAD_ZONE) / LM_ORBIT_RATE_FACTOR;
gAgentCamera.setOrbitLeftKey(orbit_rate);
}
else if (pos.x > LM_DEAD_ZONE)
{
gAgentCamera.unlockView();
orbit_rate = (pos.x - LM_DEAD_ZONE) / LM_ORBIT_RATE_FACTOR;
gAgentCamera.setOrbitRightKey(orbit_rate);
}
if (pos.z < -LM_DEAD_ZONE)
{ // Camera zoom in
gAgentCamera.unlockView();
orbit_rate = (llabs(pos.z) - LM_DEAD_ZONE) / LM_ORBIT_RATE_FACTOR;
gAgentCamera.setOrbitInKey(orbit_rate);
}
else if (pos.z > LM_DEAD_ZONE)
{ // Camera zoom out
gAgentCamera.unlockView();
orbit_rate = (pos.z - LM_DEAD_ZONE) / LM_ORBIT_RATE_FACTOR;
gAgentCamera.setOrbitOutKey(orbit_rate);
}
if (pos.y < -LM_DEAD_ZONE)
{ // Camera zoom in
gAgentCamera.unlockView();
orbit_rate = (llabs(pos.y) - LM_DEAD_ZONE) / LM_ORBIT_RATE_FACTOR;
gAgentCamera.setOrbitUpKey(orbit_rate);
}
else if (pos.y > LM_DEAD_ZONE)
{ // Camera zoom out
gAgentCamera.unlockView();
orbit_rate = (pos.y - LM_DEAD_ZONE) / LM_ORBIT_RATE_FACTOR;
gAgentCamera.setOrbitDownKey(orbit_rate);
}
} // end 2 finger
}
}
示例10: if
// This mode tries to detect simple hand motion and either triggers an avatar gesture or
// sends a chat message into SL in response. It is very rough, hard-coded for detecting
// a hand wave (a SL gesture) or the wiggling-thumb gun trigger (a chat message sent to a
// special version of the popgun).
void LLLMImpl::modeGestureDetection1(Leap::HandList & hands)
{
static S32 trigger_direction = -1;
S32 numHands = hands.count();
if (numHands == 1)
{
// Get the first hand
Leap::Hand hand = hands[0];
// Check if the hand has any fingers
Leap::FingerList finger_list = hand.fingers();
S32 num_fingers = finger_list.count();
static S32 last_num_fingers = 0;
if (num_fingers == 1)
{ // One finger ... possibly reset the
Leap::Finger finger = finger_list[0];
Leap::Vector finger_dir = finger.direction();
// Negative Z is into the screen - check that it's the largest component
S32 abs_z_dir = llabs(finger_dir.z);
if (finger_dir.z < -0.5 &&
abs_z_dir > llabs(finger_dir.x) &&
abs_z_dir > llabs(finger_dir.y))
{
Leap::Vector finger_pos = finger.tipPosition();
Leap::Vector finger_vel = finger.tipVelocity();
LL_INFOS("LeapMotion") << "finger direction is " << finger_dir.x << ", " << finger_dir.y << ", " << finger_dir.z
<< ", position " << finger_pos.x << ", " << finger_pos.y << ", " << finger_pos.z
<< ", velocity " << finger_vel.x << ", " << finger_vel.y << ", " << finger_vel.z
<< LL_ENDL;
}
if (trigger_direction != -1)
{
LL_INFOS("LeapMotion") << "Reset trigger_direction - one finger" << LL_ENDL;
trigger_direction = -1;
}
}
else if (num_fingers == 2)
{
Leap::Finger barrel_finger = finger_list[0];
Leap::Vector barrel_finger_dir = barrel_finger.direction();
// Negative Z is into the screen - check that it's the largest component
F32 abs_z_dir = llabs(barrel_finger_dir.z);
if (barrel_finger_dir.z < -0.5f &&
abs_z_dir > llabs(barrel_finger_dir.x) &&
abs_z_dir > llabs(barrel_finger_dir.y))
{
Leap::Finger thumb_finger = finger_list[1];
Leap::Vector thumb_finger_dir = thumb_finger.direction();
Leap::Vector thumb_finger_pos = thumb_finger.tipPosition();
Leap::Vector thumb_finger_vel = thumb_finger.tipVelocity();
if ((thumb_finger_dir.x < barrel_finger_dir.x) )
{ // Trigger gunfire
if (trigger_direction < 0 && // Haven't fired
thumb_finger_vel.x > 50.f && // Moving into screen
thumb_finger_vel.z < -50.f &&
mChatMsgTimer.checkExpirationAndReset(LLLEAP_CHAT_MSG_INTERVAL))
{
// Chat message looks like "/2343 LM2 gunfire"
std::string gesture_chat_msg("/2343 LM2 gunfire");
//LLNearbyChatBar::sendChatFromViewer(gesture_chat_msg, CHAT_TYPE_SHOUT, FALSE);
trigger_direction = 1;
LL_INFOS("LeapMotion") << "Sent gunfire chat" << LL_ENDL;
}
else if (trigger_direction > 0 && // Have fired, need to pull thumb back
thumb_finger_vel.x < -50.f &&
thumb_finger_vel.z > 50.f) // Moving out of screen
{
trigger_direction = -1;
LL_INFOS("LeapMotion") << "Reset trigger_direction" << LL_ENDL;
}
}
}
else if (trigger_direction != -1)
{
LL_INFOS("LeapMotion") << "Reset trigger_direction - hand pos" << LL_ENDL;
trigger_direction = -1;
}
}
else if (num_fingers == 5 &&
num_fingers == last_num_fingers)
{
if (mGestureTimer.checkExpirationAndReset(LLLEAP_GESTURE_INTERVAL))
{
// figure out a gesture to trigger
std::string gestureString("/overhere");
LLGestureMgr::instance().triggerAndReviseString( gestureString );
}
}
last_num_fingers = num_fingers;
//.........这里部分代码省略.........
示例11: modeFlyingControlTest
// This controller mode is used to fly the avatar, going up, down, forward and turning.
void LLLMImpl::modeFlyingControlTest(Leap::HandList & hands)
{
static S32 sLMFlyingHysteresis = 0;
S32 numHands = hands.count();
BOOL agent_is_flying = gAgent.getFlying();
if (numHands == 0
&& agent_is_flying
&& sLMFlyingHysteresis > 0)
{
sLMFlyingHysteresis--;
if (sLMFlyingHysteresis == 0)
{
LL_INFOS("LeapMotion") << "LM stop flying - look ma, no hands!" << LL_ENDL;
gAgent.setFlying(FALSE);
}
}
else if (numHands == 1)
{
// Get the first hand
Leap::Hand hand = hands[0];
// Check if the hand has any fingers
Leap::FingerList finger_list = hand.fingers();
S32 num_fingers = finger_list.count();
Leap::Vector palm_pos = hand.palmPosition();
Leap::Vector palm_normal = hand.palmNormal();
F32 ball_radius = (F32) hand.sphereRadius();
Leap::Vector ball_center = hand.sphereCenter();
// Number of fingers controls flying on / off
if (num_fingers == 0 && // To do - add hysteresis or data smoothing?
agent_is_flying)
{
if (sLMFlyingHysteresis > 0)
{
sLMFlyingHysteresis--;
}
else
{
LL_INFOS("LeapMotion") << "LM stop flying" << LL_ENDL;
gAgent.setFlying(FALSE);
}
}
else if (num_fingers > 2 &&
!agent_is_flying)
{
LL_INFOS("LeapMotion") << "LM start flying" << LL_ENDL;
gAgent.setFlying(TRUE);
sLMFlyingHysteresis = 5;
}
// Radius of ball controls forward motion
if (agent_is_flying)
{
if (ball_radius > 110.f)
{ // Open hand, move fast
gAgent.setControlFlags(AGENT_CONTROL_AT_POS | AGENT_CONTROL_FAST_AT);
}
else if (ball_radius > 85.f)
{ // Partially open, move slow
gAgent.setControlFlags(AGENT_CONTROL_AT_POS);
}
else
{ // Closed - stop
gAgent.clearControlFlags(AGENT_CONTROL_AT_POS);
}
// Height of palm controls moving up and down
if (palm_pos.y > 260.f)
{ // Go up fast
gAgent.setControlFlags(AGENT_CONTROL_UP_POS | AGENT_CONTROL_FAST_UP);
}
else if (palm_pos.y > 200.f)
{ // Go up
gAgent.setControlFlags(AGENT_CONTROL_UP_POS);
}
else if (palm_pos.y < 60.f)
{ // Go down fast
gAgent.setControlFlags(AGENT_CONTROL_FAST_UP | AGENT_CONTROL_UP_NEG);
}
else if (palm_pos.y < 120.f)
{ // Go down
gAgent.setControlFlags(AGENT_CONTROL_UP_NEG);
}
else
{ // Clear up / down
gAgent.clearControlFlags(AGENT_CONTROL_FAST_UP | AGENT_CONTROL_UP_POS | AGENT_CONTROL_UP_NEG);
}
// Palm normal going left / right controls direction
if (mYawTimer.checkExpirationAndReset(LLLEAP_YAW_INTERVAL))
{
if (palm_normal.x > 0.4f)
{ // Go left fast
//.........这里部分代码省略.........
示例12: finger_count_comparator
bool finger_count_comparator (Leap::Hand a, Leap::Hand b) { return a.fingers().count() > b.fingers().count(); }
示例13: if
void jester::LeapMotionImpl::processFingers(Leap::Hand hand, Bone::BoneId fingerOne, LeapHand whichHand) {
Leap::FingerList fingerList = hand.fingers();
std::vector<Leap::Finger> fingers;
FingerData *fingerIds = (whichHand == LeapHand::LEFT ? kLeftFingerIds : kRightFingerIds);
bool fingersFound[] = {false, false, false, false, false};
//project finger tip positions onto palm plane and calculate angle
for (Leap::FingerList::const_iterator fingerIter = fingerList.begin(); fingerIter != fingerList.end(); fingerIter++) {
fingers.push_back(*fingerIter);
}
//if this is the first time we've seen the full hand, calibrate the finger lengths
if (fingerIds[0].id == -1 && fingers.size() == 5) {
if (whichHand == LeapHand::LEFT)
std::sort(fingers.begin(), fingers.end(), left_hand_finger_x_coordinate_comparator);
else if (whichHand == LeapHand::RIGHT)
std::sort(fingers.begin(), fingers.end(), right_hand_finger_x_coordinate_comparator);
else
return;
fingersFound[0] = fingersFound[1] = fingersFound[2] = fingersFound[3] = fingersFound[4] = true;
for (int i = 0; i < 5; i++) {
fingerIds[i].id = fingers[i].id();
fingerIds[i].length = fingers[i].length();
}
} else if (fingerIds[0].id == -1)
return;
//search for all of the known finger ids
for (unsigned int i = 0; i < 5; i++) {
for (unsigned int j = 0; j < fingers.size(); j++) {
if (fingers[j].id() == fingerIds[i].id) {
fingersFound[i] = true;
setFingerInJointData(fingers[j], static_cast<Bone::BoneId>(fingerOne + i));
fingers.erase(fingers.begin() + j);
}
}
}
//match all unclaimed fingers based on closest size
for (unsigned int i = 0; i < fingers.size(); i++) {
float closestLengthDelta = FLT_MAX;
int closestFingerIx = -1;
for (int j = 0; j < 5; j++) {
if (!fingersFound[j]) {
float lengthDelta = abs(fingerIds[j].length - fingers[i].length());
if (lengthDelta < closestLengthDelta) {
closestLengthDelta = lengthDelta;
closestFingerIx = j;
}
}
}
if (closestFingerIx >= 0) {
fingersFound[closestFingerIx] = true;
fingerIds[closestFingerIx].id = fingers[i].id();
setFingerInJointData(fingers[i], static_cast<Bone::BoneId>(fingerOne + closestFingerIx));
}
}
}
示例14: nextFrame
void LeapManager::nextFrame(Avatar& avatar) {
// Apply the frame data directly to the avatar.
Hand& hand = avatar.getHand();
// If we actually get valid Leap data, this will be set to true;
bool gotRealData = false;
if (controllersExist()) {
_listener->onFrame(*_controller);
}
#ifndef LEAP_STUBS
if (controllersExist()) {
gotRealData = true;
// First, see which palms and fingers are still valid.
Leap::Frame& frame = _listener->lastFrame;
// Note that this is O(n^2) at worst, but n is very small.
// After this many frames of no data, assume the digit is lost.
const int assumeLostAfterFrameCount = 10;
// Increment our frame data counters
for (size_t i = 0; i < hand.getNumPalms(); ++i) {
PalmData& palm = hand.getPalms()[i];
palm.incrementFramesWithoutData();
if (palm.getFramesWithoutData() > assumeLostAfterFrameCount) {
palm.setActive(false);
}
for (size_t f = 0; f < palm.getNumFingers(); ++f) {
FingerData& finger = palm.getFingers()[f];
finger.incrementFramesWithoutData();
if (finger.getFramesWithoutData() > assumeLostAfterFrameCount) {
finger.setActive(false);
}
}
}
size_t numLeapHands = frame.hands().count();
std::vector<PalmData*> palmAssignment(numLeapHands);
// Look for matches
for (size_t index = 0; index < numLeapHands; ++index) {
PalmData* takeoverCandidate = NULL;
palmAssignment[index] = NULL;
Leap::Hand leapHand = frame.hands()[index];
int id = leapHand.id();
if (leapHand.isValid()) {
for (size_t i = 0; i < hand.getNumPalms() && palmAssignment[index] == NULL; ++i) {
PalmData& palm = hand.getPalms()[i];
if (palm.getLeapID() == id) {
// Found hand with the same ID. We're set!
palmAssignment[index] = &palm;
palm.resetFramesWithoutData();
}
else if (palm.getFramesWithoutData() > assumeLostAfterFrameCount) {
takeoverCandidate = &palm;
}
}
if (palmAssignment[index] == NULL) {
palmAssignment[index] = takeoverCandidate;
}
if (palmAssignment[index] == NULL) {
palmAssignment[index] = &hand.addNewPalm();
}
}
}
// Apply the assignments
for (size_t index = 0; index < numLeapHands; ++index) {
if (palmAssignment[index]) {
Leap::Hand leapHand = frame.hands()[index];
PalmData& palm = *(palmAssignment[index]);
palm.resetFramesWithoutData();
palm.setLeapID(leapHand.id());
palm.setActive(true);
const Leap::Vector pos = leapHand.palmPosition();
const Leap::Vector normal = leapHand.palmNormal();
palm.setRawPosition(glm::vec3(pos.x, pos.y, pos.z));
palm.setRawNormal(glm::vec3(normal.x, normal.y, normal.z));
}
}
// Look for fingers per palm
for (size_t i = 0; i < hand.getNumPalms(); ++i) {
PalmData& palm = hand.getPalms()[i];
if (palm.isActive()) {
Leap::Hand leapHand = frame.hand(palm.getLeapID());
if (leapHand.isValid()) {
int numLeapFingers = leapHand.fingers().count();
std::vector<FingerData*> fingerAssignment(numLeapFingers);
// Look for matches
for (size_t index = 0; index < numLeapFingers; ++index) {
FingerData* takeoverCandidate = NULL;
fingerAssignment[index] = NULL;
Leap::Finger leapFinger = leapHand.fingers()[index];
int id = leapFinger.id();
//.........这里部分代码省略.........
示例15: InterfaceEventTick
//.........这里部分代码省略.........
//Pinching
float pinchStrength = hand.pinchStrength();
bool pinched = handPinched(pinchStrength);
//While grabbing disable pinching detection, this helps to reduce spam as pose confidence plummets
if (grabbed) pinched = pastHandState.pinched;
else
{
if (pinched)
ILeapEventInterface::Execute_LeapHandPinching(_private->interfaceDelegate, pinchStrength, _private->eventHand);
if (pinched && !pastHandState.pinched)
{
ILeapEventInterface::Execute_LeapHandPinched(_private->interfaceDelegate, pinchStrength, _private->eventHand);
//input mapping
if (_private->eventHand->HandType == LeapHandType::HAND_LEFT)
EmitKeyDownEventForKey(EKeysLeap::LeapLeftPinch, 0, 0);
else
EmitKeyDownEventForKey(EKeysLeap::LeapRightPinch, 0, 0);
}
else if (!pinched && pastHandState.pinched)
{
ILeapEventInterface::Execute_LeapHandUnpinched(_private->interfaceDelegate, pinchStrength, _private->eventHand);
//input mapping
if (_private->eventHand->HandType == LeapHandType::HAND_LEFT)
EmitKeyUpEventForKey(EKeysLeap::LeapLeftPinch, 0, 0);
else
EmitKeyUpEventForKey(EKeysLeap::LeapRightPinch, 0, 0);
}
}
//-Fingers-
Leap::FingerList fingers = hand.fingers();
//Count
int fingerCount = fingers.count();
if ((pastHandState.fingerCount != fingerCount))
ILeapEventInterface::Execute_FingerCountChanged(_private->interfaceDelegate, fingerCount);
if (_private->eventFinger == NULL)
{
_private->eventFinger = NewObject<ULeapFinger>(this);
_private->eventFinger->SetFlags(RF_RootSet);
}
Leap::Finger finger;
//Cycle through each finger
for (int j = 0; j < fingerCount; j++)
{
finger = fingers[j];
_private->eventFinger->setFinger(finger);
//Finger Moved
if (finger.isValid())
ILeapEventInterface::Execute_LeapFingerMoved(_private->interfaceDelegate, _private->eventFinger);
}
//Do these last so we can easily override debug shapes
//Leftmost
finger = fingers.leftmost();
_private->eventFinger->setFinger(finger);
ILeapEventInterface::Execute_LeapLeftMostFingerMoved(_private->interfaceDelegate, _private->eventFinger);