本文整理汇总了C++中leap::Hand类的典型用法代码示例。如果您正苦于以下问题:C++ Hand类的具体用法?C++ Hand怎么用?C++ Hand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Hand类的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: 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;
}
}
示例3: modeStreamDataToSL
// This experimental mode sends chat messages into SL on a back channel for LSL scripts
// to intercept with a listen() event. This is experimental and not sustainable for
// a production feature ... many avatars using this would flood the chat system and
// hurt server performance. Depending on how useful this proves to be, a better
// mechanism should be designed to stream data from the viewer into SL scripts.
void LLLMImpl::modeStreamDataToSL(Leap::HandList & hands)
{
S32 numHands = hands.count();
if (numHands == 1 &&
mChatMsgTimer.checkExpirationAndReset(LLLEAP_CHAT_MSG_INTERVAL))
{
// Get the first (and only) hand
Leap::Hand hand = hands[0];
Leap::Vector palm_pos = hand.palmPosition();
Leap::Vector palm_normal = hand.palmNormal();
F32 ball_radius = (F32) hand.sphereRadius();
Leap::Vector ball_center = hand.sphereCenter();
// Chat message looks like "/2343 LM1,<palm pos>,<palm normal>,<sphere center>,<sphere radius>"
LLVector3 vec;
std::stringstream status_chat_msg;
status_chat_msg << "/2343 LM,";
status_chat_msg << "<" << palm_pos.x << "," << palm_pos.y << "," << palm_pos.z << ">,";
status_chat_msg << "<" << palm_normal.x << "," << palm_normal.y << "," << palm_normal.z << ">,";
status_chat_msg << "<" << ball_center.x << "," << ball_center.y << "," << ball_center.z << ">," << ball_radius;
FSNearbyChat::instance().sendChatFromViewer(status_chat_msg.str(), CHAT_TYPE_SHOUT, FALSE);
}
}
示例4: evaluate
/**
Returns
1 if abs(xvel) <= 1/2 abs(yvel)
0 otherwise
*/
virtual int evaluate(const Leap::Frame &frame,
const std::string& nodeid) {
Leap::Hand h = frame.hand(0);
if (h.isValid()) {
Leap::Vector vel = h.palmVelocity();
return (abs(vel.x) <= 0.5 * abs(vel.y))
? 1 : 0;
} else
return 0;
}
示例5: 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;
}
示例6: handForId
bool handForId(int32 checkId, Leap::HandList hands, Leap::Hand& returnHand)
{
for (int i = 0; i < hands.count(); i++)
{
Leap::Hand hand = hands[i];
if (checkId == hand.id()){
returnHand = hand;
return true;
}
}
return false;
}
示例7: HandForId
bool FLeapMotionInputDevice::HandForId(int32 CheckId, Leap::HandList Hands, Leap::Hand& ReturnHand)
{
for (int i = 0; i < Hands.count(); i++)
{
Leap::Hand Hand = Hands[i];
if (CheckId == Hand.id())
{
ReturnHand = Hand;
return true;
}
}
return false;
}
示例8: frame
virtual void onFrame (const Leap::Controller&)
{
const Leap::Frame frame(m_Controller.frame(0));
const Leap::Hand hand(frame.hands().rightmost());
if (!hand.isValid())
{
m_LastNormalizedPos.reset();
return;
}
const Leap::Vector pos(hand.palmPosition());
m_LastNormalizedPos = frame.interactionBox().normalizePoint(pos);
}
示例9:
void jester::LeapMotionImpl::processHand(Leap::Hand hand, LeapHand whichHand) {
Bone::JointId toSet = (whichHand == LeapHand::LEFT ? Bone::JointId::WRIST_L : Bone::JointId::WRIST_R);
Bone::BoneId firstFinger = (whichHand == LeapHand::LEFT ? Bone::BoneId::PHALANX_L_1 : Bone::BoneId::PHALANX_R_1);
JointFusionData wristData;
wristData.confidence = LeapConfidence;
wristData.position = glm::vec3(hand.palmPosition()[0] / LeapMeasurmentScalingFactor,
hand.palmPosition()[1] / LeapMeasurmentScalingFactor,
hand.palmPosition()[2] / LeapMeasurmentScalingFactor);
wristData.id = toSet;
kJointData.insert(std::pair<Bone::JointId, JointFusionData>(toSet, wristData));
processFingers(hand, firstFinger, whichHand);
}
示例10: eventShake
int StateKen::eventShake(StateContext& context, const Leap::Controller& controller)
{
std::cout << "けん\n" << std::endl;
const Leap::Frame frame = controller.frame();
const Leap::Hand hand = frame.hands()[0];
Leap::Vector position = hand.palmPosition();
JankenApp::getInstance()->setShakeStartPosition(position);
int ret = context.changeState(StatePon::getInstance());
return ret;
}
示例11: 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);
}
}
}
}
示例12: convertHandRotation
void convertHandRotation(const Leap::Hand& hand, MatrixF& outRotation)
{
// We need to convert from Motion coordinates to
// Torque coordinates. The conversion is:
//
// Motion Torque
// a b c a b c a -c b
// d e f --> -g -h -i --> -g i -h
// g h i d e f d -f e
const Leap::Vector& handToFingers = hand.direction();
Leap::Vector handFront = -handToFingers;
const Leap::Vector& handDown = hand.palmNormal();
Leap::Vector handUp = -handDown;
Leap::Vector handRight = handUp.cross(handFront);
outRotation.setColumn(0, Point4F( handRight.x, -handRight.z, handRight.y, 0.0f));
outRotation.setColumn(1, Point4F( -handFront.x, handFront.z, -handFront.y, 0.0f));
outRotation.setColumn(2, Point4F( handUp.x, -handUp.z, handUp.y, 0.0f));
outRotation.setPosition(Point3F::Zero);
}
示例13: onFrame
void LeapListener::onFrame(const Controller& controller) {
const Frame frame = controller.frame();
static int64_t lastFrameID = 0;
if(frame.id() < lastFrameID+10)
return;
Leap::HandList hands = frame.hands();
Leap::Hand hand = hands[0];
if(hand.isValid()) {
float pitch = hand.direction().pitch();
float yaw = hand.direction().yaw();
float roll = hand.palmNormal().roll();
float height = hand.palmPosition().y;
std::cout << "Pitch: " << RAD_TO_DEG*pitch << " Yaw: " << RAD_TO_DEG*yaw << " Roll: " << RAD_TO_DEG*roll << " Height: " << height << " Frame: " << frame.id() << std::endl;
// switch(gest.type()) {
// case Gesture::TYPE_CIRCLE:
// std::cout << "Takeoff" << std::endl;
// if (jakopter_takeoff() < 0)
// return;
// break;
// case Gesture::TYPE_SWIPE:
// std::cout << "Land" << std::endl;
// if (jakopter_land() < 0)
// return;
// break;
// default:
// break;
// }
char c = 's';
if (height > 300)
c = 'u';
else if(height < 75)
c = 'k';
else if (height < 150)
c = 'd';
if (roll > 0.7)
c = 'l';
else if (roll < -0.7)
c = 'r';
if (pitch > 0.7)
c = 'b';
else if (pitch < -0.7)
c = 'f';
FILE *cmd = fopen(CMDFILENAME,"w");
fprintf(cmd, "%c\n", c);
fclose(cmd);
}
lastFrameID = frame.id();
}
示例14: recognizedControls
void BallGesture::recognizedControls(const Leap::Controller &controller, std::vector<ControlPtr> &controls) {
Leap::Frame frame = controller.frame();
// hands detected?
if (frame.hands().isEmpty())
return;
for (int i = 0; i < frame.hands().count(); i++) {
// gonna assume the user only has two hands. sometimes leap thinks otherwise.
if (i > 1) break;
Leap::Hand hand = frame.hands()[i];
double radius = hand.sphereRadius(); // in mm
if (! radius)
continue;
BallRadiusPtr bc = make_shared<BallRadius>(radius, i);
ControlPtr cptr = dynamic_pointer_cast<Control>(bc);
controls.push_back(cptr);
}
}
示例15: 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;
}
}
}
}
}