void FluidVisualization::update(){
	if(resizeFluid) 	{
		fluidSolver.setSize(fluidCellsX, fluidCellsX / msa::getWindowAspectRatio());
		fluidDrawer.setup(&fluidSolver);
		resizeFluid = false;
	}
    for (cursorMap::iterator i = cursors.begin(); i != cursors.end(); ++i) {
        tuioCursor tc = (i->second);

        ofVec2f Pos=ofVec2f(tc.x,tc.y);
        ofVec2f Vel=ofVec2f(tc.dx,tc.dy)*0.05;

        addToFluid(Pos, Vel,ink,force);
    }
    if(flame){
        ofVec2f Pos = ofVec2f(0.5, 1);
        ofVec2f Vel = ofVec2f(ofRandom(-0.005,0.005),-0.01);
        addToFluid(Pos, Vel, true, true);
    }
    /*Pos = ofVec2f(0.25, 1);
	Vel = ofVec2f(ofRandom(-0.005,0.005)-0.005,-0.1);
	addToFluid(Pos, Vel, true, true);
    Pos = ofVec2f(0.75, 1);
	Vel = ofVec2f(ofRandom(-0.005,0.005)+0.005,-0.1);
	addToFluid(Pos, Vel, true, true);*/
	fluidSolver.update();
}
Esempio n. 2
0
void testApp::update(){
	if(resizeFluid) 	{
		fluidSolver.setSize(fluidCellsX, fluidCellsX / msa::getWindowAspectRatio());
		fluidDrawer.setup(&fluidSolver);
		resizeFluid = false;
	}
	
#ifdef USE_TUIO
	tuioClient.getMessage();
	
	// do finger stuff
	list<ofxTuioCursor*>cursorList = tuioClient.getTuioCursors();
	for(list<ofxTuioCursor*>::iterator it=cursorList.begin(); it != cursorList.end(); it++) {
		ofxTuioCursor *tcur = (*it);
        float vx = tcur->getXSpeed() * tuioCursorSpeedMult;
        float vy = tcur->getYSpeed() * tuioCursorSpeedMult;
        if(vx == 0 && vy == 0) {
            vx = ofRandom(-tuioStationaryForce, tuioStationaryForce);
            vy = ofRandom(-tuioStationaryForce, tuioStationaryForce);
        }
        addToFluid(tcur->getX(), tcur->getY(), vx, vy);
    }
#endif
	
	fluidSolver.update();
}
Esempio n. 3
0
void testApp::mouseDragged(int x, int y, int button) {
	ofVec2f eventPos = ofVec2f(x, y);
	ofVec2f mouseNorm = ofVec2f(eventPos) / ofGetWindowSize();
	ofVec2f mouseVel = ofVec2f(eventPos - pMouse) / ofGetWindowSize();
	addToFluid(mouseNorm, mouseVel, false, true);
	pMouse = eventPos;
}
Esempio n. 4
0
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y){
	ofVec2f eventPos = ofVec2f(x, y);
	ofVec2f mouseNorm = ofVec2f(eventPos) / ofGetWindowSize();
	ofVec2f mouseVel = ofVec2f(eventPos - pMouse) / ofGetWindowSize();
	addToFluid(mouseNorm, mouseVel, true, true);
	pMouse = eventPos;
}
Esempio n. 5
0
//--------------------------------------------------------------
void fluid001::update(){
	if(resizeFluid) 	{
		fluidSolver.setSize(fluidCellsX, fluidCellsX / window.aspectRatio);
		fluidDrawer.setup(&fluidSolver);
		resizeFluid = false;
	}

#ifdef USE_TUIO
	tuioClient.getMessage();
	
	// do finger stuff
	list<ofxTuioCursor*>cursorList = tuioClient.getTuioCursors();
	for(list<ofxTuioCursor*>::iterator it=cursorList.begin(); it != cursorList.end(); it++) {
		ofxTuioCursor *tcur = (*it);
        float vx = tcur->getXSpeed() * tuioCursorSpeedMult;
        float vy = tcur->getYSpeed() * tuioCursorSpeedMult;
        if(vx == 0 && vy == 0) {
            vx = ofRandom(-tuioStationaryForce, tuioStationaryForce);
            vy = ofRandom(-tuioStationaryForce, tuioStationaryForce);
        }
        addToFluid(tcur->getX(), tcur->getY(), vx, vy);
    }
#endif
	
	fluidSolver.update();
	
	// save old mouse position (openFrameworks doesn't do this automatically like processing does)
	pmouseX = mouseX;
	pmouseY = mouseY;
}
void msaFluidParticlesApp::mouseMove( MouseEvent event )
{
	Vec2f mouseNorm = Vec2f( event.getPos() ) / getWindowSize();
	Vec2f mouseVel = Vec2f( event.getPos() - pMouse ) / getWindowSize();
	addToFluid( mouseNorm, mouseVel, true, true );
	pMouse = event.getPos();
}
Esempio n. 7
0
//--------------------------------------------------------------
void fluid001::opticalFlowToFluid() {

	int								x, y;
	float							dx, dy;

	float iw					= 1.0f/flow.captureWidth;
	float iy					= 1.0f/flow.captureHeight;

	int particleEmitCounter		= 0;
	float flowThreshold			= 100;
	float opticalFlowFluidMult	= 0.001;
	float multX					= (float)ofGetWidth()/flow.captureWidth;
	float multY					= (float)ofGetHeight()/flow.captureHeight;

	for ( y = 0; y < flow.captureHeight; y+=flow.captureRowsStep ){
		for ( x = 0; x < flow.captureWidth; x+=flow.captureColsStep ){

			dx					= cvGetReal2D( flow.vel_x, y, x );
			dy					= cvGetReal2D( flow.vel_y, y, x );
			if(dx*dx+dy*dy > flowThreshold) {

			addToFluid((float)x/flow.captureWidth, (float)y/flow.captureHeight, dx*opticalFlowFluidMult, dy*opticalFlowFluidMult);

			}
		}
	}
}
Esempio n. 8
0
void fluid001::mouseDragged(int x, int y, int button) {
	float mouseNormX = x * window.invWidth;
    float mouseNormY = y * window.invHeight;
    float mouseVelX = (x - pmouseX) * window.invWidth;
    float mouseVelY = (y - pmouseY) * window.invHeight;
	
	addToFluid(mouseNormX, mouseNormY, mouseVelX, mouseVelY, false);
}
Esempio n. 9
0
//--------------------------------------------------------------
void fluid001::mouseMoved(int x, int y ){
	float mouseNormX = x * window.invWidth;
    float mouseNormY = y * window.invHeight;
    float mouseVelX = (x - pmouseX) * window.invWidth;
    float mouseVelY = (y - pmouseY) * window.invHeight;

    addToFluid(mouseNormX, mouseNormY, mouseVelX, mouseVelY, true);
}
void msaFluidParticlesApp::mouseDrag( MouseEvent event )
{
	Vec2f mouseNorm = Vec2f( event.getPos() ) / getWindowSize();
	Vec2f mouseVel = Vec2f( event.getPos() - pMouse ) / getWindowSize();
	addToFluid( mouseNorm, mouseVel, false, true );
	pMouse = event.getPos();

	mArcball.mouseDrag( event.getPos() );
	mCurrentMouseDown = event.getPos();
}
void smokeScene::draw(float x, float y, float scale){
    
    //moved this from update as the easiest wy to get mapping vars
    for (int i = 0; i < flow->current.size(); i++) {
        if (flow->motion[i + flow->motion.size()/2].lengthSquared() > threshold) {
            
            ofVec2f featNorm;
            featNorm.x = ((flow->features[i].x - 160) * scale + 160 + x)  / ofGetWidth();
            featNorm.y = ((flow->features[i].y - 120) * scale + 120 + y)  / ofGetHeight();
            
            ofVec2f featVel;
            featVel.x = flow->motion[i + flow->motion.size()/2].x * scale / ofGetWidth();
            featVel.y = flow->motion[i + flow->motion.size()/2].y * scale / ofGetHeight();
            
            addToFluid(featNorm, featVel, true, true);
        }
    }
    
	fluidSolver.update();
    //end update
    
    
    ofPushStyle();
    ofSetBackgroundAuto(false);
//    ofEnableAlphaBlending();
    
    if(drawFluid) {
        ofClear(0);
		glColor3f(1, 1, 1);
		fluidDrawer.draw(0, 0, ofGetWidth(), ofGetHeight());
	} else {
        //		if(ofGetFrameNum()%5==0)
        fadeToColor(0,0,0, 0.01);
	}
	if(drawParticles) {
        ofSetColor(particleColor);
		particleSystem.updateAndDraw(fluidSolver, ofGetWindowSize(), drawFluid, particleColor);
    }
	
    ofSetBackgroundAuto(true);
    ofPopStyle();
}
Esempio n. 12
0
void testApp::update(){
	if(resizeFluid) 	{
		fluidSolver.setSize(fluidCellsX, fluidCellsX / msa::getWindowAspectRatio());
		fluidDrawer.setup(&fluidSolver);
		resizeFluid = false;
        myVideo->setupVideo(fluidSolver.getWidth(), fluidSolver.getHeight(), &fluidSolver);
	}
    myVideo->update();
	
#ifdef USE_TUIO
    if(bTuioOn){
        tuioClient.getMessage();
        
        // do finger stuff
        list<ofxTuioCursor*>cursorList = tuioClient.getTuioCursors();
        float MaxSpeed = 0.01;
        float MaxSpeed2 = MaxSpeed*MaxSpeed;
        for(list<ofxTuioCursor*>::iterator it=cursorList.begin(); it != cursorList.end(); it++) {
            ofxTuioCursor *tcur = (*it);
            float vx = tcur->getXSpeed() * tuioCursorSpeedMult;
            float vy = tcur->getYSpeed() * tuioCursorSpeedMult;
            
            if(vx == 0 && vy == 0) {
                vx = ofRandom(-tuioStationaryForce, tuioStationaryForce);
                vx = vx > MaxSpeed ? MaxSpeed : vx;
                vy = ofRandom(-tuioStationaryForce, tuioStationaryForce);
                vy = vy > MaxSpeed ? MaxSpeed : vy;
            }
            float v2 = vx*vx+vy*vy;
            if(v2 > MaxSpeed2){
                float ratio = sqrt(v2/MaxSpeed2);
                vx/=ratio;
                vy/=ratio;
            };

//            float x =tcur->getX(), y=tcur->getY();
//            add a factor to correct LKB output range error
            float x =tcur->getX()*xFactor, y=tcur->getY()*yFactor;
//            float x =tcur->getX()*1.0, y=tcur->getY()*1.0;
            addToFluid(ofVec2f(x, y), ofVec2f(vx, vy), true, true);
            cout<<"TUIO "<<x <<" "<<y<<endl; 
        }
    }
#endif
	
	fluidSolver.update();
    
//    osc msg queue update:
    for(int i=0; i<NUM_MSG_STRINGS; i++){
        if(timers[i]<ofGetElapsedTimef()){
            msg_strings[i]="";
        }
    }
    
//    while(receiver.hasWaitingMessages()){
//        parseOSCMessage();
//    }
    
    while(ipadReceiver.hasWaitingMessages()){
        parseIpadOSCMessage();
    }
    
    if(music.getIsPlaying()){
        oscSendString("/1/labelMusicPositionMs", msToTime(music.getPositionMS()));
        oscSendFloat("/1/musicPosition", music.getPosition());
    }
}
Esempio n. 13
0
//--------------------------------------------------------------
void testApp::update(){
	ofBackground(33, 33, 76);
	
	smurfFloor->think();
	
	if(resizeFluid) {
		fluidSolver.setSize(fluidCellsX, fluidCellsX / window.aspectRatio);
		fluidDrawer.setup(&fluidSolver);
		resizeFluid = false;
	}

	tuio.getMessage();
	
	///------------------------------------------------------
	
	
	windowResized(ofGetWidth(), ofGetHeight());		// force this at start (cos I don't think it is called)
	
	// do finger stuff
	list<ofxTuioCursor*>cursorList = tuio.getTuioCursors();
	for(list<ofxTuioCursor*>::iterator it=cursorList.begin(); it != cursorList.end(); it++) {
		ofxTuioCursor *tcur = (*it);
        float vx = tcur->getXSpeed() * tuioCursorSpeedMult;
        float vy = tcur->getYSpeed() * tuioCursorSpeedMult;
        if(vx == 0 && vy == 0) {
            vx = ofRandom(-tuioStationaryForce, tuioStationaryForce);
            vy = ofRandom(-tuioStationaryForce, tuioStationaryForce);
        }
        addToFluid(tcur->getX(), tcur->getY(), vx, vy, true);
    }
	
	for (int i=0; i<smurfFloor->brain->getSmurfs()->size(); i++ ) {
		Smurf* s = smurfFloor->brain->getSmurfs()->at(i);
		ofxTuioObject *blob = (ofxTuioObject*) s->getTuio();
		//addToFluid(blob->getX(), blob->getY(), blob->getMotionSpeed(), blob->getMotionSpeed(), false);
		addToFluid(blob->getX(), blob->getY(), blob->getRotationAccel(), blob->getRotationAccel(), true);
	}
	
	for (int i=0; i<smurfFloor->brain->getConnections()->size(); i++ ) {
		SConnection *connection = smurfFloor->brain->getConnections()->at(i);
		if (connection != NULL) {
			handleAnchorsUpdate(connection);
		}
	}
	
	for (int i=0; i<smurfFloor->waves->size(); i++ ) {
		SWave* w = smurfFloor->waves->at(i);
				
		if (w->getFid() != -1) {
			for (float cc=0.0;cc<15.0;cc++) {
				float vx = ofRandom(-tuioStationaryForce, tuioStationaryForce);
				float vy = ofRandom(-tuioStationaryForce, tuioStationaryForce);
			
				float x = (w->getX() + cosf(ofDegToRad(cc*24.0))*w->getRadius())/ofGetWidth();
				float y = (w->getY() + sinf(ofDegToRad(cc*24.0))*w->getRadius())/ofGetHeight();
				
				//Smurf *s = smurfFloor->brain->findSmurf(w->getFid());
				//if (s != NULL && w->getX(),w->getRadius()
					addToFluid(
							x,
							y,
							0.001,
							0.001,
							true
							);
			}
		}
	}
		
	fluidSolver.update();
	
	// save old mouse position (openFrameworks doesn't do this automatically like processing does)
	pmouseX = mouseX;
	pmouseY = mouseY;
	
}