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