Example #1
0
void LeapPalmDirectionApp::draw()
{
	gl::clear();
	gl::setViewport( getWindowBounds() );
	gl::setMatrices( mCamera );

	gl::enableDepthRead();
	gl::enableDepthWrite();

	for ( auto handIter = mHands.cbegin(); handIter != mHands.cend(); ++handIter )
	{
		gl::color( Color::white() );
		const LeapSdk::Hand &hand = handIter->second;

		Quatf normToDir( Vec3f( 1, 0, 0 ), M_PI / 2.f ); // 90 degree rotation around x
		Vec3f dir0 = hand.getNormal() * normToDir; // direction from normal
		Quatf dirQuat( dir0, hand.getDirection() ); // rotation from calculated direction to actual one
		Quatf normQuat( Vec3f( 0, -1, 0 ), hand.getNormal() ); // rotation to actual normal
		Quatf rotQuat = normQuat * dirQuat; // final rotation

		// hand plane
		gl::pushModelView();
		gl::translate( hand.getPosition() );
		gl::rotate( rotQuat );
		gl::drawColorCube( Vec3f::zero(), Vec3f( 1, .1, 1 ) * 100 );
		gl::popModelView();
		gl::drawVector( hand.getPosition(), hand.getPosition() + hand.getNormal() * 70.f );
		gl::drawVector( hand.getPosition(), hand.getPosition() + hand.getDirection() * 70.f );
	}
}
void _TBOX_PREFIX_App::draw() 
{
	// Clear window
	gl::setViewport( getWindowBounds() );
	gl::clear( Colorf::black() );
	gl::setMatrices( mCamera );
	
	// Iterate through hands
	for ( LeapSdk::HandMap::const_iterator handIter = mHands.begin(); handIter != mHands.end(); ++handIter ) {
		const LeapSdk::Hand& hand = handIter->second;

		// Fingers
		const LeapSdk::FingerMap& fingers = hand.getFingers();
		for( LeapSdk::FingerMap::const_iterator fingerIter = fingers.begin(); fingerIter != fingers.end(); ++fingerIter ) {
			const LeapSdk::Finger& finger = fingerIter->second;

			// Finger tip
			gl::drawColorCube( finger.getPosition(), Vec3f( 20, 20, 20 ) );

			// Finger orientation
			Vec3f tipPosition = finger.getPosition() + finger.getDirection() * finger.getLength();
			gl::color( ColorAf::gray( 0.8f ) );
			gl::drawLine( finger.getPosition(), tipPosition );
		}
	}
}
Example #3
0
void BrainbowApp::update()
{
    //LEAP
    if ( mLeap && mLeap->isConnected() ) {
		mLeap->update();
	}
    //GET HAND
    for ( LeapSdk::HandMap::const_iterator handIter = mHands.begin(); handIter != mHands.end(); ++handIter ) {
		const LeapSdk::Hand& hand = handIter->second;
        //        cout << hand.getPosition().x << endl;
        //        cout << hand.getDirection();
        
        scaledX = (hand.getPosition().x *(getWindowWidth()/400))+(getWindowWidth()/2);
        scaledY = (-hand.getPosition().y*(getWindowHeight()/400) + getWindowHeight())*2.5 - 400;
        scaledZ = hand.getPosition().z*2+300;
        handPos = Vec3f(scaledX, scaledY, scaledZ);
    }
    
    //AUDIO
    //    mAudio.update();
    
    
    //SCENES
    if (sceneOne)
        scene1();
    if (sceneTwo)
        scene2();
    
    
    //LIGHT
    
    mLight->lookAt( handPos, Vec3f::zero() );
    
    //ROTATE DIAMOND
    if (gong)
        mDiamond.getModelMatrix().rotate( Vec3f( 0.0f, 0.5f, 0), 0.01f );

    
}
Example #4
0
void BrainbowApp::shutdown()
{
	mLeap->removeCallback( mCallbackId );
	mHands.clear();
}
Example #5
0
void BrainbowApp::draw()
{
	gl::setViewport( getWindowBounds() );
    
    // SCREENPULSE
    // changes every 12.5 seconds
    float gray = (cos(getElapsedSeconds()/4)*.3)/2 ;
    float otherCol = (sin(getElapsedSeconds()/4)*.2)/2;
    
    screenCol = Vec3f (lightFade+gray, lightFade, (lightFade*2)-otherCol);
    
    if (sceneOne)
        gl::clear( Color(lightFade+gray, lightFade, (lightFade*2)-otherCol) );
    if (sceneTwo)
        gl::clear( Color(1, 1, 1) );
    
    
    // FADE IN INTRO
    if (lightFade < .5){
        lightFade += .0005;
    }
    
    if (mHands.empty())
        mLight->disable();
    
    updateShadowMap();
    
    gl::enableDepthRead();
    gl::enableDepthWrite();
    mShader.bind();
    glEnable( GL_TEXTURE_2D );
	mDepthFbo.bindDepthTexture();
    mShader.bind();
    
    
    // FIRST SCENE
    if (sceneOne){
        
        // disc
        if (zshift > 0){
            glPushMatrix();
            glTranslated( 640, 400, zshift - 200);
            if (shift2 && discOp > 1)
                glScalef(discOp, discOp, 0);
            //    cout << discOp << endl;
            mDisc.draw();
            glPopMatrix();
        }
        
        //cloud
        glPushMatrix();
        glTranslated( getWindowWidth() * 0.5f, getWindowHeight() * 0.5f, zshift );
        //    if (lightFade > .45f)
        mCloud.update(scaledX, scaledY, scaledZ, diamondFade, 1);
        glPopMatrix();
        
        if (drawDiamond){
            glPushMatrix();
            glTranslated( getWindowWidth() * 0.5f, getWindowHeight() * 0.5f, zshift);
            mDiamond.draw();
            glPopMatrix();
        }
    }
    
    // SECOND SCENE
    if (sceneTwo){
        
        mLight->lookAt( Vec3f(scaledX, scaledY, scaledZ +200), Vec3f (getWindowWidth()*.05, getWindowHeight() * 0.5f, 0.0f ));
        
        // cursor
        glPushMatrix();
        glTranslated( scaledX, scaledY, scaledZ );
        mCur.draw();
        
        if (scaledZ < 375 && scaledZ > 350)
            gl::drawSphere(Vec3f(0,0,0), (scaledZ-350)*.4);
        if (scaledZ >= 375)
            gl::drawSphere(Vec3f(0,0,0), 25*.4);
        glPopMatrix();
        
        
        // rotate whole scene; implement this later:
        
        //        if (targetFilled){
        //            glPushMatrix();
        //            glRotatef(getElapsedSeconds()*10, Vec3f (640, 400, 350) );
        //        }
        for (int i = 0; i < cubes.size() ; i++){
            glPushMatrix();
            glTranslatef(cubes[i].getLocation());
            cubes[i].update(.01f, screenCol);
            glPopMatrix();
        }
        offCounter = 0;        
        for (int i = 0; i < targets.size() ; i++){
            glPushMatrix();
            glTranslatef(targets[i].getLocation());
            targets[i].update(.01f, handPos, screenCol);
            if (targets[i].getBoxed() && targets[i].getBoxNumber() < 15 ){
                addCube(targets[i].getLocation().x, targets[i].getLocation().y, targets[i].getLocation().z);
                targets[i].addBox();
                if (targets[i].getBoxNumber() == 15)
                mAudio.playTraz("box");   
            }
            
            glPopMatrix();
            if (targets[i].getChargeSound()){
                if (!mAudio.isPlaying("charge")){
                    offCounter = 0;
                    mAudio.playTraz("charge");
                }
            }
            //stop charge if deactivated
            if (!targets[i].getChargeSound()){
                offCounter++;
            }
            if (offCounter == targets.size()){
                mAudio.stopTraz("charge");
            }
        }
        //  (from above)
        //   if (targetFilled)
        //   glPopMatrix();
        //
        
        //cloud
        glPushMatrix();
        glTranslated( getWindowWidth() * 0.5f, getWindowHeight() * 0.5f, zshift );
        mCloud.update(0, 0, 0, 0, 2);
        glPopMatrix();
    }
    
    mShader.unbind();
    mDepthFbo.unbindTexture();
    
    //    writeImage( getHomeDirectory() / ("image_" + toString( getElapsedFrames() ) + ".png"), copyWindowSurface() );
	
}
Example #6
0
// Runs update logic
void UiApp::update()
{
	// Update frame rate
	mFrameRate = getAverageFps();

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

	// Update device
	if ( mLeap && mLeap->isConnected() ) {		
		mLeap->update();
	}
	
	// Interact with first hand
	if ( mHands.empty() ) {
		mCursorType		= CursorType::NONE;
	} else {
		const Hand& hand = mHands.begin()->second;
		
		// Update cursor position
		mCursorPositionTarget	= warp( hand.getPosition() );
		if ( mCursorType == CursorType::NONE ) {
			mCursorPosition = mCursorPositionTarget;
		}
		
		// Choose cursor type based on number of exposed fingers
		switch ( hand.getFingers().size() ) {
			case 0:
				mCursorType	= CursorType::GRAB;
				break;
			case 1:
				mCursorType	= CursorType::TOUCH;
				break;
			default:
				mCursorType	= CursorType::HAND;
				break;
		}
	}
	
	// Smooth cursor animation
	mCursorPosition = mCursorPosition.lerp( 0.21f, mCursorPositionTarget );
	mCursorPosition.z = 0.0f;
	
	// Hit buttons
	for ( size_t i = 0; i < 3; ++i ) {
		mButtonState[ i ] = false;
		if ( mCursorType == CursorType::TOUCH &&
			mCursorPosition.distance( mButtonPosition[ i ] ) < (float)mButton[ 0 ].getSize().length() * 0.5f ) {
			mButtonState[ i ] = true;
		}
	}
	
	// Slider
	if ( mCursorType == CursorType::GRAB &&
		math<float>::abs( mCursorPosition.x - mSliderPosition.x ) < (float)mSlider.getWidth() * 0.5f &&
		math<float>::abs( mCursorPosition.y - mSliderPosition.y ) < (float)mSlider.getHeight() * 0.5f ) {
		float x1			= mTrackPosition.x;
		float x2			= mTrackPosition.x + (float)( mTrack.getWidth() - mSlider.getWidth() );
		mSliderPosition.x	= math<float>::clamp( mCursorPosition.x, x1, x2 );
	}
}
Example #7
0
void LeapPalmDirectionApp::shutdown()
{
	mLeap->removeCallback( mCallbackId );
	mHands.clear();
}
void _TBOX_PREFIX_App::shutdown()
{
	mLeap->removeCallback( mCallbackId );
	mHands.clear();
}
Example #9
0
// Render
void LeapApp::draw()
{
	// Clear window
	gl::setViewport( getWindowBounds() );
	gl::clear( Colorf::black() );
	gl::setMatrices( mCamera );

	// Enable depth
	gl::enableAlphaBlending();
	gl::enableDepthRead();
	gl::enableDepthWrite();
	
	// Iterate through hands
	float headLength = 6.0f;
	float headRadius = 3.0f;
	for ( HandMap::const_iterator handIter = mHands.begin(); handIter != mHands.end(); ++handIter ) {
		const Hand& hand = handIter->second;

		// Hand ball
		if ( hand.getBallRadius() > 0.0f ) {
			gl::color( ColorAf( 1.0f, 1.0f, 0.0f, 0.25f ) );
			gl::enableWireframe();
			gl::drawSphere( hand.getBallPosition(), hand.getBallRadius(), 16 );
			gl::disableWireframe();
		}

		// Hand direction
		gl::color( 1.0f, 0.0f, 1.0f, 1.0f );
		gl::drawVector( hand.getPosition(), hand.getPosition() + hand.getDirection() * 100.0f, headLength, headRadius );

		// Hand normal
		gl::color( 0.0f, 0.0f, 1.0f, 1.0f );
		gl::drawVector( hand.getPosition(), hand.getPosition() + hand.getNormal() * 100.0f, headLength, headRadius );

		// Hand velocity
		gl::color( 0.0f, 1.0f, 0.0f, 1.0f );
		gl::drawVector( hand.getPosition(), hand.getPosition() + hand.getVelocity() * 100.0f, headLength, headRadius );

		// Fingers
		const FingerMap& fingers = hand.getFingers();
		for ( FingerMap::const_iterator fingerIter = fingers.begin(); fingerIter != fingers.end(); ++fingerIter ) {
			const Finger& finger = fingerIter->second;

			// Finger
			Vec3f position = finger.getPosition() + finger.getDirection() * -finger.getLength() * 3.0f;
			gl::color( ColorAf::white() );
			gl::drawLine( finger.getPosition(), position );

			// Finger tip
			gl::pushMatrices();
			gl::translate( position );
			gl::drawStrokedCircle( Vec2f::zero(), finger.getWidth(), 16 );
			gl::popMatrices();

			// Finger velocity
			gl::color( 0.0f, 1.0f, 0.0f, 1.0f );
			gl::drawVector( position, position + finger.getVelocity() * 0.05f, headLength, headRadius );
		}
	}
	
	// Draw the interface
	mParams.draw();

}