当前位置: 首页>>代码示例>>C++>>正文


C++ Frame::gestures方法代码示例

本文整理汇总了C++中leap::Frame::gestures方法的典型用法代码示例。如果您正苦于以下问题:C++ Frame::gestures方法的具体用法?C++ Frame::gestures怎么用?C++ Frame::gestures使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在leap::Frame的用法示例。


在下文中一共展示了Frame::gestures方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: processGesture

void LeapFishyApp::processGesture()
{
	Leap::Frame frame = m_LeapController.frame();

	if( m_LastFrame == frame )
		return;

	Leap::GestureList gestures =	m_LastFrame.isValid()			?
									frame.gestures( m_LastFrame )	:
									frame.gestures();

	m_LastFrame = frame;

	for( int i = 0; i < gestures.count(); i++ )
	{
		if( gestures[i].type() == Leap::Gesture::TYPE_SWIPE )
		{
			Leap::SwipeGesture swipe = gestures[i];
			Leap::Vector diff = 0.006f*(swipe.position() - swipe.startPosition());
			Vec2f curSwipe(diff.x, -diff.y);
			m_pPlayer->AddVelocity( curSwipe );
		}
		else if(	gestures[i].type() == Leap::Gesture::TYPE_KEY_TAP || 
					gestures[i].type() == Leap::Gesture::TYPE_SCREEN_TAP )
		{
			m_pPlayer->KillVelocity();
		}
	}
}
开发者ID:seanfoo73,项目名称:LeapExperiments,代码行数:29,代码来源:LeapFishyApp.cpp

示例2: processGestures

//Handle Leap Gesture processing.
//Trigger the corresponding effects in the particle field.
void GesturesDemo::processGestures() {
  Leap::Frame frame = controller.frame();

  if ( lastFrame == frame ) {
    return;
  }

  Leap::GestureList gestures =  lastFrame.isValid()       ?
                                frame.gestures(lastFrame) :
                                frame.gestures();

  lastFrame = frame;

  size_t numGestures = gestures.count();

  for (size_t i=0; i < numGestures; i++) {
    if (gestures[i].type() == Leap::Gesture::TYPE_SCREEN_TAP) {
      printf("screen screen tap gesture");
      Leap::ScreenTapGesture tap = gestures[i];
      ci::Vec3f tapLoc = normalizeCoords(tap.position());
      field.Repel(tap.id(), ci::Vec2f(tapLoc.x, tapLoc.y), 3.0);
    } else if (gestures[i].type() == Leap::Gesture::TYPE_KEY_TAP) {
      printf("screen key tap gesture");
      Leap::KeyTapGesture tap = gestures[i];
      ci::Vec3f tapLoc = normalizeCoords(tap.position());
      field.Repel(tap.id(), ci::Vec2f(tapLoc.x, tapLoc.y), -3.0);
    } else if (gestures[i].type() == Leap::Gesture::TYPE_SWIPE) {
      printf(" swipe  gesture");
      Leap::SwipeGesture swipe = gestures[i];
      Leap::Vector diff = 0.004f*(swipe.position() - swipe.startPosition());
      ci::Vec3f curSwipe(diff.x, -diff.y, diff.z);
      field.Translate(swipe.id(), curSwipe);
    } else if (gestures[i].type() == Leap::Gesture::TYPE_CIRCLE) {
      printf(" circle gesture");
      Leap::CircleGesture circle = gestures[i];
      float progress = circle.progress();
      if (progress >= 1.0f) {
        ci::Vec3f center = normalizeCoords(circle.center());
        ci::Vec3f normal(circle.normal().x, circle.normal().y, circle.normal().z);
        double curAngle = 6.5;
        if (normal.z < 0) {
          curAngle *= -1;
        }
        field.Rotate(circle.id(), ci::Vec2f(center.x, center.y), circle.radius()/250, curAngle);
      }
    }
  }
}
开发者ID:sjokoladevx,项目名称:Black-Nanocopter-Down---Final-Project-Repo,代码行数:50,代码来源:GesturesDemo.cpp

示例3: update

