예제 #1
0
void MilluminApp::setup()
{
	listener.setup(5001);
	host = "127.0.0.1";
	port = 5000;
	sender.setup(host, port);
    
    
	mTex = gl::Texture(200, 100); //create our texture to publish
	mSurface = Surface8u(200, 100, false); //create a surface to manipulate
	randomizeSurface(&mSurface); //randomize our surface
	mTex.update(mSurface); //tell the texture about our changes
	
	archimedes.set(100.f, 0.6f); //set up and calculate our spiral
	archimedes.calc();
	mRot = 0.f;
	
	mScreenSyphon.setName("Cinder Screen"); // set a name for each item to be published
	mTextureSyphon.setName("Cinder Texture");
	
	mClientSyphon.setup();
    
	// in order for this to work, you must run simple server from the testapps directory
	// any other syphon item you create would work as well, just change the name
    mClientSyphon.setApplicationName("Simple Server");
    mClientSyphon.setServerName("");
	
	mClientSyphon.bind();
}
예제 #2
0
void osc_exampleApp::setup()
{
  mListener.setup(23232);
  for (auto& emg : mEMG) {
    emg.resize(1000);
    std::fill(emg.begin(), emg.end(), 0);
  }
}
예제 #3
0
void PxlFkr::setup()
{
	// Todo: enable resize from lua
	setWindowSize(1024, 768);
	
	listener.setup(PORT);
	luaBridge.setup();
}
예제 #4
0
void osc_exampleApp::update()
{
  while(mListener.hasWaitingMessages() ) {
    osc::Message message;
    mListener.getNextMessage( &message );
    
    if (message.getAddress() == "/myo") {
      for (int i = 0; i < min((size_t)message.getNumArgs(), mEMG.size()); i++) {
        if( message.getArgType(i) == osc::TYPE_INT32 ) {
          mEMG[i].push_front(message.getArgAsInt32(i));
          mEMG[i].pop_back();
        }
      }
    } else {
      console() << "Unknown message: " << message.getAddress() << endl;
    }
  }
}
예제 #5
0
void OSCListenerApp::update()
{
	while( listener.hasWaitingMessages() ) {
		osc::Message message;
		listener.getNextMessage( &message );
		
		console() << "New message received" << std::endl;
		console() << "Address: " << message.getAddress() << std::endl;
		console() << "Num Arg: " << message.getNumArgs() << std::endl;
		for (int i = 0; i < message.getNumArgs(); i++) {
			console() << "-- Argument " << i << std::endl;
			console() << "---- type: " << message.getArgTypeName(i) << std::endl;
			if( message.getArgType(i) == osc::TYPE_INT32 ) {
				try {
					console() << "------ value: "<< message.getArgAsInt32(i) << std::endl;
				}
				catch (...) {
					console() << "Exception reading argument as int32" << std::endl;
				}
			}
			else if( message.getArgType(i) == osc::TYPE_FLOAT ) {
				try {
					console() << "------ value: " << message.getArgAsFloat(i) << std::endl;
				}
				catch (...) {
					console() << "Exception reading argument as float" << std::endl;
				}
			}
			else if( message.getArgType(i) == osc::TYPE_STRING) {
				try {
					console() << "------ value: " << message.getArgAsString(i).c_str() << std::endl;
				}
				catch (...) {
					console() << "Exception reading argument as string" << std::endl;
				}
			}
		}
        
        if( message.getNumArgs() != 0 && message.getArgType( 0 ) == osc::TYPE_FLOAT )
            positionX = message.getArgAsFloat(0);
	}
}
예제 #6
0
void redEyeApp::update() {
    
    //--osc input
    while(mListener.hasWaitingMessages()) {
		osc::Message msg;
		mListener.getNextMessage(&msg);
        mOsc= msg.getAddress();
        for(uint32_t i= 0; i<msg.getNumArgs(); i++) {
            mOsc= mOsc+" "+msg.getArgAsString(i, true);
        }
        if(msg.getAddress()=="/numSamples") {
            mNumSamples= math<int32_t>::clamp(msg.getArgAsInt32(0, true), 1, 2048);
        } else if(msg.getAddress()=="/downSample") {
            mDownSample= math<int32_t>::clamp(msg.getArgAsInt32(0, true), 0, 2047);
        } else if(msg.getAddress()=="/amplitude") {
            mAmplitude= msg.getArgAsFloat(0, true);
        } else if(msg.getAddress()=="/width") {
            mWidth= math<float>::clamp(msg.getArgAsFloat(0, true), 0, 1000);
        } else if(msg.getAddress()=="/colorBack") {
            ColorA col= ColorA(0, 0, 0, 1);
            for(uint32_t i= 0; i<min(msg.getNumArgs(), 4); i++) {
                col[i]= msg.getArgAsFloat(i, true);
            }
            mColorBack.set(col.r, col.g, col.b, col.a);
        
        } else if(msg.getAddress()=="/scale0") {
            Vec3f sca= Vec3f(1.0f, 1.0f, 1.0f);
            for(uint32_t i= 0; i<min(msg.getNumArgs(), 3); i++) {
                msg.getArgAsFloat(i, true);
            }
            mScale0.set(sca.x, sca.y, sca.z);
        } else if(msg.getAddress()=="/scale1") {
            Vec3f sca= Vec3f(1.0f, 1.0f, 1.0f);
            for(uint32_t i= 0; i<min(msg.getNumArgs(), 3); i++) {
                msg.getArgAsFloat(i, true);
            }
            mScale1.set(sca.x, sca.y, sca.z);
        } else if(msg.getAddress()=="/rotate0") {
            Vec3f rot= Vec3f::zero();
            for(uint32_t i= 0; i<min(msg.getNumArgs(), 3); i++) {
                rot[i]= msg.getArgAsFloat(i, true);
            }
            mRotate0.set(rot.x, rot.y, rot.z);
        } else if(msg.getAddress()=="/rotate1") {
            Vec3f rot= Vec3f::zero();
            for(uint32_t i= 0; i<min(msg.getNumArgs(), 3); i++) {
                rot[i]= msg.getArgAsFloat(i, true);
            }
            mRotate1.set(rot.x, rot.y, rot.z);
        } else if(msg.getAddress()=="/translate0") {
            Vec3f tra= Vec3f::zero();
            for(uint32_t i= 0; i<min(msg.getNumArgs(), 3); i++) {
                tra[i]= msg.getArgAsFloat(i, true);
            }
            mTranslate0.set(tra.x, tra.y, tra.z);
        } else if(msg.getAddress()=="/translate1") {
            Vec3f tra= Vec3f::zero();
            for(uint32_t i= 0; i<min(msg.getNumArgs(), 3); i++) {
                tra[i]= msg.getArgAsFloat(i, true);
            }
            mTranslate1.set(tra.x, tra.y, tra.z);
        } else if(msg.getAddress()=="/color0") {
            ColorA col= ColorA(0, 0, 0, 1);
            for(uint32_t i= 0; i<min(msg.getNumArgs(), 4); i++) {
                col[i]= msg.getArgAsFloat(i, true);
            }
            mColor0.set(col.r, col.g, col.b, col.a);
        } else if(msg.getAddress()=="/color1") {
            ColorA col= ColorA(0, 0, 0, 1);
            for(uint32_t i= 0; i<min(msg.getNumArgs(), 4); i++) {
                col[i]= msg.getArgAsFloat(i, true);
            }
            mColor1.set(col.r, col.g, col.b, col.a);
        }
	}
    
    //--audio input
    mPcmBuffer= mInput.getPcmBuffer();
    if(mPcmBuffer) {
        mBufferSize= mPcmBuffer->getSampleCount();
        //std::cout<<"mBufferSize: "<<mBufferSize<<std::endl;
        mBufferLeft= mPcmBuffer->getChannelData(audio::CHANNEL_FRONT_LEFT);
        //mBufferRight= mPcmBuffer->getChannelData(audio::CHANNEL_FRONT_RIGHT);
        mFftLeft= audio::calculateFft(mPcmBuffer->getChannelData(audio::CHANNEL_FRONT_LEFT), mBufferSize/2);
        //mFftRight= audio::calculateFft(mPcmBuffer->getChannelData(audio::CHANNEL_FRONT_LEFT), mBufferSize/2);
        mAmplitude= 0.0f;
        for(uint32_t i= 0; i<mBufferSize; i++) {
            mAmplitude += abs(mBufferLeft->mData[i]);
        }
        mAmplitude /= float(mBufferSize);   //average amplitude
        
        Surface32f mSurfaceSnd(mBufferSize, 1, true);
        Surface32f::Iter sndIter(mSurfaceSnd.getIter());
        uint32_t i= 0;
        while(sndIter.line()) {
            while(sndIter.pixel()) {
                sndIter.r()= mBufferLeft->mData[i];
                i++;
            }
        }
        mTextureSnd= gl::Texture(mSurfaceSnd);
        
        Surface32f mSurfaceFft(mBufferSize/2, 1, true);
        Surface32f::Iter fftIter(mSurfaceFft.getIter());
        uint32_t j= 0;
        float *fftBuffer= mFftLeft.get();
        while(fftIter.line()) {
            while(fftIter.pixel()) {
                fftIter.r()= fftBuffer[j];
                j++;
            }
        }
        mTextureFft= gl::Texture(mSurfaceFft);
    }
    
    //--shaders
    if(mShader!=NULL) {
        if((fs::last_write_time(mPathFrag)>mTimeFrag) || (fs::last_write_time(mPathVert)>mTimeVert)) {
            loadShader();   //hot-loading shader
        }
    }
    
    mFps= getAverageFps();
}
예제 #7
0
void OSCListenerApp::setup()
{
	listener.setup( 3000 );
	positionX = 0;
}
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 );
}