void UserManager::setBounds( const Rectf &rect ) { mOutputRect = rect; Rectf kRect( 0, 0, 640, 480 ); // kinect image rect Rectf dRect = kRect.getCenteredFit( mOutputRect, true ); if( mOutputRect.getAspectRatio() > dRect.getAspectRatio() ) dRect.scaleCentered( mOutputRect.getWidth() / dRect.getWidth() ); else dRect.scaleCentered( mOutputRect.getHeight() / dRect.getHeight() ); mOutputMapping = RectMapping( kRect, dRect, true ); }
void Gallery::Picture::render( const Rectf &rect ) { Rectf txtRect; Rectf outRect = rect; gl::pushModelView(); Vec2f flipScale( 1, 1 ); double currentTime = app::getElapsedSeconds(); if ( zooming ) { Rectf zoomRect; if ( mTexture ) zoomRect = mTexture.getBounds(); else zoomRect = Rectf( 0, 0, 1024, 768 ); Rectf screenRect( app::getWindowBounds() ); zoomRect = zoomRect.getCenteredFit( screenRect, true ); if ( screenRect.getAspectRatio() > zoomRect.getAspectRatio() ) zoomRect.scaleCentered( screenRect.getWidth() / zoomRect.getWidth() ); else zoomRect.scaleCentered( screenRect.getHeight() / zoomRect.getHeight() ); Vec2f center = lerp< Vec2f >( zoomRect.getCenter(), outRect.getCenter(), mZoom ); float scale = lerp< float >( zoomRect.getWidth(), outRect.getWidth(), mZoom ) / outRect.getWidth(); outRect.offsetCenterTo( center ); outRect.scaleCentered( scale ); if ( mZoom == 1. ) zooming = false; } else if ( currentTime < appearanceTime ) { flipScale = Vec2f( 0, 1 ); } else if ( currentTime < appearanceTime + sFlipDuration * .5 ) { float flipU = easeOutQuart( ( currentTime - appearanceTime ) / ( sFlipDuration * .5 ) ); flipScale = Vec2f( flipU, 1 ); } else if ( flipping ) { float flipU = easeInOutQuart( math<float>::clamp( ( currentTime - flipStart ) / sFlipDuration ) ); if ( ( flipU >= .5 ) && !flipTextureChanged ) { setRandomTexture(); flipTextureChanged = true; } flipScale = Vec2f( math<float>::abs( flipU * 2 - 1 ), 1 ); if ( flipU >= 1 ) flipping = false; } if ( mTexture ) { txtRect = mTexture.getBounds(); mTexture.bind(); gl::color( Color::white() ); } else { txtRect = Rectf( 0, 0, 1024, 768 ); gl::color( Color::black() ); } txtRect = txtRect.getCenteredFit( outRect, true ); gl::translate( txtRect.getCenter() ); gl::scale( flipScale ); gl::translate( -txtRect.getCenter() ); gl::drawSolidRect( txtRect ); if ( mTexture ) mTexture.unbind(); else gl::color( Color::white() ); gl::popModelView(); }