void EpicMonsterApp::flockToBody() {
    if(timer.getSeconds() > mTimerSlower) {
        timer.stop();
        timer.start();
        
        gl::setMatricesWindow( mPPFbo.getSize(), false ); // false to prevent vertical flipping;
    
        mPPFbo.updateBind();
    
        mBakeShader.bind();
        mBakeShader.uniform( "positions", 0 );
        mBakeShader.uniform( "scale", mNormalScale );
        mBakeShader.uniform( "velocities", 1 );
        mBakeShader.uniform( "n", n);
        mBakeShader.uniform( "attractorPos", mAttractor);
        
        mBakeShader.uniform( "offset", Vec3f(mParTexOffset.x, mParTexOffset.y, mParIteration));
    
        
        glDisable(GL_CULL_FACE);
        mAssimpLoader.draw();
        mBakeShader.unbind();
    
        mPPFbo.updateUnbind();
        mPPFbo.swap();
        mParIteration+= triangles;
        if(mParIteration > (6*n.x*n.x))
            mParIteration = 0;
        // TODO: baketuksessa overflowaa tyylikkäästi takaisin alkuun, jos menee yli
    }

}
Exemplo n.º 2
0
void gpuPSApp::keyDown( KeyEvent event ){
    if( event.getChar() == 'r' ) {
        mSwapFbo.reloadTextures();
    } else if (event.getChar() == ' ') {
        mStep = !mStep;
    }
}
Exemplo n.º 3
0
void gpuPSApp::draw()
{
    
    gl::setMatrices( mMayaCam.getCamera() );
    gl::setViewport( getWindowBounds() );
    gl::clear( Color::white() );
    
    mSwapFbo.bindTexture(0);
    mSwapFbo.bindTexture(1);
    mDisplacementShader.bind();
    mDisplacementShader.uniform("displacementMap", 0 );
    mDisplacementShader.uniform("velocityMap", 1);
    gl::draw( mVboMesh );
    mDisplacementShader.unbind();
    mSwapFbo.unbindTexture();
    
    gl::setMatricesWindow(getWindowSize());
    gl::drawString( toString( SIDE*SIDE ) + " vertices", Vec2f(32.0f, 32.0f));
    gl::drawString( toString((int) getAverageFps()) + " fps", Vec2f(32.0f, 52.0f));
}
void EpicMonsterApp::keyDown(KeyEvent event) {
    if( event.getChar() == 'r' ) {
        mPPFbo.reloadTextures();
    } else if (event.getChar() == ' ') {
        mStep = !mStep;
    } else if (event.getChar() == 'k') {
        limit++;
    } else if (event.getChar() == 'j') {
        limit--;
    } else if (event.getChar() == 'f') {
        setFullScreen( !isFullScreen() );
    }
}
Exemplo n.º 5
0
void gpuPSApp::update()
{
    if (mStep) {
        computeAttractorPosition();
        
        gl::setMatricesWindow( mSwapFbo.getSize(), false ); // false to prevent vertical flipping
        gl::setViewport( mSwapFbo.getBounds() );
        
        mSwapFbo.updateBind();
        
        mParticlesShader.bind();
        mParticlesShader.uniform( "positions", 0 );
        mParticlesShader.uniform( "velocities", 1 );
        mParticlesShader.uniform( "attractorPos", mAttractor);
        gl::drawSolidRect(mSwapFbo.getBounds());
        mParticlesShader.unbind();
        
        mSwapFbo.updateUnbind();
        mSwapFbo.swap();
    }
}
void EpicMonsterApp::draw()
{
	gl::clear( Color::black() );
    
	gl::setMatrices( mMayaCam.getCamera() );
    gl::setViewport( getWindowBounds() );
    
    
    
	gl::enableDepthWrite();
	gl::enableDepthRead();
    
	gl::color( Color::white() );
    
	if ( mEnableWireframe )
		gl::enableWireframe();
	gl::Light light( gl::Light::DIRECTIONAL, 0 );
	light.setAmbient( Color::white() );
	light.setDiffuse( Color::white() );
	light.setSpecular( Color::white() );
	light.lookAt( Vec3f( 0, 0, 0 ), Vec3f( 0, 5, 0 ) );
	light.update( mMayaCam.getCamera() );
	light.enable();
    
	gl::enable( GL_LIGHTING );
	gl::enable( GL_NORMALIZE );
    
    mAssimpLoader.draw();
    
    
    mNormalMap.bind( 2 );
    
    mPPFbo.bindTexture(0);
    mPPFbo.bindTexture(1);
    mDisplacementShader.bind();
    mDisplacementShader.uniform("displacementMap", 0 );
    mDisplacementShader.uniform("velocityMap", 1);
    mDisplacementShader.uniform("normalMap", 2);
        mDisplacementShader.uniform("fallDirection", mFallDirection);
    gl::draw( mVboMesh );
    mDisplacementShader.unbind();
    mPPFbo.unbindTexture();
    
    if(mEnableDebugTexture) {
        gl::Texture tex = mPPFbo.getTexture(0);
        //console() << getWindowBounds();
        gl::draw(tex, Rectf(-5.0f, -5.0f, 5.0f, 5.0f));
    }
    
    
	
    //gl::setMatricesWindow(getWindowSize());
    gl::drawString( toString( SIDE*SIDE ) + " vertices", Vec2f(32.0f, 32.0f));
        gl::drawString( toString((int) getAverageFps()) + " fps", Vec2f(32.0f, 52.0f));
    
	gl::disable( GL_LIGHTING );
    
	if ( mEnableWireframe )
		gl::disableWireframe();
    
    mScreenSyphon.publishScreen(); //publish the screen
    
	params::InterfaceGl::draw();
}
void EpicMonsterApp::update()
{
	static int lastNodeIndex = -1;
    
	if ( mNodeIndex != lastNodeIndex )
	{
		setupParams();
		lastNodeIndex = mNodeIndex;
	}
    
	if ( !mNoBones )
	{
		mAssimpLoader.setNodeOrientation( mNodeNames[ mNodeIndex ],
                                         mNodeOrientations[ mNodeIndex ] );
        
        mAssimpLoader.setNodePosition( mNodeNames[ mNodeIndex ],
                                         mNodePositions[ mNodeIndex ] );
	}
    
	mAssimpLoader.update();
    
	mFps = getAverageFps();
    
    
    computeAttractorPosition();
    
    if (mStep) {
        
        gl::setMatricesWindow( mPPFbo.getSize(), false ); // false to prevent vertical flipping
        gl::setViewport( mPPFbo.getBounds() );
        
        mPPFbo.updateBind();
        
        mParticlesShader.bind();
        mParticlesShader.uniform( "positions", 0 );
        mParticlesShader.uniform( "velocities", 1 );
        mParticlesShader.uniform( "attractorPos", mAttractor);
        mParticlesShader.uniform( "fallDirection", mFallDirection);
        

        gl::drawSolidRect(mPPFbo.getBounds());
        mParticlesShader.unbind();
        
        
        mPPFbo.updateUnbind();
        mPPFbo.swap();
    }
    
    //else {
        flockToBody();
    //}
     
     
    
    while (listener.hasWaitingMessages()) {
		osc::Message message;
		listener.getNextMessage(&message);
		
		console() << "New message received" << std::endl;
		console() << "Address: " << message.getAddress() << std::endl;
        
        if(boneMap.find(message.getAddress()) != boneMap.end()) {
           string bone = boneMap.at(message.getAddress());
            
            Vec3f pos = Vec3f(message.getArgAsFloat(0), message.getArgAsFloat(1), message.getArgAsFloat(2));
            Quatf ori = Quatf(message.getArgAsFloat(3), message.getArgAsFloat(4), message.getArgAsFloat(5), message.getArgAsFloat(6));
            mAssimpLoader.setNodePosition(bone, pos*0.2);
            mAssimpLoader.setNodeOrientation(bone, ori);
        }
		
	}
}