void GestureApp::update()
{
	mFrameRate = getAverageFps();

	if ( mFullScreen != isFullScreen() ) {
		setFullScreen( mFullScreen );
	}

	const Leap::GestureList& gestures = mFrame.gestures();
	for ( Leap::GestureList::const_iterator iter = gestures.begin(); iter != gestures.end(); ++iter ) {
		const Leap::Gesture& gesture	= *iter;
		Leap::Gesture::Type type		= gesture.type();
		if ( type == Leap::Gesture::Type::TYPE_CIRCLE ) {
			const Leap::CircleGesture& gesture = (Leap::CircleGesture)*iter;
			
			mDialBrightness	= 1.0f;
			mDialValueDest	= gesture.progress();
		} else if ( type == Leap::Gesture::Type::TYPE_KEY_TAP ) {
			const Leap::KeyTapGesture& gesture = (Leap::KeyTapGesture)*iter;
			vec2 center	= warpVector( gesture.position() );
			center			-= mOffset;
			
			for ( vector<Key>::iterator keyIter = mKeys.begin(); keyIter != mKeys.end(); ++keyIter ) {
				if ( keyIter->mBounds.contains( center ) ) {
					keyIter->mBrightness = 1.0f;
					break;
				}
			}			
		} else if ( type == Leap::Gesture::Type::TYPE_SCREEN_TAP ) {
			mBackgroundBrightness = 1.0f;
		} else if ( type == Leap::Gesture::Type::TYPE_SWIPE ) {
			const Leap::SwipeGesture& swipeGesture = (Leap::SwipeGesture)gesture;
			ci::vec2 a	= warpVector( swipeGesture.startPosition() );
			ci::vec2 b	= warpVector( swipeGesture.position() );
			
			mSwipeBrightness	= 1.0f;
			if ( gesture.state() == Leap::Gesture::State::STATE_STOP ) {
				mSwipePosDest	= b.x < a.x ? 0.0f : 1.0f;
			} else {
				float step		= mSwipeStep;
				mSwipePosDest	+= b.x < a.x ? -step : step;
			}
			mSwipePosDest		= math<float>::clamp( mSwipePosDest, 0.0f, 1.0f );
		}
	}
	
	mDialValue				= lerp( mDialValue, mDialValueDest, mDialSpeed );
	mSwipePos				= lerp( mSwipePos, mSwipePosDest, mSwipePosSpeed );
	mBackgroundBrightness	*= mFadeSpeed;
	mDialBrightness			*= mFadeSpeed;
	mSwipeBrightness		*= mFadeSpeed;
	for ( vector<Key>::iterator iter = mKeys.begin(); iter != mKeys.end(); ++iter ) {
		iter->mBrightness *= mFadeSpeed;
	}
}
开发者ID:BanTheRewind,项目名称:Cinder-LeapMotion,代码行数:55,代码来源:GestureApp.cpp

示例4: 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;
				}
			}
		}
	}
}
开发者ID:joemasterjohn,项目名称:medleap,代码行数:36,代码来源:MenuController.cpp

示例5: updateGestures

