本文整理汇总了C++中leap::Frame::hands方法的典型用法代码示例。如果您正苦于以下问题:C++ Frame::hands方法的具体用法?C++ Frame::hands怎么用?C++ Frame::hands使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类leap::Frame
的用法示例。
在下文中一共展示了Frame::hands方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onLeapFrame
void ExampleTool::onLeapFrame( Leap::Frame const &aFrame )
{
mHands = aFrame.hands().count();
mFingers = 0;
for( int i = 0; i < mHands; ++ i )
mFingers += aFrame.hands()[ i ].fingers().count();
}
示例2: 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();
}
示例3: copyFromFrame
void LeapMotionFrame::copyFromFrame(const Leap::Frame& frame, const F32& maxHandAxisRadius)
{
// This also resets all counters
clear();
// Retrieve frame information
mFrameValid = frame.isValid();
mFrameId = frame.id();
mFrameTimeStamp = frame.timestamp();
mFrameInternalId = smNextInternalFrameId;
++smNextInternalFrameId;
mFrameSimTime = Sim::getCurrentTime();
mFrameRealTime = Platform::getRealMilliseconds();
if(!mFrameValid)
{
return;
}
// Retrieve hand information
mHandCount = frame.hands().count();
if(mHandCount > 0)
{
copyFromFrameHands(frame.hands(), maxHandAxisRadius);
}
// Retrieve pointable information
mPointableCount = frame.pointables().count();
if(mPointableCount > 0)
{
copyFromFramePointables(frame.pointables());
}
}
示例4: 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;
}
}
示例5: CopyHandsData
void LeapController::CopyHandsData( LeapFrame & a_frame_internal, Leap::Frame & a_frame_external )
{
const Leap::Device & device = m_ctrl.devices()[0];
a_frame_internal.hands.clear();
a_frame_internal.hands.resize(a_frame_external.hands().count());
a_frame_internal.fingers.clear();
for ( int i_hand = 0; i_hand < a_frame_external.hands().count(); ++i_hand )
{
const Leap::Hand & hand_ext = a_frame_external.hands()[i_hand];
// setup hand
LeapHand & hand = a_frame_internal.hands[i_hand];
hand.id = hand_ext.id();
hand.fingers_count = 0;
hand.dir = toV3( hand_ext.direction() );
hand.palm_normal = toV3( hand_ext.palmNormal() );
hand.palm_pos = toV3( hand_ext.palmPosition() ) * LEAP_SCALE;
hand.palm_vel = toV3( hand_ext.palmVelocity() ) * LEAP_SCALE;
hand.sphere_center = toV3( hand_ext.sphereCenter() ) * LEAP_SCALE;
hand.sphere_radius = hand_ext.sphereRadius() * LEAP_SCALE;
hand.age = hand_ext.timeVisible();
hand.dist_to_boundary = device.distanceToBoundary( hand_ext.palmPosition() ) * LEAP_SCALE;
int hand_ext_finger_count = hand_ext.fingers().count();
// clamp the number of fingers if LEAP bugs out and returns hand with more than 5 fingers
hand_ext_finger_count = max( hand_ext_finger_count, LEAP_MAX_NUM_FINGERS_PER_HAND );
//ASSERT( hand_ext_finger_count <= LEAP_MAX_NUM_FINGERS_PER_HAND );
for( int i_finger = 0; i_finger < hand_ext_finger_count; ++i_finger )
{
const Leap::Finger & finger_ext = hand_ext.fingers()[i_finger];
if ( finger_ext.isValid() )
{
// alloc new finger
a_frame_internal.fingers.resize( a_frame_internal.fingers.size()+1 );
LeapFinger &finger = a_frame_internal.fingers.back();
finger.id = finger_ext.id();
finger.hand_id = hand.id;
finger.hand_index = (int)i_hand;
finger.finger_size = v2( finger_ext.width(), finger_ext.length() ) * LEAP_SCALE;
finger.dir = toV3( finger_ext.direction() );
finger.tip_pos = toV3( finger_ext.tipPosition() ) * LEAP_SCALE;
finger.tip_vel = toV3( finger_ext.tipVelocity() ) * LEAP_SCALE;
finger.age = finger_ext.timeVisible();
finger.tip_pos_stabilized = toV3( finger_ext.stabilizedTipPosition() ) * LEAP_SCALE;
finger.dist_to_boundary = device.distanceToBoundary( finger_ext.tipPosition() ) * LEAP_SCALE;
// add finger
hand.fingers_index[hand.fingers_count] = (int)a_frame_internal.fingers.size()-1;
++hand.fingers_count;
}
}
}
}
示例6: onLeapFrame
void ManipTool::onLeapFrame( Leap::Frame const &aFrame )
{
if( (aFrame.timestamp() - mLastExaminedFrame ) < 16*1000 )
return;
if( aFrame.hands().count() > 2 )
return;
mLastExaminedFrame = aFrame.timestamp();
U16 curFrame = getNextFrameNo( mLastStoredFrame );
Fingers &curFingers = mFingersPerFrame[ curFrame ];
U16 curFinger = 0;
curFingers.clear();
curFingers.mTimestamp = mLastExaminedFrame;
Leap::HandList hands = aFrame.hands();
for( int i = 0; i < hands.count(); ++i )
{
for( int j = 0; j < hands[i].fingers().count(); ++j )
{
Leap::Finger oFinger( hands[i].fingers()[j] );
Finger &oF = curFingers.mFingers[ curFinger++ ];
oF.mId = oFinger.id();
oF.mTimestamp = mLastExaminedFrame;
copy( oFinger.direction(), oF.mDir );
copy( oFinger.tipPosition(), oF.mTip );
oF.mWidth = oFinger.width();
oF.mLength = oFinger.length();
}
}
curFingers.mStoredFingers = curFinger;
if( mTotalStoredFrames > 0 )
{
Fingers &prevFingers = mFingersPerFrame[ mLastStoredFrame ];
for( U16 i = 0; i < curFingers.mStoredFingers; ++i )
{
Finger &curFinger = curFingers.mFingers[i];
Finger const *prevFinger = prevFingers.getFinger( curFinger.mId );
if( !prevFinger )
continue;
subtract( curFinger.mTip, prevFinger->mTip, curFinger.mFromLast );
curFinger.mLenFromLast = normalize( curFinger.mFromLast );
}
}
mLastStoredFrame = curFrame;
++mTotalStoredFrames;
}
示例7: getPinches
pinch_list HandController::getPinches() {
Leap::Frame frame = controller_.frame();
pinch_list pinches;
for (int i = 0; i < frame.hands().count(); ++i) {
float pinch_strength = frame.hands()[i].pinchStrength();
Leap::Vector tip = frame.hands()[i].fingers()[1].tipPosition();
Vec3f transformed_tip = scale_ * ToVec3f(tip) + translation_;
pinches.push_back(std::pair<Vec3f, float>(transformed_tip, pinch_strength));
}
return pinches;
}
示例8: onFrame
void MouseController::onFrame(const Leap::Controller &controller) {
// get list of detected screens
const Leap::ScreenList screens = controller.calibratedScreens();
// make sure we have a detected screen
if (screens.empty()) return;
const Leap::Screen screen = screens[0];
// find the first finger or tool
const Leap::Frame frame = controller.frame();
const Leap::HandList hands = frame.hands();
if (hands.empty()) return;
const Leap::PointableList pointables = hands[0].pointables();
if (pointables.empty()) return;
const Leap::Pointable firstPointable = pointables[0];
// get x, y coordinates on the first screen
const Leap::Vector intersection = screen.intersect(
firstPointable,
true, // normalize
1.0f // clampRatio
);
// if the user is not pointing at the screen all components of
// the returned vector will be Not A Number (NaN)
// isValid() returns true only if all components are finite
if (! intersection.isValid()) return;
unsigned int x = screen.widthPixels() * intersection.x;
// flip y coordinate to standard top-left origin
unsigned int y = screen.heightPixels() * (1.0f - intersection.y);
CGPoint destPoint = CGPointMake(x, y);
CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, destPoint);
}
示例9: draw
void CinderProjectApp::draw()
{
// Clear window
gl::setViewport( getWindowBounds() );
gl::clear( Colorf::black() );
gl::setMatrices( mCamera );
// Iterate through hands
const Leap::HandList& hands = mFrame.hands();
for ( Leap::HandList::const_iterator handIter = hands.begin(); handIter != hands.end(); ++handIter ) {
const Leap::Hand& hand = *handIter;
// Draw palm
gl::color(1, .2, .4, 1);
gl::drawSphere(LeapMotion::toVec3f(hand.palmPosition()),20,12);
// Pointables
const Leap::PointableList& pointables = hand.pointables();
for ( Leap::PointableList::const_iterator pointIter = pointables.begin(); pointIter != pointables.end(); ++pointIter ) {
const Leap::Pointable& pointable = *pointIter;
Vec3f dir = LeapMotion::toVec3f( pointable.direction() );
float length = pointable.length();
Vec3f tipPos = LeapMotion::toVec3f( pointable.tipPosition() );
Vec3f basePos = tipPos + dir * length;
gl::drawColorCube( tipPos, Vec3f( 20, 20, 20 ) );
gl::color( ColorAf::gray( 0.8f ) );
gl::drawLine( basePos, tipPos );
}
}
}
示例10: update
// Runs update logic
void TracerApp::update()
{
// Update frame rate
mFrameRate = getAverageFps();
// Process hand data
const Leap::HandList& hands = mFrame.hands();
for ( Leap::HandList::const_iterator handIter = hands.begin(); handIter != hands.end(); ++handIter ) {
const Leap::Hand& hand = *handIter;
const Leap::PointableList& pointables = hand.pointables();
for ( Leap::PointableList::const_iterator pointIter = pointables.begin(); pointIter != pointables.end(); ++pointIter ) {
const Leap::Pointable& pointable = *pointIter;
int32_t id = pointable.id();
if ( mRibbons.find( id ) == mRibbons.end() ) {
Vec3f v = randVec3f() * 0.01f;
v.x = math<float>::abs( v.x );
v.y = math<float>::abs( v.y );
v.z = math<float>::abs( v.z );
Colorf color( ColorModel::CM_RGB, v );
Ribbon ribbon( id, color );
mRibbons[ id ] = ribbon;
}
float width = math<float>::abs( pointable.tipVelocity().y ) * 0.0025f;
width = math<float>::max( width, 5.0f );
mRibbons[ id ].addPoint( LeapMotion::toVec3f( pointable.tipPosition() ), width );
}
}
// Update ribbons
for ( RibbonMap::iterator iter = mRibbons.begin(); iter != mRibbons.end(); ++iter ) {
iter->second.update();
}
}
示例11: update
// Runs update logic
void UiApp::update()
{
// Update frame rate
mFrameRate = getAverageFps();
// Toggle fullscreen
if ( mFullScreen != isFullScreen() ) {
setFullScreen( mFullScreen );
}
// Interact with first hand
const Leap::HandList& hands = mFrame.hands();
if ( hands.isEmpty() ) {
mCursorType = CursorType::NONE;
} else {
const Leap::Hand& hand = *hands.begin();
// Update cursor position
mCursorPositionTarget = warpVector( hand.palmPosition() );
if ( mCursorType == CursorType::NONE ) {
mCursorPosition = mCursorPositionTarget;
}
// Choose cursor type based on number of exposed fingers
switch ( hand.fingers().count() ) {
case 0:
mCursorType = CursorType::GRAB;
// Slider
if ( mSlider.getBounds().contains( mCursorPosition - mSliderPosition ) ) {
float x1 = mTrackPosition.x;
float x2 = mTrackPosition.x + (float)( mTrack.getWidth() - mSlider.getWidth() );
mSliderPosition.x = math<float>::clamp( mCursorPosition.x, x1, x2 );
}
break;
case 1:
mCursorType = CursorType::TOUCH;
// Buttons
mFingerTipPosition = warpPointable( *hand.fingers().begin() );
for ( size_t i = 0; i < 3; ++i ) {
mButtonState[ i ] = false;
if ( mButton[ 0 ].getBounds().contains( mFingerTipPosition - mButtonPosition[ i ] ) ) {
mButtonState[ i ] = true;
}
}
break;
default:
mCursorType = CursorType::HAND;
break;
}
}
// Smooth cursor animation
mCursorPosition = mCursorPosition.lerp( 0.21f, mCursorPositionTarget );
}
示例12:
void ClipController::clip2H(const Leap::Frame& frame)
{
Hand hand = frame.hands().rightmost();
Hand other_hand = frame.hands().leftmost();
if (other_hand.grabStrength() > 0.95f) {
VolumeController& vc = MainController::getInstance().volumeController();
const Mat4& inv = vc.getCamera().viewInverse();
Vec3 n = inv * hand.palmNormal().toVector4<Vec4>();
Vec3 p = frame.interactionBox().normalizePoint(hand.palmPosition()).toVector4<Vec4>();
p = (p - 0.5f) * 2.0f * 0.75f;
p = inv * Vec4(p.x, p.y, p.z, 0.0f);
selectedPlane().normal(n);
selectedPlane().point(p);
vc.markDirty();
}
}
示例13: frame_hands
static VALUE frame_hands(VALUE self)
{
Leap::Frame * f;
Leap::HandList * list;
Data_Get_Struct(self, Leap::Frame, f);
list = new Leap::HandList(f->hands());
return WrapHandList(list);
}
示例14: 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;
}
示例15: 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;
// retrieve first pointable object (finger or tool)
// from the frame
const Leap::PointableList pointables = frame.hands()[0].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;
}