// add force and dye to fluid, and create particles
void msaFluidParticlesApp::addToFluid( Vec2f pos, Vec2f vel, bool addColor, bool addForce )
{
    float speed = vel.x * vel.x  + vel.y * vel.y * getWindowAspectRatio() * getWindowAspectRatio();    // balance the x and y components of speed with the screen aspect ratio
    if( speed > 0 ) {
		pos.x = constrain( pos.x, 0.0f, 1.0f );
		pos.y = constrain( pos.y, 0.0f, 1.0f );
		
        const float colorMult = 100;
        const float velocityMult = 30;
		
		if( addColor ) {
			Color drawColor( CM_HSV, ( getElapsedFrames() % 360 ) / 360.0f, 1, 1 );
			
			fluidSolver.addColorAtPos( pos, drawColor * colorMult );

			if( drawParticles )
				particleSystem.addParticles( pos * Vec2f( getWindowSize() ), 10 );
		}
		
		if( addForce )
			fluidSolver.addForceAtPos( pos, vel * velocityMult );
		
		if( ! drawFluid && getElapsedFrames()%5==0 )
			fadeToColor( 0, 0, 0, 0.1f );
    }
}
Beispiel #2
0
//Update loop called from the Main App class
//Checks for incoming messages from OSC
//Updates entities (environment and NPCs)
//and activates PCG
void EntityManager :: update( ){
    
    oscManager->recieveMessage();

    updatePlankton();
    updateUrchins();
    updateSparks();
    updateSpores();
    updateEggs();
    updateStarfish();
    updateJellies();
    updateFriendlies();

    
    updateOffset( );
    environment->update( hero->global, hero->local );

    if( getElapsedFrames() < 400 ) return;
    
    entityGenerator->generatePlankton( &plankton, &eggs );
    entityGenerator->generateSpores( &spores );
    entityGenerator->generateUrchin( &urchins );
    entityGenerator->generateStarfish( &starfish );
    entityGenerator->generateJellyfish( &jellies );
    if( entityGenerator->generateEgg( &eggs, &friendlies, &plankton ) )
    {
        oscManager->newFriendly();
    }
}
void msaFluidParticlesApp::keyDown( KeyEvent event )
{ 
    switch( event.getChar() ) {
		case 'a':
			drawFluid = !drawFluid;
		break;
		case 'd':
			drawFluidTex = !drawFluidTex;
		break;
		case 'f':
			setFullScreen( ! isFullScreen() );
		break;
		case ' ':
			fluidSolver.randomizeColor();
		break;
		case 'p':
			drawParticles = ! drawParticles;
		break;
		case 'b': {
			Timer timer;
			timer.start();
			const int ITERS = 1000;
			for( int i = 0; i < ITERS; ++i )
				fluidSolver.update();
			timer.stop();
			console() << ITERS << " iterations took " << timer.getSeconds() << " seconds." << std::endl;
		}
		break;
		case 's':
			writeImage( getHomeDirectory() / "cinder" / "saveImage_" / ( toString( getElapsedFrames() ) + ".png" ), copyWindowSurface() );
			break;
    }
}
//Stage 3,4,5
void HodginDidItApp::updateBlend()
{
	int cTime = getElapsedFrames();
	if(cTime==S_BL_2_SEG||cTime==S_SEG_2_BW||cTime==S_BW_2_RGB)
	{
		mBlendCounter = 0;
		mBlendAmt = 1.0f;
		console() << "STAGE: " << mStage << endl;
	}
	int cTimeBase;
	switch(mStage)
	{
		case 3:
		{
			cTimeBase = S_BL_2_SEG;
			break;
		}
		case 4:
		{
			cTimeBase = S_SEG_2_BW;
			break;
		}
		case 5:
		{
			cTimeBase = S_BW_2_RGB;
			break;
		}
	}
	cTimeBase = cTime-cTimeBase;
	if(mStage<=5&&cTimeBase<90)
		mBlendAmt = lerp<float>( 0.0f, 1.0f, (cTimeBase%S_FADE_TIME)/(float)S_FADE_TIME );
	else
		mBlendAmt = 1;
	++mBlendCounter;
}
void HodginDidItApp::drawStrings()
{
	Vec2f cOffset = mFont->measureString(mScreenText);
	Vec2f cCursorPos = mFont->measureString(mCursor);
	Rectf cFit = Rectf(320-(cOffset.x*0.5f),240-(cOffset.y*0.5f),320+(cOffset.x*0.5f),240+(cOffset.y*0.5f));
	Rectf cCursorRect = Rectf(cFit.x2,cFit.y1,cFit.x2+cCursorPos.x,cFit.y1+cCursorPos.y);
	mFont->drawString(mScreenText, cFit);
	if(getElapsedFrames()%10<5)
		mFont->drawString(mCursor, cCursorRect);
}
Beispiel #6
0
void EntityManager :: updateStarfish(){
    
    for( vector<Starfish*>::iterator p = starfish.begin(); p < starfish.end(); ){
        
        if( farFromHero( (*p)->global ) == true ){
            //delete if too far away
            removeFromColliders((GameObject*)(*p));
            delete *p;
            p = starfish.erase(p);
            
        } else {
            
            //update standardly
            (*p)->collide(hero->global);
            (*p)->update();
            
            //chord change if active
            if( (*p)->activated() == true){
                oscManager->changeChord();
                environment->splash( (*p)->global, 20.0f, 100.0f );
                environment->bubble( (*p)->local, 5 );
            }
            
            if( (*p)->onScreen() == true){
                entityGenerator->starLastSeen = 0;
            }
            
            //periodically creates bubbles
            if( (*p)->fleeing )
            {
                if( getElapsedFrames() % 15 == 0) environment->bubble( (*p)->local, 1 );
                if( getElapsedFrames() % 3  == 0) environment->splash( (*p)->global, 30.0f, 40.0f);
            }
            
            ++p;
        }
    }
    
    entityGenerator->starLastSeen++;
    
}
//Stage 1,2
void HodginDidItApp::updateStrings()
{
	int cTime = getElapsedFrames();
	if(cTime==0||cTime==S_ASK_START)
		mScreenText="";
	if(mStage==1)
	{
		if(getElapsedFrames()%2==0)
		{
			if(mScreenText.size()<mHello.size())
				mScreenText+=mHello[mScreenText.size()];
		}
	}
	else if(mStage==2)
	{
		if(getElapsedFrames()%2==0)
		{
			if(mScreenText.size()<mQuestion.size())
				mScreenText+=mQuestion[mScreenText.size()];
		}
	}
}
void FurPoint::update(const Perlin &perlin, float stepX, float stepY, float stepZ){
    if (1.0f - age / lifetime <= 0.0f) isDead = true;
    if (position.x < 0 || position.x > getWindowWidth()) isDead = true;
    if (position.y < 0 || position.y > getWindowHeight()) isDead = true;
    
    noiseFloat = perlin.fBm( position.x * stepX, position.y * stepY, getElapsedFrames() * stepZ );
    noiseVec.x = cos(((noiseFloat) * M_PI_2) * 10.0f);
    noiseVec.y = sin(((noiseFloat) * M_PI_2) * 10.0f);
    velocity += noiseVec;
    velocity *= 0.5f;
    position += velocity;
    age++;
}
void HodginDidItApp::update()
{
	int cTime = getElapsedFrames();
	if(cTime < S_HELLO_START)
		mStage = 0;
	else if(cTime>=S_HELLO_START&&cTime<S_ASK_START)
		mStage = 1;
	else if(cTime>=S_ASK_START&&cTime<S_BL_2_SEG)
		mStage = 2;
	else if(cTime>=S_BL_2_SEG&&cTime<S_SEG_2_BW)
		mStage = 3;
	else if(cTime>=S_SEG_2_BW&&cTime<S_BW_2_RGB)
		mStage = 4;
	else if(cTime>=S_BW_2_RGB&&cTime<S_VEIL_START)
		mStage = 5;
	else if(cTime>=S_VEIL_START)
		mStage = 6;
		
	if(mStage>=3)
	{
		if(mPXC.AcquireFrame(true))
		{
			updateCamera();
			mPXC.ReleaseFrame();
		}
	}

	switch(mStage)
	{
		case 1:
		case 2:
		{
			updateStrings();
			break;
		}
		case 3:
		case 4:
		case 5:
		{
			updateBlend();
			break;
		}
		case 6:
		{
			updateVeil();
			break;
		}
	}
}
// Only drawing here, do not place logic during drawing or it will slow down OpenGL
// Called every frame
void HelloWorldApp::draw() {

    // Clear screen every frame with black
    ci::gl::clear( ci::Color( 0, 0, 0 ) );

    // Create a random color based on the number of frames passed
    ci::Color aColor = ci::Color( 0, 0, 0 );
    aColor.r = fabs( cosf(getElapsedFrames() * 0.008) );
    aColor.g = fabs( sinf(getElapsedFrames() * 0.01) );
    aColor.b = (float) getMousePos().x / getWindowWidth();

    // Set the color and draw a simple line to the mouse
    ci::gl::color( aColor );
    ci::gl::drawLine( ci::Vec2f(getMousePos()), ci::Vec2f( getWindowCenter() ) );


    // Test drawing a texture...
    // Always check if texture loaded before drawing to avoid race condition on app start
    if ( texture ) {
        ci::gl::color( ci::ColorA(1.0f, 1.0f, 1.0f, 1.0f) );
        ci::gl::draw( texture, getWindowCenter() );
    }

}
void Wormhole3ContinuousOutputs::draw()
{
	gl::clear( Color( 0, 0, 0 ) );

	gl::setMatrices(mCamera);
	{
		gl::ScopedGlslProg shdr(mShader);
		gl::pushModelMatrix();

		gl::rotate(getElapsedFrames()*mParamRotSpeed, vec3(0, 1, 0));
		mDraw->drawInstanced(mRings.size());
		gl::popModelMatrix();
	}

	gl::setMatricesWindow(getWindowSize());
}
Beispiel #12
0
void SplatTestApp::update() {
  if (spaceNav) {
    spaceNav->update();
  }

  {
    const auto &ori = cameraBody.orientation;
    cameraBody.impulse = glm::rotate(ori, cameraTranslation * vec3(1, 1, -1)) * 0.000005f;
    cameraBody.angularImpulse = quat(cameraRotation * vec3(1, 1, -1) * 0.00000333f);
  }

  cameraBody.step();
  cameraBody.applyTransform(camera);

  particleSys->update(getElapsedSeconds(), getElapsedFrames(), cameraBody.position,
                      cameraBody.position - cameraBody.positionPrev, camera.getViewDirection());

  updateGui();
}
//--------------------------------------------------------------
void FingerTracker::addToFluid( Vec2f pos, Vec2f vel, bool addColor, bool addForce ) {
    float speed = vel.x * vel.x  + vel.y * vel.y * getWindowAspectRatio() * getWindowAspectRatio();
    if(speed > 0) {
		pos.x = constrain(pos.x, 0.0f, 1.0f);
		pos.y = constrain(pos.y, 0.0f, 1.0f);
        const float colorMult = 100;
        const float velocityMult = 30;
        int index = fluidSolver.getIndexForPos(pos);
		if(addColor) {
			Color drawColor( CM_HSV, ( getElapsedFrames() % 360 ) / 360.0f, 1, 1 );
            fluidSolver.addColorAtIndex(index, drawColor * colorMult);
            if(drawParticles) {
                particleSystem.addParticlesWithVelc( pos*Vec2f(getWindowSize()), vel*Vec2f(getWindowSize()), 2 );
            }
		}
		if(addForce)
			fluidSolver.addForceAtIndex(index, vel * velocityMult);
    }
}
Beispiel #14
0
Cube::Cube(Vec3f loc, Vec3f colour, string type){
    cubeMaterial.setSpecular( ColorA (colour.x, colour.y, colour.z, .3) );
	cubeMaterial.setDiffuse( ColorA (colour.x, colour.y, colour.z, .3));
	cubeMaterial.setAmbient(ColorA (colour.x, colour.y, .05f, .01f)) ;
	cubeMaterial.setShininess( 600.0f );
    cubeMaterial.setEmission(ColorA(1, 1, 1, 1 ));
    
    gl::lineWidth(15);
    
    tempCube = cinder::gl::DisplayList (GL_COMPILE);
    tempCube.newList();
    if (type == "stroked")
    gl::drawStrokedCube(Vec3f(0,0,0), Vec3f (80, 80, 80));
    if (type == "solid")
    gl::drawCube(Vec3f(0,0,0), Vec3f (80, 80, 80));
    tempCube.endList();
    tempCube.setMaterial( cubeMaterial );
    
    location = loc;
    rotator = Vec3f(sin(getElapsedSeconds()), cos (getElapsedSeconds()), tan(getElapsedFrames()));
}
void Wormhole3ContinuousOutputs::update()
{
	for (auto ri = begin(mRings); ri != end(mRings);) {
		if (!ri->Active) {
			ri = mRings.erase(ri);
		}
		else {
			ri->Step(mParamRingSpeed*mReceived.z);
			++ri;
		}
	}


	if (getElapsedFrames() % mParamSpawnTime == 0) {
		auto r = mReceived.x;
		auto b = mReceived.y;

		mRings.push_back(Ring(Color(r, 1, b), vec2(mReceived.x, mReceived.y)));
	}

	mData->bufferData(mRings.size()*sizeof(Ring), mRings.data(), GL_DYNAMIC_DRAW);
}
void ReymentaServerApp::update()
{
	if (mFirstLaunch) {
		CI_LOG_V("update begin");
		CI_LOG_V(getElapsedFrames());
	}
	mParameterBag->iFps = getAverageFps();
	mParameterBag->sFps = toString(floor(mParameterBag->iFps));
	getWindow()->setTitle("(" + mParameterBag->sFps + " fps) Server");
	if (mParameterBag->iGreyScale)
	{
		mParameterBag->controlValues[1] = mParameterBag->controlValues[2] = mParameterBag->controlValues[3];
		mParameterBag->controlValues[5] = mParameterBag->controlValues[6] = mParameterBag->controlValues[7];
	}

	mParameterBag->iChannelTime[0] = getElapsedSeconds();
	mParameterBag->iChannelTime[1] = getElapsedSeconds() - 1;
	mParameterBag->iChannelTime[3] = getElapsedSeconds() - 2;
	mParameterBag->iChannelTime[4] = getElapsedSeconds() - 3;
	//
	if (mParameterBag->mUseTimeWithTempo)
	{
		mParameterBag->iGlobalTime = mParameterBag->iTempoTime*mParameterBag->iTimeFactor;
	}
	else
	{
		mParameterBag->iGlobalTime = getElapsedSeconds();
	}
	mParameterBag->iGlobalTime *= mParameterBag->iSpeedMultiplier;

	if (ui::GetDrawData() != NULL) {
		if (mBatchass->isRemoteClientActive()) {
			// Count
			int cmd_count = 0;
			int vtx_count = 0;
			for (int n = 0; n < ui::GetDrawData()->CmdListsCount; n++)
			{
				const ImDrawList * cmd_list = ui::GetDrawData()->CmdLists[n];
				const ImDrawVert * vtx_src = cmd_list->VtxBuffer.begin();
				cmd_count += cmd_list->CmdBuffer.size();
				vtx_count += cmd_list->VtxBuffer.size();
			}

			// Send 
			static int sendframe = 0;
			if (sendframe++ >= 240) // every 2 frames, @TWEAK
			{
				sendframe = 0;
				if (cmd_count > 0 || vtx_count > 0) {

					mBatchass->preparePacketFrame(cmd_count, vtx_count);
					// Add all drawcmds
					Cmd cmd;
					for (int n = 0; n < ui::GetDrawData()->CmdListsCount; n++)
					{
						const ImDrawList* cmd_list = ui::GetDrawData()->CmdLists[n];
						const ImDrawCmd* pcmd_end = cmd_list->CmdBuffer.end();
						for (const ImDrawCmd* pcmd = cmd_list->CmdBuffer.begin(); pcmd != pcmd_end; pcmd++)
						{
							cmd.Set(*pcmd);
							mBatchass->Write(cmd);
						}
					}
					// Add all vtx
					Vtx vtx;
					for (int n = 0; n < ui::GetDrawData()->CmdListsCount; n++)
					{
						const ImDrawList* cmd_list = ui::GetDrawData()->CmdLists[n];
						const ImDrawVert* vtx_src = cmd_list->VtxBuffer.begin();
						int vtx_remaining = cmd_list->VtxBuffer.size();
						while (vtx_remaining-- > 0)
						{
							vtx.Set(*vtx_src++);
							mBatchass->Write(vtx);
						}
					}
					// Send
					mBatchass->SendPacket();
				}
			}
		}
		ImGuiIO& io = ImGui::GetIO();

		// Setup resolution (every frame to accommodate for window resizing)
		int w, h;
		int display_w, display_h;

		// Setup time step
		static double time = 0.0f;
		const double current_time = getElapsedSeconds();
		io.DeltaTime = (float)(current_time - time);
		time = current_time;
	}

	// @RemoteImgui begin
	/*ImGui::RemoteUpdate();
	ImGui::RemoteInput input;
	if (ImGui::RemoteGetInput(input))
	{
	ImGuiIO& io = ImGui::GetIO();
	for (int i = 0; i < 256; i++)
	io.KeysDown[i] = input.KeysDown[i];
	io.KeyCtrl = input.KeyCtrl;
	io.KeyShift = input.KeyShift;
	io.MousePos = input.MousePos;
	io.MouseDown[0] = (input.MouseButtons & 1);
	io.MouseDown[1] = (input.MouseButtons & 2) != 0;
	io.MouseWheel = (float)input.MouseWheel;
	}
	else*/
	// @RemoteImgui end
	{
		// Setup inputs
		// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
		//double mouse_x, mouse_y;
		//glfwGetCursorPos(window, &mouse_x, &mouse_y);
		//mouse_x *= (float)display_w / w;                                                               // Convert mouse coordinates to pixels
		//mouse_y *= (float)display_h / h;
		//io.MousePos = ImVec2((float)mouse_x, (float)mouse_y);                                          // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
		//io.MouseDown[0] = mousePressed[0] || glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) != 0;  // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
		//io.MouseDown[1] = mousePressed[1] || glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) != 0;
	}
	mBatchass->update();
	mProg->uniform("iGlobalTime", static_cast<float>(getElapsedSeconds()));
	//mProg->uniform("iMouse", mMouseCoord);
	//mProg->uniform("iChannel0", 0);

	if (mFirstLaunch) {
		CI_LOG_V("update end");
	}

}