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 ); } } }
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 ); }
// 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 ); } }
// 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(); }