예제 #1
0
void AssimpApp::draw()
{
	gl::clear( Color::black() );

	gl::setMatrices( mMayaCam.getCamera() );

	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, 5, -20 ), Vec3f( 0, 5, 0 ) );
	light.update( mMayaCam.getCamera() );
	light.enable();

	gl::enable( GL_LIGHTING );
	gl::enable( GL_NORMALIZE );

	mAssimpLoader.draw();
	gl::disable( GL_LIGHTING );

	if ( mEnableWireframe )
		gl::disableWireframe();

	if ( mDrawBBox )
		gl::drawStrokedCube( mAssimpLoader.getBoundingBox() );

	params::InterfaceGl::draw();
}
예제 #2
0
void AssimpApp::setup()
{
	mAssimpLoader = assimp::AssimpLoader( getAssetPath( "astroboy_walk.dae" ) );
	mAssimpLoader.setAnimation( 0 );


	CameraPersp cam;
	cam.setPerspective( 60, getWindowAspectRatio(), 0.1f, 1000.0f );
	cam.setEyePoint( Vec3f( 0, 7, 20 ) );
	cam.setCenterOfInterestPoint( Vec3f( 0, 7, 0 ) );
	mMayaCam.setCurrentCam( cam );

	mParams = params::InterfaceGl( "Parameters", Vec2i( 200, 300 ) );
	mEnableWireframe = false;
	mParams.addParam( "Wireframe", &mEnableWireframe );
	mEnableTextures = true;
	mParams.addParam( "Textures", &mEnableTextures );
	mEnableSkinning = true;
	mParams.addParam( "Skinning", &mEnableSkinning );
	mEnableAnimation = false;
	mParams.addParam( "Animation", &mEnableAnimation );
	mDrawBBox = false;
	mParams.addParam( "Bounding box", &mDrawBBox );
	mParams.addSeparator();
	mParams.addParam( "Fps", &mFps, "", true );
}
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
    }

}
예제 #4
0
void AssimpApp::update()
{
	mAssimpLoader.enableTextures( mEnableTextures );
	mAssimpLoader.enableSkinning( mEnableSkinning );
	mAssimpLoader.enableAnimation( mEnableAnimation );

	double time = fmod( getElapsedSeconds(), mAssimpLoader.getAnimationDuration( 0 ) );
	mAssimpLoader.setTime( time );
	mAssimpLoader.update();

	mFps = getAverageFps();
}
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);
        }
		
	}
}
void EpicMonsterApp::setup()
{
    mScreenSyphon.setName("Epic Monster Demo");
    
    mFallDirection = Vec3f(0.0,-1.0,0.0);
    listener.setup(7000);
    
    // Slows down particle pulses
    mTimerSlower = 0.05;
    
    // Number of iterations for particle drawing to texture
    n = Vec3f(128, 128, 0);
    
    // Where texture baking shader starts drawing (obsolete)
    mParTexOffset = Vec3f(-1.0, 1.0, 0.0);
    timer = cinder::Timer(true);
    mStep = true;
    try {
        // Multiple render targets shader updates the positions/velocities
        mParticlesShader = gl::GlslProg( ci::app::loadResource( PASSTHROUGH_VERT ), ci::app::loadResource( PARTICLES_FRAG ));
        // Vertex displacement shader
        mDisplacementShader = gl::GlslProg( ci::app::loadResource( VERTEXDISPLACEMENT_VERT ), ci::app::loadResource( VERTEXDISPLACEMENT_FRAG ));
        
        mBakeShader = gl::GlslProg( ci::app::loadResource( BAKE_VERT ), ci::app::loadResource( BAKE_FRAG ));
    }
    catch( ci::gl::GlslProgCompileExc &exc ) {
        std::cout << "Shader compile error: " << endl;
        std::cout << exc.what();
    }
    catch( const std::exception& ex ) {
        std::cout << "Unable to load shader" << endl;
    }
    
    setupPingPongFbo();
    // THE VBO HAS TO BE DRAWN AFTER FBO!
    setupVBO();
    
    // End of Particle setup
    
    try {
    mAssimpLoader = assimp::AssimpLoader( getAssetPath( "Monsu7b.dae" ) );
        
    }
    catch(const std::exception& ex ) {
        std::cout << "Model loading error: " << endl;
        std::cout << ex.what();
    }
    
    mNormalMap	= gl::Texture( loadImage( loadResource( RES_NORMAL ) ) );
	mAssimpLoader.enableSkinning();
    
	mNodeNames = mAssimpLoader.getNodeNames();
	if ( mNodeNames.empty () )
	{
		mNodeNames.push_back( "NO BONES!" );
		mNoBones = true;
	}
	else
	{
		mNoBones = false;
	}
    
	// query original node orientations from model
	mNodeOrientations.assign( mNodeNames.size(), Quatf() );
	if ( !mNoBones )
	{
		for ( size_t i = 0; i < mNodeOrientations.size(); ++i )
		{
			mNodeOrientations[ i ] = mAssimpLoader.getNodeOrientation( mNodeNames[ i ] );
		}
	}
    
    // query original node orientations from model
	mNodePositions.assign( mNodeNames.size(), Vec3f() );
	if ( !mNoBones )
	{
		for ( size_t i = 0; i < mNodePositions.size(); ++i )
		{
			mNodePositions[ i ] = mAssimpLoader.getNodePosition( mNodeNames[ i ] );
		}
	}
    
	mNodeIndex = 0;
    triangles = mAssimpLoader.totalTriangles();
	mEnableWireframe = false;
    mEnableDebugTexture = false;
    
	mParams = params::InterfaceGl( "Parameters", Vec2i( 200, 300 ) );
    
	setupParams();
    
    CameraPersp cam;
	cam.setPerspective( 60, getWindowAspectRatio(), 0.1f, 1000.0f );
	cam.setEyePoint( Vec3f( 0, 1, 3 ) );
	cam.setCenterOfInterestPoint( Vec3f( 0, 0, 0 ) );
	mMayaCam.setCurrentCam( cam );
}