예제 #1
0
// Draw pointables calibrated to the screen
void GestureApp::drawPointables()
{
	gl::color( ColorAf::white() );
	const HandMap& hands = mFrame.getHands();
	for ( HandMap::const_iterator iter = hands.begin(); iter != hands.end(); ++iter ) {
		const Hand& hand = iter->second;
		const FingerMap& fingers = hand.getFingers();
		for ( FingerMap::const_iterator fingerIter = fingers.begin(); fingerIter != fingers.end(); ++fingerIter ) {
			const Finger& finger = fingerIter->second;
			
			Vec2f pos( warpPointable( finger ) );
			drawDottedCircle( pos, mPointableRadius, mDotRadius * 0.5f, mCircleResolution / 2 );
		}
	}
}
예제 #2
0
void BrainbowApp::onFrame( LeapSdk::Frame frame )
{
	mHands = frame.getHands();
}
예제 #3
0
// Called when Leap frame data is ready
void ChargesApp::onFrame( LeapSdk::Frame frame )
{
	mHands = frame.getHands();
	mTimestamp = frame.getTimestamp();
}
예제 #4
0
void LeapPalmDirectionApp::onFrame( LeapSdk::Frame frame )
{
	mHands = frame.getHands();
}
void _TBOX_PREFIX_App::onFrame( LeapSdk::Frame frame )
{
	mHands = frame.getHands();
}
예제 #6
0
// Runs update logic
void GestureApp::update()
{
	// Update frame rate
	mFrameRate = getAverageFps();

	// Toggle fullscreen
	if ( mFullScreen != isFullScreen() ) {
		setFullScreen( mFullScreen );
	}

	// Update device
	if ( mLeap && mLeap->isConnected() ) {		
		mLeap->update();
	}
	
	const vector<Leap::Gesture>& gestures = mFrame.getGestures();
	for ( vector<Leap::Gesture>::const_iterator iter = gestures.begin(); iter != gestures.end(); ++iter ) {
		Gesture::Type type = iter->type();
		if ( type == Gesture::Type::TYPE_CIRCLE ) {
			
			// Cast to circle gesture
			const Leap::CircleGesture& gesture = (Leap::CircleGesture)*iter;
			
			// Control dial
			mDialBrightness	= 1.0f;
			mDialValueDest	= gesture.progress();
			
		} else if ( type == Gesture::Type::TYPE_KEY_TAP ) {
			
			// Cast to circle gesture and read data
			const Leap::KeyTapGesture& gesture = (Leap::KeyTapGesture)*iter;
			Vec2f center	= warpVector( fromLeapVector( gesture.position() ) );
			center			-= mOffset;
			
			// Press key
			for ( vector<Key>::iterator iter = mKeys.begin(); iter != mKeys.end(); ++iter ) {
				if ( iter->mBounds.contains( center ) ) {
					iter->mBrightness = 1.0f;
					break;
				}
			}
			
		} else if ( type == Gesture::Type::TYPE_SCREEN_TAP ) {
			
			// Turn background white for screen tap
			mBackgroundBrightness = 1.0f;
			
		} else if ( type == Gesture::Type::TYPE_SWIPE ) {
			
			// Cast to swipe gesture and read data
			const Leap::SwipeGesture& gesture = (Leap::SwipeGesture)*iter;
			ci::Vec2f a	= warpVector( fromLeapVector( gesture.startPosition() ) );
			ci::Vec2f b	= warpVector( fromLeapVector( gesture.position() ) );
			
			// Update swipe position
			mSwipeBrightness	= 1.0f;
			if ( gesture.state() == 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 );
		}
	}
	
	// UI animation
	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;
	}
}
예제 #7
0
// Draw active gestures with dotted lines
void GestureApp::drawGestures()
{
	gl::color( ColorAf::white() );
	
	// Iterate through gestures
	const vector<Leap::Gesture>& gestures = mFrame.getGestures();
	for ( vector<Leap::Gesture>::const_iterator iter = gestures.begin(); iter != gestures.end(); ++iter ) {
		Gesture::Type type = iter->type();
		if ( type == Gesture::Type::TYPE_CIRCLE ) {
			
			// Cast to circle gesture and read data
			const Leap::CircleGesture& gesture = (Leap::CircleGesture)*iter;
						
			Vec2f pos	= warpVector( fromLeapVector( gesture.center() ) );
			float progress	= gesture.progress();
			float radius	= gesture.radius() * 2.0f; // Don't ask, it works
			
			drawDottedCircle( pos, radius, mDotRadius, mCircleResolution, progress );
			
		} else if ( type == Gesture::Type::TYPE_KEY_TAP ) {
			
			// Cast to circle gesture and read data
			const Leap::KeyTapGesture& gesture = (Leap::KeyTapGesture)*iter;
			Vec2f center = warpVector( fromLeapVector( gesture.position() ) );
			
			// Draw square where key press happened
			Vec2f size( 30.0f, 30.0f );
			drawDottedRect( center, size );
			
		} else if ( type == Gesture::Type::TYPE_SCREEN_TAP ) {
			
			// Draw big square on center of screen
			Vec2f center = getWindowCenter();
			Vec2f size( 300.0f, 300.0f );
			drawDottedRect( center, size );
		} else if ( type == Gesture::Type::TYPE_SWIPE ) {
			
			// Cast to swipe gesture and read data
			const Leap::SwipeGesture& gesture = (Leap::SwipeGesture)*iter;
			ci::Vec2f a	= warpVector( fromLeapVector( gesture.startPosition() ) );
			ci::Vec2f b	= warpVector( fromLeapVector( gesture.position() ) );
			
			// Set draw direction
			float spacing = mDotRadius * 3.0f;
			float direction = 1.0f;
			if ( b.x < a.x ) {
				direction *= -1.0f;
				swap( a, b );
			}
			
			// Draw swipe line
			Vec2f pos = a;
			while ( pos.x <= b.x ) {
				pos.x += spacing;
				gl::drawSolidCircle( pos, mDotRadius, 32 );
			}
			
			// Draw arrow head
			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 + Vec2f( 0.0f, spacing ), mDotRadius, 32 );
			gl::drawSolidCircle( pos + Vec2f( 0.0f, spacing * -1.0f ), mDotRadius, 32 );
			pos.x		+= spacing;
			gl::drawSolidCircle( pos + Vec2f( 0.0f, spacing * 2.0f ), mDotRadius, 32 );
			gl::drawSolidCircle( pos + Vec2f( 0.0f, spacing * -2.0f ), mDotRadius, 32 );
		}
	}
}