//--------------------------------------------------------------
void ofxLeapMotion::updateGestures(){
	
	Leap::Frame frame = ourController->frame();
	
	if(lastFrame == frame){
		return;
	}
	
	Leap::GestureList gestures = lastFrame.isValid() ? frame.gestures(lastFrame) : frame.gestures();
	
	lastFrame = frame;
	
	size_t numGestures = gestures.count();
	
	for(size_t i=0; i < numGestures; i++){
		
		// screen tap gesture (forward poke / tap)
		if(gestures[i].type() == Leap::Gesture::TYPE_SCREEN_TAP){
			Leap::ScreenTapGesture tap = gestures[i];

			screenTapPosition = getMappedofPoint(tap.position());   // screen tap gesture data = tap position
			screenTapDirection = getofPoint(tap.direction());       // screen tap gesture data = tap direction

			iGestures = 1;
		}
		
		// key tap gesture (down tap)
		else if(gestures[i].type() == Leap::Gesture::TYPE_KEY_TAP){
			Leap::KeyTapGesture tap = gestures[i];

			keyTapPosition = getofPoint(tap.position());            // key tap gesture data = tap position

			iGestures = 2;
		}
		
		// swipe gesture
		else if(gestures[i].type() == Leap::Gesture::TYPE_SWIPE){
			Leap::SwipeGesture swipe = gestures[i];
			Leap::Vector diff = 0.04f*(swipe.position() - swipe.startPosition());
			ofVec3f curSwipe(diff.x, -diff.y, diff.z);
			
			// swipe left
			if(curSwipe.x < -3 && curSwipe.x > -20){
				iGestures = 4;
			}
			// swipe right
			else if(curSwipe.x > 3 && curSwipe.x < 20){
				iGestures = 3;
			}
			// swipe up
			if(curSwipe.y < -3 && curSwipe.y > -20){
				iGestures = 6;
			}
			// swipe down
			else if(curSwipe.y > 3 && curSwipe.y < 20){
				iGestures = 5;
			}
			
			// 3D swiping
			// swipe forward
			if(curSwipe.z < -5){
				iGestures = 7;
			}
			// swipe back
			else if(curSwipe.z > 5){
				iGestures = 8;
			}
			
			// more swipe gesture data
			swipeSpeed = swipe.speed();                             // swipe speed in mm/s
			swipeDurationSeconds = swipe.durationSeconds();         // swipe duration in seconds
			swipeDurationMicros = swipe.duration();                 // swipe duration in micros
			swipe.position();
		}
		
		// circle gesture
		else if(gestures[i].type() == Leap::Gesture::TYPE_CIRCLE){
			Leap::CircleGesture circle = gestures[i];
			circleProgress = circle.progress();                     // circle progress

			if(circleProgress >= 1.0f){
				
				circleCenter = getMappedofPoint(circle.center());                           // changed to global
				circleNormal.set(circle.normal().x, circle.normal().y, circle.normal().z);  // changed to global

				double curAngle = 6.5;
				if(circleNormal.z < 0){
					curAngle *= -1;
				}
				
				if(curAngle < 0){
					// clockwise rotation
					iGestures = 10;
				}
				else{
					// counter-clockwise rotation
					iGestures = 9;
				}
			}
//.........这里部分代码省略.........
开发者ID:hujkuj,项目名称:ofxLeapMotion,代码行数:101,代码来源:ofxLeapMotion.cpp

示例6: InterfaceEventTick


//.........这里部分代码省略.........
		//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);

		//Rightmost
		finger = fingers.rightmost();
		_private->eventFinger->setFinger(finger);
		ILeapEventInterface::Execute_LeapRightMostFingerMoved(_private->interfaceDelegate, _private->eventFinger);

		//Frontmost
		finger = fingers.frontmost();
		_private->eventFinger->setFinger(finger);
		ILeapEventInterface::Execute_LeapFrontMostFingerMoved(_private->interfaceDelegate, _private->eventFinger);

		//touch only for front-most finger, most common use case
		float touchDistance = finger.touchDistance();
		if (touchDistance <= 0.f)
			ILeapEventInterface::Execute_LeapFrontFingerTouch(_private->interfaceDelegate, _private->eventFinger);

		//Set the state data for next cycle
		pastHandState.grabbed = grabbed;
		pastHandState.pinched = pinched;
		pastHandState.fingerCount = fingerCount;

		_private->pastState.setStateForId(pastHandState, hand.id());
	}

	_private->pastState.handCount = handCount;

	//Gestures
	for (int i = 0; i < frame.gestures().count(); i++)
	{
		Leap::Gesture gesture = frame.gestures()[i];
		Leap::Gesture::Type type = gesture.type();

		switch (type)
		{
		case Leap::Gesture::TYPE_CIRCLE:
			if (_private->eventCircleGesture == NULL){
				_private->eventCircleGesture = NewObject<ULeapCircleGesture>(this);
				_private->eventCircleGesture->SetFlags(RF_RootSet);
			}
			_private->eventCircleGesture->setGesture(Leap::CircleGesture(gesture));
			ILeapEventInterface::Execute_CircleGestureDetected(_private->interfaceDelegate, _private->eventCircleGesture);
			_private->eventGesture = _private->eventCircleGesture;
			break;
		case Leap::Gesture::TYPE_KEY_TAP:
			if (_private->eventKeyTapGesture == NULL)
			{
				_private->eventKeyTapGesture = NewObject<ULeapKeyTapGesture>(this);
				_private->eventKeyTapGesture->SetFlags(RF_RootSet);
			}
			_private->eventKeyTapGesture->setGesture(Leap::KeyTapGesture(gesture));
			ILeapEventInterface::Execute_KeyTapGestureDetected(_private->interfaceDelegate, _private->eventKeyTapGesture);
			_private->eventGesture = _private->eventKeyTapGesture;
			break;
		case Leap::Gesture::TYPE_SCREEN_TAP:
			if (_private->eventScreenTapGesture == NULL)
			{
				_private->eventScreenTapGesture = NewObject<ULeapScreenTapGesture>(this);
				_private->eventScreenTapGesture->SetFlags(RF_RootSet);
			}
			_private->eventScreenTapGesture->setGesture(Leap::ScreenTapGesture(gesture));
开发者ID:77stone,项目名称:leap-ue4,代码行数:67,代码来源:LeapController.cpp

示例7: drawGestures

void GestureApp::drawGestures()
{
	gl::color( ColorAf::white() );
	
	const Leap::GestureList& gestures = mFrame.gestures();
	for ( Leap::GestureList::const_iterator iter = gestures.begin(); iter != gestures.end(); ++iter ) {
		const Leap::Gesture& gesture	= *iter;
		Leap::Gesture::Type type		= gesture.type();
		if ( type == Leap::Gesture::Type::TYPE_CIRCLE ) {
			const Leap::CircleGesture& gesture = (Leap::CircleGesture)*iter;
						
			vec2 pos	= warpVector( gesture.center() );
			float progress	= gesture.progress();
			float radius	= gesture.radius() * 2.0f;
			
			drawDottedCircle( pos, radius, mDotRadius, mCircleResolution, progress );
		} else if ( type == Leap::Gesture::Type::TYPE_KEY_TAP ) {
			const Leap::KeyTapGesture& gesture = (Leap::KeyTapGesture)*iter;
			vec2 center = warpVector( gesture.position() );
			
			vec2 size( 30.0f, 30.0f );
			drawDottedRect( center, size );
		} else if ( type == Leap::Gesture::Type::TYPE_SCREEN_TAP ) {
			
			vec2 center = getWindowCenter();
			vec2 size( 300.0f, 300.0f );
			drawDottedRect( center, size );
		} else if ( type == Leap::Gesture::Type::TYPE_SWIPE ) {
			const Leap::SwipeGesture& gesture = (Leap::SwipeGesture)*iter;
			ci::vec2 a	= warpVector( gesture.startPosition() );
			ci::vec2 b	= warpVector( gesture.position() );
			
			float spacing = mDotRadius * 3.0f;
			float direction = 1.0f;
			if ( b.x < a.x ) {
				direction *= -1.0f;
				swap( a, b );
			}

			vec2 pos = a;
			while ( pos.x <= b.x ) {
				pos.x += spacing;
				gl::drawSolidCircle( pos, mDotRadius, 32 );
			}
			
			if ( direction > 0.0f ) {
				pos		= b;
				spacing	*= -1.0f;
			} else {
				pos		= a;
				pos.x	+= spacing;
			}
			pos.y		= a.y;
			pos.x		+= spacing;
			gl::drawSolidCircle( pos + vec2( 0.0f, spacing ), mDotRadius, 32 );
			gl::drawSolidCircle( pos + vec2( 0.0f, spacing * -1.0f ), mDotRadius, 32 );
			pos.x		+= spacing;
			gl::drawSolidCircle( pos + vec2( 0.0f, spacing * 2.0f ), mDotRadius, 32 );
			gl::drawSolidCircle( pos + vec2( 0.0f, spacing * -2.0f ), mDotRadius, 32 );
		}
	}
}
开发者ID:BanTheRewind,项目名称:Cinder-LeapMotion,代码行数:62,代码来源:GestureApp.cpp

示例8: ParseEvents


//.........这里部分代码省略.........
		{
			ILeapEventInterface::Execute_LeapRightMostFingerMoved(EventDelegate, PEventFinger);
		});

		//Frontmost
		Finger = Fingers.frontmost();
		PEventFinger->SetFinger(Finger);
		CallFunctionOnDelegates([&](UObject* EventDelegate)
		{
			ILeapEventInterface::Execute_LeapFrontMostFingerMoved(EventDelegate, PEventFinger);
		});

		//touch only for front-most finger, most common use case
		float touchDistance = Finger.touchDistance();
		if (touchDistance <= 0.f)
		{
			CallFunctionOnDelegates([&](UObject* EventDelegate)
			{
				ILeapEventInterface::Execute_LeapFrontFingerTouch(EventDelegate, PEventFinger);
			});
		}

		//Set the state data for next cycle
		PastHandState.Grabbed = Grabbed;
		PastHandState.Pinched = Pinched;
		PastHandState.FingerCount = FingerCount;

		PastState->SetStateForId(PastHandState, Hand.id());
	}

	PastState->HandCount = HandCount;

	//Gestures
	for (int i = 0; i < Frame.gestures().count(); i++)
	{
		Leap::Gesture Gesture = Frame.gestures()[i];
		Leap::Gesture::Type Type = Gesture.type();

		switch (Type)
		{
		case Leap::Gesture::TYPE_CIRCLE:
			if (PEventCircleGesture == nullptr)
			{
				PEventCircleGesture = NewObject<ULeapCircleGesture>();
				PEventCircleGesture->AddToRoot();
			}
			PEventCircleGesture->SetGesture(Leap::CircleGesture(Gesture));
			CallFunctionOnDelegates([&](UObject* EventDelegate)
			{
				ILeapEventInterface::Execute_CircleGestureDetected(EventDelegate, PEventCircleGesture);
			});
			PEventGesture = PEventCircleGesture;
			break;
		case Leap::Gesture::TYPE_KEY_TAP:
			if (PEventKeyTapGesture == nullptr)
			{
				PEventKeyTapGesture = NewObject<ULeapKeyTapGesture>();
				PEventKeyTapGesture->AddToRoot();
			}
			PEventKeyTapGesture->SetGesture(Leap::KeyTapGesture(Gesture));
			CallFunctionOnDelegates([&](UObject* EventDelegate)
			{
				ILeapEventInterface::Execute_KeyTapGestureDetected(EventDelegate, PEventKeyTapGesture);
			});
			PEventGesture = PEventKeyTapGesture;
			break;
开发者ID:7hny,项目名称:leap-ue4,代码行数:67,代码来源:FLeapMotionInputDevice.cpp

示例9: oleap_bang

void oleap_bang(t_oleap *x)
{

	const Leap::Frame frame = x->leap->frame();
    const int64_t frame_id = frame.id();
    Leap::Controller controller;
    
	// ignore the same frame
	if (frame_id == x->frame_id_save) return;
	x->frame_id_save = frame_id;
	
	//outlet_anything(x->outlet, gensym("frame_start"), 0, nil);
    
    char buff[128];
    
    const Leap::HandList hands = frame.hands();
	const size_t numHands = hands.count();
    const Leap::Hand leftmost = hands.leftmost();
    const Leap::Hand rightmost = hands.rightmost();
    
    t_osc_bundle_u *bundle = osc_bundle_u_alloc();//alloc creates memory for and initializes the bundle

    controller.enableGesture(Leap::Gesture::TYPE_CIRCLE);
    controller.enableGesture(Leap::Gesture::TYPE_KEY_TAP);
    controller.enableGesture(Leap::Gesture::TYPE_SCREEN_TAP);
    controller.enableGesture(Leap::Gesture::TYPE_SWIPE);
    
    
    // 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;
                
                sprintf(buff,"/gesture/circle/center/x");
                oleap_bundleMessage(bundle,buff,circle.center().x);
                
                sprintf(buff,"/gesture/circle/center/y");
                oleap_bundleMessage(bundle,buff,circle.center().y);
                
                sprintf(buff,"/gesture/circle/center/z");
                oleap_bundleMessage(bundle,buff,circle.center().z);
                
                sprintf(buff,"/gesture/circle/pitch");
                oleap_bundleMessage(bundle,buff,circle.center().pitch());
                
                sprintf(buff,"/gesture/circle/yaw");
                oleap_bundleMessage(bundle,buff,circle.center().yaw());
                
                sprintf(buff,"/gesture/circle/roll");
                oleap_bundleMessage(bundle,buff,circle.center().roll());
                
                sprintf(buff,"/gesture/circle/radius");
                oleap_bundleMessage(bundle,buff,circle.radius());
                
                sprintf(buff,"/gesture/circle/duration");
                oleap_bundleMessage(bundle,buff,circle.duration());
                
                
                if (circle.pointable().direction().angleTo(circle.normal()) <= Leap::PI/4) {
                    clockwiseness = "clockwise";
                    
                    sprintf(buff,"/gesture/circle/clockwiseness/");
                    oleap_bundleMessage(bundle,buff,1);
                    
                } else {
                    clockwiseness = "counterclockwise";
                    
                    sprintf(buff,"/gesture/circle/clockwiseness/");
                    oleap_bundleMessage(bundle,buff,-1);
                }
                
                
                // 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;
                    
                    sprintf(buff,"/gesture/circle/angle/sweep");
                    oleap_bundleMessage(bundle,buff,sweptAngle);
                }
            }
                
            case Leap::Gesture::TYPE_SWIPE:
            {
                Leap::SwipeGesture swipe = gesture;
                int swipe_id = gesture.id();
                int gesture_state = gesture.state();
                Leap::Vector swipe_direction = swipe.direction();
                float swipe_speed = swipe.speed();
                
                ////////////////////////////////Swipe data
//.........这里部分代码省略.........
开发者ID:KevinGutowski,项目名称:o.io.leap,代码行数:101,代码来源:o.io.leap.cpp

示例10: CopyGesturesData

void LeapController::CopyGesturesData( LeapFrame & a_frame_internal, Leap::Frame & a_frame_external )
{
    a_frame_internal.gestures.clear();

    const int num_gestures = min( a_frame_external.gestures().count(), LEAP_MAX_NUM_GESTURES );

    for ( int i_gesture = 0; i_gesture < num_gestures; ++i_gesture )
    {
        const Leap::Gesture & gesture_ext = a_frame_external.gestures()[i_gesture];

        if (!gesture_ext.isValid()) continue;

        // alloc new gesture
        a_frame_internal.gestures.resize( a_frame_internal.gestures.size()+1 );
        ASSERT( a_frame_internal.gestures.size() < LEAP_MAX_NUM_GESTURES );

        // initialize gesture
        LeapGesture & gesture = a_frame_internal.gestures.back();
        gesture.duration = gesture_ext.durationSeconds();
        gesture.id = gesture_ext.id();

        // set gesture state state
        switch( gesture_ext.state() )
        {
        case Leap::Gesture::STATE_START:
            gesture.state = LEAPGESTURE_STATE_START;
            break;
        case Leap::Gesture::STATE_UPDATE:
            gesture.state = LEAPGESTURE_STATE_UPDATE;
            break;
        case Leap::Gesture::STATE_STOP:
            gesture.state = LEAPGESTURE_STATE_STOP;
            break;
        default: {
            ASSERT(false);
        }
        }

        switch( gesture_ext.type() )
        {
        case Leap::Gesture::TYPE_CIRCLE:
        {
            gesture.type = LEAPGESTURE_CIRCLE;

            Leap::CircleGesture subgesture(gesture_ext);
            gesture.data.circle.finger_id = subgesture.pointable().id();
            gesture.data.circle.center = toLeapVec3(subgesture.center() * LEAP_SCALE);
            gesture.data.circle.normal = toLeapVec3(subgesture.normal());
            gesture.data.circle.progress = subgesture.progress();
            gesture.data.circle.radius = subgesture.radius() * LEAP_SCALE;

            break;
        }

        case Leap::Gesture:: TYPE_SWIPE:
        {
            gesture.type = LEAPGESTURE_SWIPE;

            Leap::SwipeGesture subgesture(gesture_ext);
            gesture.data.swipe.finger_id = subgesture.pointable().id();
            gesture.data.swipe.dir = toLeapVec3(subgesture.direction());
            gesture.data.swipe.pos = toLeapVec3(subgesture.position() * LEAP_SCALE);
            gesture.data.swipe.start_pos = toLeapVec3(subgesture.startPosition() * LEAP_SCALE);
            gesture.data.swipe.speed = subgesture.speed() * LEAP_SCALE;

            break;
        }

        case Leap::Gesture::TYPE_SCREEN_TAP:
        {
            gesture.type = LEAPGESTURE_SCREEN_TAP;

            Leap::ScreenTapGesture subgesture(gesture_ext);
            gesture.data.screen_tap.finger_id = subgesture.pointable().id();
            gesture.data.screen_tap.dir = toLeapVec3(subgesture.direction());
            gesture.data.screen_tap.pos = toLeapVec3(subgesture.position() * LEAP_SCALE);

            break;
        }

        case Leap::Gesture::TYPE_KEY_TAP:
        {
            gesture.type = LEAPGESTURE_KEY_TAP;

            Leap::KeyTapGesture subgesture(gesture_ext);
            gesture.data.key_tap.finger_id = subgesture.pointable().id();
            gesture.data.key_tap.dir = toLeapVec3(subgesture.direction());
            gesture.data.key_tap.pos = toLeapVec3(subgesture.position() * LEAP_SCALE);

            break;
        }

        case Leap::Gesture::TYPE_INVALID:
        {
            ASSERT(false);
        }
        }
    }
}
开发者ID:kalineh,项目名称:FunkEngine-Public,代码行数:99,代码来源:LeapController.cpp

示例11: 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()]
//.........这里部分代码省略.........
开发者ID:RobDeBagel,项目名称:fadecandy,代码行数:101,代码来源:fc_leap.cpp


注:本文中的leap::Frame::gestures方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。