Ejemplo n.º 1
0
void testApp::draw(){
	
	ofSetHexColor(0xffffff);
	colorImg.draw(20,20);
	grayImage.draw(360,20);
	grayBg.draw(20,280);
	grayDiff.draw(360,280);
	
	ofFill();
	ofSetHexColor(0x333333);
	ofRect(360,540,320,240);
	
	ofSetHexColor(0xffffff);
	contourFinder.draw(360,540);
	
	ofSetHexColor(0xffffff);
	string repstr;
	repstr = "bg subtraction and blob detection\n";
	repstr += "press space to capture bg\n";
	repstr += "threshold" + ofToString(threshold, 0) + "(press: +/-)\n";
	repstr += "num blobs found " + ofToString(contourFinder.nBlobs, 0) + "\n";
	repstr += "fps: " + ofToString(ofGetFrameRate(), 4);
	ofDrawBitmapString(repstr, 20, 600);
}
//--------------------------------------------------------------
void testApp::draw()
{
	// draw to the FBO
	ofEnableAlphaBlending();	
	fbo.begin();
	ofClear(0, 0, 0, 0);
		autoShader.begin();
		autoShader.setUniform1f("u_time", ofGetElapsedTimef() );
			image.draw(0,0, ofGetWidth(), ofGetHeight() );
		autoShader.end();
	fbo.end();
	ofDisableAlphaBlending();

	// draw the FBO to screen
	fbo.draw(0, 0);

	// draw the FPS
	sprintf(tempStr, "%4.1f", ofGetFrameRate() );
	ofVec2f pos( ofGetWidth()-30, ofGetHeight()-5 );
	ofSetColor(0);
	font.drawString( tempStr, pos.x + 1, pos.y + 1 );
	ofSetColor( 255 );
	font.drawString( tempStr, pos.x, pos.y );
}
Ejemplo n.º 3
0
//--------------------------------------------------------------
void testApp::update(){
    checkShaderFile();
    
    //  Video 
    //
    if (video != NULL){
        video->update();
    }
    
    // OSC
    //
	while(oscReceiver.hasWaitingMessages()){
		ofxOscMessage m;
		oscReceiver.getNextMessage(&m);
        
        for(int i = 0; i < uniforms.size(); i++){
            if(uniforms[i]->type == UNIFORM_FLOAT){
                if (uniforms[i]->text.find('/') == 0){
                    
                    if (uniforms[i]->text == m.getAddress() ){
                        uniforms[i]->fValue = m.getArgAsFloat(0);
                    }
                }
            } else if(uniforms[i]->type == UNIFORM_VEC2){
                if (uniforms[i]->text.find('/') == 0){
                    if (uniforms[i]->text == m.getAddress() ){
                        uniforms[i]->vec2Value.set(m.getArgAsFloat(0), m.getArgAsFloat(1));
                    }
                }
            }
        }
        
	}
    
    ofSetWindowTitle(sServer.getName() + "@sNode" + "    ( runnig at " +ofToString(ofGetFrameRate())+ " fps)");
}
//--------------------------------------------------------------
void testApp::draw(){
	ofBackground(200);	
	ofSetColor(255);
	
	if (mode == MODE_TRACKING)	TM.draw();
	if (mode == MODE_TEST)		BT.draw();
	if (mode == MODE_DRAW )		eyeApp.draw();
	if (mode == MODE_TYPING)	typeScene.draw();
	if (mode == MODE_PONG)		ponger.draw();
	
	// draw a green dot to see how good the tracking is:
	if(TM.bBeenCalibrated || bMouseSimulation){
		if( mode != MODE_DRAW ){
			ofFill();
			ofSetColor(0,255,0,120);
			ofCircle(eyeSmoothed.x, eyeSmoothed.y, 20);
			ofSetColor(255,0,0,40);
			ofCircle(eyeRaw.x, eyeRaw.y, 10);
		}
	}
	
	ofSetColor(0);
	ofDrawBitmapString("FrameRate: " + ofToString((int) ofGetFrameRate()), 1, ofGetHeight() - 20);
}
Ejemplo n.º 5
0
//--------------------------------------------------------------
void ofApp::draw(){
    ofEnableAlphaBlending();
    
    ofSetColor(255,160);
    ofDrawBitmapString("OF FPS "+ofToString(ofGetFrameRate()), 30, ofGetWindowHeight()-50);
    ofDrawBitmapString("Robot FPS "+ofToString(robot.robot.getThreadFPS()), 30, ofGetWindowHeight()-65);
    gizmo.setViewDimensions(viewportSim.width, viewportSim.height);
    
    
    cams[1]->begin(viewportSim);
    gizmo.draw( *cams[1] );
    robot.movement.draw(0);
    cams[1]->end();
    
    cams[0]->begin(viewportReal);
    tcpNode.draw();
    
    if (!hideRobot){
        robot.robot.model.draw();
    }
    cams[0]->end();
    
    
    
    
    timeline.draw();
    
    panel.draw();
    panelJoints.draw();
    panelJointsIK.draw();
    panelWorkSurface.draw();
    panelJointsSpeed.draw();
    panelTargetJoints.draw();
    
    //    syphon.publishScreen();
}
Ejemplo n.º 6
0
//--------------------------------------------------------------
void testApp::draw() {
	ofBackground(100, 100, 100);
	
	m_cam.begin();
	ofScale(1, -1, 1); // flip the y axis 
	//ofRotateY(45);
	ofTranslate(-cDepthWidth/ 2, -cDepthHeight / 2);
	m_mesh.draw();
	m_cam.end();

	
	// draw instructions
	ofSetColor(255, 255, 255);
	stringstream reportStream;
	reportStream << "fps: " << ofGetFrameRate() << "  Kinect Nearmode: " << kinect.isNearmode() << endl
				 << "press 'c' to close the stream and 'o' to open it again, stream is: " << kinect.isOpened() << endl
				 << "press UP and DOWN to change the tilt angle: " << angle << " degrees" << endl
				 << "press LEFT and RIGHT to change the far clipping distance: " << farClipping << " mm" << endl
				 << "press '+' and '-' to change the near clipping distance: " << nearClipping << " mm" << endl
				 << "press 'r' to record and 'p' to playback, record is: " << bRecord << ", playback is: " << bPlayback << endl
				 << "press 'v' to show video only: " << bDrawVideo << ",      press 'd' to show depth + users label only: " << bDrawDepthLabel << endl
				 << "press 's' to show skeleton only: " << bDrawSkeleton << ",   press 'q' to show point cloud sample: " << bDrawCalibratedTexture;
	ofDrawBitmapString(reportStream.str(), 20, 648);
}
Ejemplo n.º 7
0
//-----------------------------------------------------------------------------------------
//
void ofApp::draw()
{
	ofBackgroundGradient( ofColor(40,40,40), ofColor(0,0,0), OF_GRADIENT_CIRCULAR);	

	
	ofEnableDepthTest();
	camera.begin();
	
		// draw a grid on the floor
		ofSetColor( ofColor(60) );
		ofPushMatrix();
			ofRotate(90, 0, 0, -1);
			ofDrawGridPlane( 10, 10, false );
		ofPopMatrix();

	
	camera.end();

	ofSetColor( ofColor::white );
	ofDisableDepthTest();


	fontSmall.drawStringShadowed(ofToString(ofGetFrameRate(),2), ofGetWidth()-35, ofGetHeight() - 6, ofColor::whiteSmoke, ofColor::black );
}
Ejemplo n.º 8
0
void ofApp::update() {

    ofSetWindowTitle(ofToString(ofGetFrameRate()));
    
    for (auto &thing : things) {
        thing.update();
    }
    
    if (tex.getWidth() < things.size()) {
        ofLogError() << "thing texture not big enough!";
        ofExit();
    }

    int l = tex.getWidth() * tex.getHeight() * 3;
    float pixa[l];
    
    for (int i = 0; i < things.size(); i++) {
        pixa[i * 3] = things[i].pos.x / ofGetWidth();
        pixa[i * 3 + 1] = things[i].pos.y / ofGetHeight();
        pixa[i * 3 + 2] = 0;
    }
    
    tex.loadData(pixa, tex.getWidth(), tex.getHeight(), GL_RGB);
}
Ejemplo n.º 9
0
//--------------------------------------------------------------
void ofApp::draw(){
    
    if(mode == 1) {
        ofPushMatrix();
//        ofTranslate(dx, dy);
//        ofScale(ofGetWidth()/kinect.width*dz,ofGetHeight()/kinect.height*dz);
//        input_image.draw(0,0);
        prettyContourFinder.draw(dx,dy, ofGetWidth()*dz, ofGetHeight()*dz);
//        input_image.draw(dx, dy, PROJECTOR_WIDTH*dz, PROJECTOR_HEIGHT*dz);
//        contourFinder.draw(dx, dy, ofGetWidth()*dz, ofGetHeight()*dz);
        ofPopMatrix();
    }
    else if (mode == 2) {
        ripples.draw(dx, dy, ofGetWidth()*dz, ofGetHeight()*dz);
//        input_image.draw(0, 0, ofGetWidth()*dz, ofGetHeight()*dz);
    }
    else if (mode == 3) {
        easyCam.begin();
        drawPointCloud();
        easyCam.end();
    }
    
    stringstream reportStream;
    reportStream << "Framerate: " << ofToString(ofGetFrameRate()) << endl
    << "Frame: " << ofToString(ofGetFrameNum()) << endl
    << "Threshold: " << threshold << endl
    << "Contour area: " << min_contour_area << endl
    << "Damping: " << ripples.damping << endl
    << "Tilt Angle: " << angle << endl
    << "RGB: " << red << ", " << green << ", " << blue << endl
//    << "Tempo: " << (1.0 / tempo) * 60 << "bpm" << endl;
    << (ofGetElapsedTimef() - lastBeat) / tempo << endl;
    if(display_feedback) {
        ofDrawBitmapString(reportStream.str(), 100, ofGetHeight() - 200);
    }
}
Ejemplo n.º 10
0
//--------------------------------------------------------------
void ofApp::update(){
	float dt = 1.0 / max(ofGetFrameRate(), 1.f); // more smooth as 'real' deltaTime.
	
	simpleCam.update();
	if (simpleCam.isFrameNew()) {
		cameraFbo.begin();
		simpleCam.draw(cameraFbo.getWidth(), 0, -cameraFbo.getWidth(), cameraFbo.getHeight());  // draw flipped
		cameraFbo.end();
		
		opticalFlow.setInput(cameraFbo.getTexture());
	}
	
	for (auto flow: mouseFlows) { flow->update(dt); }

	opticalFlow.update();
	
	velocityBridgeFlow.setVelocity(opticalFlow.getVelocity());
	velocityBridgeFlow.update(dt);
	densityBridgeFlow.setDensity(cameraFbo.getTexture());
	densityBridgeFlow.setVelocity(opticalFlow.getVelocity());
	densityBridgeFlow.update(dt);
	temperatureBridgeFlow.setDensity(cameraFbo.getTexture());
	temperatureBridgeFlow.setVelocity(opticalFlow.getVelocity());
	temperatureBridgeFlow.update(dt);
	
	fluidFlow.addVelocity(velocityBridgeFlow.getVelocity());
	fluidFlow.addDensity(densityBridgeFlow.getDensity());
	fluidFlow.addTemperature(temperatureBridgeFlow.getTemperature());
	for (auto flow: mouseFlows) { if (flow->didChange()) { fluidFlow.addFlow(flow->getType(), flow->getTexture()); } }
	fluidFlow.update(dt);
	
	pixelFlow.setInput(opticalFlow.getVelocity());
	for (auto flow: mouseFlows) { if (flow->didChange() && flow->getType() == FT_VELOCITY) { pixelFlow.addInput(flow->getTexture()); } }
	pixelFlow.update();
	for (auto& f : averageFlows) { f.update(pixelFlow.getPixels()); }
}
Ejemplo n.º 11
0
//--------------------------------------------------------------
void testApp::draw(){
    ofSetColor(255);
    controller.draw();
	if(drawGui)controller.drawGui();
    
	ofSetColor(100);
    ofDrawBitmapString(ofToString(ofGetFrameRate()), 20, 20);
    
    ofSetColor(255);
    ofDrawBitmapString("Press SPACE to toggle fullscreen.", 20, 40);
    ofDrawBitmapString("Press G to toggle GUI.", 20, 55);
    if(drawGui){
#ifdef TARGET_OSX
        ofDrawBitmapString("Use CMD+Z / CMD+SHIFT+Z to undo/redo changes.", 20, 100);
        ofDrawBitmapString("Use CMD+S to save changes.", 20, 115);
        ofDrawBitmapString("Use CMD+R to reload changes.", 20, 130);
#else
        ofDrawBitmapString("Use CTRL+Z / CTRL+SHIFT+Z to undo/redo changes.", 20, 100);
        ofDrawBitmapString("Use CTRL+S to save changes.", 20, 115);
        ofDrawBitmapString("Use CTRL+R to reload changes.", 20, 1130);
#endif
    }
	
}
Ejemplo n.º 12
0
//--------------------------------------------------------------
void ofApp::draw(){
	ofSetColor(255);
	video->draw(0,0);

	//aruco.draw();

	if(showMarkers){
		for(int i=0;i<aruco.getNumMarkers();i++){
			aruco.begin(i);
			drawMarker(0.15,ofColor::white);
			aruco.end();
		}
	}


	if(showBoard && aruco.getBoardProbability()>0.03){
		for(int i=0;i<aruco.getNumBoards();i++){
			aruco.beginBoard(i);
			drawMarker(.5,ofColor::red);
			aruco.end();
		}
	}
	

	ofSetColor(255);
	if(showBoardImage){
    	board.draw(ofGetWidth()-320,0,320,320*float(board.getHeight())/float(board.getWidth()));
    }
	ofDrawBitmapString("markers detected: " + ofToString(aruco.getNumMarkers()),20,20);
	ofDrawBitmapString("fps " + ofToString(ofGetFrameRate()),20,40);
	ofDrawBitmapString("m toggles markers",20,60);
	ofDrawBitmapString("b toggles board",20,80);
	ofDrawBitmapString("i toggles board image",20,100);
	ofDrawBitmapString("s saves board image",20,120);
	ofDrawBitmapString("0-9 saves marker image",20,140);
}
Ejemplo n.º 13
0
void ofApp::setup(){
    receiver.setup(PORT);
    ofSetVerticalSync(true);
    ofBackground(0, 0, 0);
    ofHideCursor();
    message= "";
    fileName= "";
    frames= 0;
    speed= 1.0;
    mode= SCALE;
    alpha= 0.f;
    steps= 255.f;
    type= NOTSET;
    ow= 0;
    oh= 0;
    x= 0;
    y= 0;
    w= ofGetScreenWidth();
    h= ofGetScreenHeight();
    info= false;
    cout<<"listening on port: "<<PORT<<"\n";
    cout<<"screen resolution: "<<ofGetScreenWidth()<<"x"<<ofGetScreenHeight()<<"\n";
    cout<<"default framerate: "<<ofGetFrameRate()<<"\n";
}
Ejemplo n.º 14
0
//--------------------------------------------------------------
void ofApp::draw(){
//    ofSetColor(245, 58, 135);
//    ofFill();


    if (camera_home == true){
      mx = ofGetWidth()/2;
      my = ofGetHeight()/2;
    }
    else if (camera_lock == false){
      mx += EaseIn(mx, float(mouseX), 0.05);
      my += EaseIn(my, float(mouseY), 0.05);
      if (abs(mouseX - mx) < 1) mx = mouseX;
      if (abs(mouseY - my) < 1) my = mouseY;
    }
    scale_display += EaseIn(scale_display, scale_target, 0.05);

    display.begin();
    ofBackground(34, 34, 34);
    waveShader_displayTiled.begin();
      waveShader_displayTiled.setUniform2f("mouse", mx, my);
      waveShader_displayTiled.setUniform1f("scale_factor", scale_display);
      waveShader_displayTiled.setUniform1i("pos", 0);
      height_Fbo0.draw(0,0);
    waveShader_displayTiled.end();

    waveShader_displayTiled.begin();
      waveShader_displayTiled.setUniform2f("mouse", mx, my);
      waveShader_displayTiled.setUniform1f("scale_factor", scale_display);
      waveShader_displayTiled.setUniform1i("pos", 1);
      height_Fbo1.draw(0,0);
    waveShader_displayTiled.end();

    waveShader_displayTiled.begin();
      waveShader_displayTiled.setUniform2f("mouse", mx, my);
      waveShader_displayTiled.setUniform1f("scale_factor", scale_display);
      waveShader_displayTiled.setUniform1i("pos", 2);
      height_Fbo2.draw(0,0);
    waveShader_displayTiled.end();

    waveShader_displayTiled.begin();
      waveShader_displayTiled.setUniform2f("mouse", mx, my);
      waveShader_displayTiled.setUniform1f("scale_factor", scale_display);
      waveShader_displayTiled.setUniform1i("pos", 3);
      height_Fbo3.draw(0,0);
    waveShader_displayTiled.end();
    display.end();

    // finally display the image
    display.draw(0,0);

    // show framerate at top left
    if (showFPS){
      ofSetColor(0);
      ofRect(10, 5, 60, 15);
      ofSetColor(255);
      string framerate = ofToString(ofGetFrameRate());
      font.drawString(framerate, 10, 18);

    }

//    cout<<"frame "<<frame_num<<endl;
}
Ejemplo n.º 15
0
//--------------------------------------------------------------
void ofApp::update() {
    ofSetWindowTitle(ofToString(ofGetFrameRate()));

    scene[selectedScene]->update();
}
Ejemplo n.º 16
0
//--------------------------------------------------------------
void ofApp::update()
{
	ofSetWindowTitle( ofToString(ofGetFrameRate() ) );
}
Ejemplo n.º 17
0
//--------------------------------------------------------------
void ballPond::setup(){
    
    ofSetFrameRate(60);
    
    //setup
	bShowDepth = false;
	bShowContour = false;
	bShowGray = false;
	bShowBlob = false;
	bShowRGB = false;
	bShowSkeleton = false;
	bDebug = false;
	bDistBlob = false;
    
    bThreshWithOpenCV = true;
	
	minBlobSize = 3000;
	
	resX = ofGetWidth();
	resY = ofGetHeight();
	
	particleRadius = 30.0;
	
    //kinect
	kinect.init();
	kinect.setVerbose(true);
	kinect.open();
    // zero the tilt on startup
	angle = 0;
	kinect.setCameraTiltAngle(angle);
    //depth thresholds
    nearThreshold = 197;
	farThreshold  = 58;
	
    //openCV
	colorImg.allocate(kinect.width, kinect.height);
	grayImage.allocate(kinect.width, kinect.height);
	grayThresh.allocate(kinect.width, kinect.height);
	grayThreshFar.allocate(kinect.width, kinect.height);
		
	//Box2D
	box2d.init();
	box2d.setGravity(0, 10);
	box2d.createBounds(0, 0, ofGetWidth(), ofGetHeight());
	box2d.checkBounds(true);
	box2d.setFPS(60.0);
	
	
	ofxBox2dLine lineStrip;
	for (int i = 0; i < 10; i++) {
		lineStripBlob.push_back(lineStrip);
	}
	clearLineStrip = 0;
	
	//Contour Analysis -> simplify
	simpleAmount = 3.2;
	//true = particles are outside
	bReversePoints = true;
	
	//ContactListener
	//contacts.Add(point, particles);
	box2d.getWorld() -> SetContactListener(&contacts);
	
	//Create Particles
	for( int i=0; i <= NUM_PARTICLES; i++ )
	{
		particles.push_back( Particle());
		Particle& circle = particles.back();
		
		float mass		= 7.0;
		float bounce	= 0.73;
		float friction	= 0.1;
		float radius	= particleRadius;
		
		circle.setPhysics( mass, bounce, friction );
		circle.setup( box2d.getWorld(), ofRandom( 0, ofGetWidth() ), ofRandom( 0, ofGetHeight() ), radius, false );
		circle.setVelocity( ofRandom( -10, 10 ), ofRandom( -10, 10 ) );
		
		//orange
		if (i < NUM_PARTICLES/5) {
			circle.r = 248;
			circle.g = 120;
			circle.b = 6;	
			circle.groupId = 1;
		}
		//purple
		else if(i >= NUM_PARTICLES/5 && i < (NUM_PARTICLES/5) * 2)
		{
			circle.r = 160;
			circle.g = 14;
			circle.b = 242;
			circle.groupId = 2;
		}
		//green
		else if(i >= (NUM_PARTICLES/5) * 2 && i < (NUM_PARTICLES/5) * 3)
		{
			circle.r = 152;
			circle.g = 189;
			circle.b = 8;
			circle.groupId = 3;
		}
		//magenta
		else if(i >= (NUM_PARTICLES/5) * 3 && i < (NUM_PARTICLES/5) * 4)
		{
			circle.r = 200;
			circle.g = 29;
			circle.b = 89;
			circle.groupId = 4;
		}
		//blue
		else if(i >= (NUM_PARTICLES/5) * 4 && i <= NUM_PARTICLES)
		{
			circle.r = 40;
			circle.g = 157;
			circle.b = 224;	
			circle.groupId = 5;
		}
	}
	
	contacts.init(particles);
    
	//Sound
	/*
    ambient.loadSound("ambient_loop.mp3");
	ambient.setLoop(true);
	ambient.setVolume(0.75f);
	ambient.play();
    */
	
	for (int i = 0; i < NUM_GUITAR; i++) {
		ofSoundPlayer guitarSound;
		guitar.push_back(guitarSound);
		if(i < 8)
			guitar[i].setVolume(0.75f);
		else {
			guitar[i].setVolume(0.4f);
		}
		guitar[i].setMultiPlay(true);
	}
	
	//GUITAR SOUND
	guitar[0].loadSound("Gitarre/gitarre1.mp3");
	guitar[1].loadSound("Gitarre/gitarre2.mp3");
	guitar[2].loadSound("Gitarre/gitarre3.mp3");
	guitar[3].loadSound("Gitarre/gitarre4.mp3");
	guitar[4].loadSound("Gitarre/gitarre5.mp3");
	guitar[5].loadSound("Gitarre/gitarre6.mp3");
	guitar[6].loadSound("Gitarre/gitarre7.mp3");
	guitar[7].loadSound("Gitarre/gitarre8.mp3");
	guitar[8].loadSound("Piano/1.mp3");
	guitar[9].loadSound("Piano/2.mp3");
	guitar[10].loadSound("Piano/3.mp3");
	guitar[11].loadSound("Piano/4.mp3");
	guitar[12].loadSound("Piano/5.mp3");
	guitar[13].loadSound("Piano/6.mp3");
	guitar[14].loadSound("Piano/7.mp3");
	guitar[15].loadSound("Piano/8.mp3");
	
	//Background Image
	background.loadImage("background_2.jpg");
	
	//load Font for Debug text
	verdana.loadFont("verdana.ttf",8, false, true);
	verdana.setLineHeight(16.0f);
	
	//create TXT file
	myfile.open(ofToDataPath("distance.txt").c_str(), ios::out | ios::app | ios::binary);
	
	mySeconds = ofGetSeconds();
	
	tempFrameRate = int(ofGetFrameRate()*50);
	saveTime = int(ofGetFrameRate()*10);
	tempTime = 0;
	
	tempFrameRateSec = int(ofGetFrameRate()*5);
	saveTimeSec = int(ofGetFrameRate()*1);
	tempTimeSec = 0;
    
}
Ejemplo n.º 18
0
//--------------------------------------------------------------
void ofApp::update()
{
    dmxLightsAndSmokeMessage[1] = 255;
    dmxLightsAndSmokeMessage[2] = 255;
    dmxLightsAndSmokeMessage[3] = 255;
    ofBackground(100, 100, 100);

    kinect.update();
    smoke.update();

    //if (!kinect.isFrameNew()) { return; }
    if (kinect.isFrameNew())
    {
        updateCvImages();
        cvfilter.update(kinect.getDepthPixels());

        contourFinder.findContours(cvfilter.getThreshImage(), 500, (kinect.width*kinect.height) / 2, 5, false, true);
        contoursManager.processContours(contourFinder.blobs);

        contoursManager.collectContours();

        colorImg.setFromPixels(kinect.getPixels(), kinect.width, kinect.height);
    }

    // draw the contours, and make the smoke see it as an obstacle
    smoke.begin();

    ofPushMatrix();

    ofScale(WIDTH / (float)kinect.width, HEIGHT / (float)kinect.height);

    contoursManager.contourMesh.draw();

    ofPopMatrix();

    smoke.end();

    // show framerate in titlebar
    ofSetWindowTitle(ofToString(ofGetFrameRate()));

    sendOsc();

    // DMX

    if (contourFinder.blobs.size() == 0 && !isDmxLightAndSmokeTimerStarted)
    {
        dmxLightsAndSmokeTimer = ofGetElapsedTimef();
        isDmxLightAndSmokeTimerStarted = true;
    }
    else if (contourFinder.blobs.size() > 0 && isDmxLightAndSmokeTimerStarted)
    {
        isDmxLightAndSmokeTimerStarted = false;
    }

    if ( ofGetElapsedTimef() - dmxLightsAndSmokeTimer > 10)
    {
        dmxLightsAndSmokeMessage[2] = 0;
        dmxLightsAndSmokeMessage[3] = 0;
        dmxLightsAndSmokeMessage[4] = 255;
    }
    else
    {
        dmxLightsAndSmokeMessage[2] = 0;
        dmxLightsAndSmokeMessage[3] = 255;
        dmxLightsAndSmokeMessage[4] = 0;
    }

    for (unsigned int i = 0; i < dmxLightsAndSmokeMessage.size(); i++)
    {
        dmxLightsAndSmoke.setLevel(i+1, dmxLightsAndSmokeMessage[i]);
    }

    if (dmxLightsAndSmoke.isConnected())
    {
        dmxLightsAndSmoke.update();
    }
}
Ejemplo n.º 19
0
//--------------------------------------------------------------
void testApp::update(){
    //fbo
    rgbaFboFloat.begin();
    drawFboTest();
	rgbaFboFloat.end();
    // sort all the dwgParti:
	sort( bgParti.begin(), bgParti.end(), comparisonFunction );
    for (int i = 0; i < bgParti.size(); i++){
		bgParti[i]->resetForce();
	}
    
    for (int i = 0; i < bgParti.size(); i++){
		for (int j = i-1; j >= 0; j--){
			if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) >	50) break;
            if (i != j){
                bgParti[i]->addForFlocking(*bgParti[j]);
            }
		}
        bgParti[i]->addRepulsionForce(mouseX, mouseY, 40, 0.4);
	}
    
	for (int i = 0; i < bgParti.size(); i++){
		bgParti[i]->addFlockingForce();
		bgParti[i]->addDampingForce();
		bgParti[i]->update();
	}
	
	
	// wrap torroidally.
	for (int i = 0; i < bgParti.size(); i++){
		ofVec2f pos = bgParti[i]->pos;
		if (pos.x < 0) pos.x = ofGetWidth();
		if (pos.x > ofGetWidth()) pos.x = 0;
		if (pos.y < 0) pos.y = ofGetHeight();
		if (pos.y > ofGetHeight()) pos.y = 0;
		bgParti[i]->pos = pos;
	}
    
    
    //osc
    
    // hide old messages
	for(int i = 0; i < NUM_MSG_STRINGS; i++){
		if(timers[i] < ofGetElapsedTimef()){
			msg_strings[i] = "";
		}
	}
    
	// check for waiting messages
	while(receiver.hasWaitingMessages()){
		// get the next message
		ofxOscMessage m;
		receiver.getNextMessage(&m);
        for (int i = 0; i < dwgParti.size(); i++){
            // check for mouse moved message
            if(m.getAddress() == "/accel/x"){
                bgParti[i]->r3 = m.getArgAsFloat(0);
                bgParti[i]->vel.x += m.getArgAsFloat(0);
                cout << m.getArgAsFloat(0) << endl;
            }
            
            if(m.getAddress() == "/accel/y"){
                bgParti[i]->r2 = m.getArgAsFloat(0);
                bgParti[i]->vel.y += m.getArgAsFloat(0);
            }
            
            if(m.getAddress() == "/accel/z"){
                bgParti[i]->r1 = m.getArgAsFloat(0);
                bgParti[i]->vel.z += m.getArgAsFloat(0);
            }
            
            
            if(m.getAddress() == "/hue"){
                bgParti[i]->c.setHue(m.getArgAsFloat(0));
            }
            
            if(m.getAddress() == "/sat"){
                bgParti[i]->c.setSaturation(m.getArgAsFloat(0));
            }
            
            
            else{
                // unrecognized message: display on the bottom of the screen
                string msg_string;
                msg_string = m.getAddress();
                msg_string += ": ";
                for(int i = 0; i < m.getNumArgs(); i++){
                    // get he argument type
                    msg_string += m.getArgTypeName(i);
                    msg_string += ":";
                    // display the argument - make sure we get the right type
                    if(m.getArgType(i) == OFXOSC_TYPE_INT32){
                        msg_string += ofToString(m.getArgAsInt32(i));
                    }
                    else if(m.getArgType(i) == OFXOSC_TYPE_FLOAT){
                        msg_string += ofToString(m.getArgAsFloat(i));
                    }
                    else if(m.getArgType(i) == OFXOSC_TYPE_STRING){
                        msg_string += m.getArgAsString(i);
                    }
                    else{
                        msg_string += "unknown";
                    }
                }
                // add to the list of strings to display
                msg_strings[current_msg_string] = msg_string;
                timers[current_msg_string] = ofGetElapsedTimef() + 5.0f;
                current_msg_string = (current_msg_string + 1) % NUM_MSG_STRINGS;
                // clear the next line
                msg_strings[current_msg_string] = "";
            }
            
        }
        
	}
    
    ofPushView();
    ofPushStyle();
    
    ofPushMatrix();
    
    ofEnableBlendMode(OF_BLENDMODE_ALPHA);
    ofClear(0, 255);
    
    float fade = abs(sin( ofGetElapsedTimef()*0.099 ));
    ofSetColor( ofMap( fade , 0.0f, 0.5f, 0.0f, 1.0f, true) * 255,255);
    
    ofDisableBlendMode();
    ofPopMatrix();
    
    ofPopView();
    ofPopStyle();
    
    ofSetWindowTitle(ofToString(ofGetFrameRate()));
    
    //osc
    
    // hide old messages
	for(int i = 0; i < NUM_MSG_STRINGS; i++){
		if(timers[i] < ofGetElapsedTimef()){
			msg_strings[i] = "";
		}
	}
    
	// check for waiting messages
	while(receiver.hasWaitingMessages()){
		// get the next message
		ofxOscMessage m;
		receiver.getNextMessage(&m);
        for (int i = 0; i < dwgParti.size(); i++){
            // check for mouse moved message
            if(m.getAddress() == "/accel/x"){
                dwgParti[i].r3 = m.getArgAsFloat(0);
                dwgParti[i].vel.x += m.getArgAsFloat(0);
                cout << m.getArgAsFloat(0) << endl;
            }
            
            if(m.getAddress() == "/accel/y"){
                dwgParti[i].r2 = m.getArgAsFloat(0);
                dwgParti[i].vel.y += m.getArgAsFloat(0);
            }
            
            if(m.getAddress() == "/accel/z"){
                dwgParti[i].r1 = m.getArgAsFloat(0);
                dwgParti[i].vel.z += m.getArgAsFloat(0);
            }
            
            
            if(m.getAddress() == "/hue"){
                dwgParti[i].c.setHue(m.getArgAsFloat(0));
            }
            
            if(m.getAddress() == "/sat"){
                dwgParti[i].c.setSaturation(m.getArgAsFloat(0));
            }
            
            
            else{
                // unrecognized message: display on the bottom of the screen
                string msg_string;
                msg_string = m.getAddress();
                msg_string += ": ";
                for(int i = 0; i < m.getNumArgs(); i++){
                    // get he argument type
                    msg_string += m.getArgTypeName(i);
                    msg_string += ":";
                    // display the argument - make sure we get the right type
                    if(m.getArgType(i) == OFXOSC_TYPE_INT32){
                        msg_string += ofToString(m.getArgAsInt32(i));
                    }
                    else if(m.getArgType(i) == OFXOSC_TYPE_FLOAT){
                        msg_string += ofToString(m.getArgAsFloat(i));
                    }
                    else if(m.getArgType(i) == OFXOSC_TYPE_STRING){
                        msg_string += m.getArgAsString(i);
                    }
                    else{
                        msg_string += "unknown";
                    }
                }
                // add to the list of strings to display
                msg_strings[current_msg_string] = msg_string;
                timers[current_msg_string] = ofGetElapsedTimef() + 5.0f;
                current_msg_string = (current_msg_string + 1) % NUM_MSG_STRINGS;
                // clear the next line
                msg_strings[current_msg_string] = "";
            }
            
        }
        
	}
    
    
    // number == 1 +++++++++++++++++++++++++++++++++++++
    
    
    if(number==1) {
        
        // background dwgParti
        
        sort( bgParti.begin(), bgParti.end(), comparisonFunction );
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->cohesion.strength = 0.1;
            bgParti[i]->cohesion.distance = 50;
            bgParti[i]->alignment.strength =  0.7;
            bgParti[i]->alignment.distance = 42;
            bgParti[i]->seperation.strength = 0.7;
            bgParti[i]->seperation.distance = 38;
            bgParti[i]->damping = 0.08;            
        }
        
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->resetForce();
        }
        
        
        for (int i = 0; i < bgParti.size(); i++){
            for (int j = i-1; j >= 0; j--){
                if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) >	50) break;
                if (i != j){
                    bgParti[i]->addForFlocking(*bgParti[j]);
                }
            }
        }

//            for (int i = 0; i < bgParti.size(); i++){
//                bgParti[i]->c.set(ofRandom(100,255),0,ofRandom(0,50),50);
//        }
//        
//        
//        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->addFlockingForce();
            bgParti[i]->addDampingForce();
            bgParti[i]->update();
        }
        
        // wrap torroidally.
        for (int i = 0; i < bgParti.size(); i++){
            ofVec2f pos = bgParti[i]->pos;
            if (pos.x < 0) pos.x = ofGetWidth();
            if (pos.x > ofGetWidth()) pos.x = 0;
            if (pos.y < 0) pos.y = ofGetHeight();
            if (pos.y > ofGetHeight()) pos.y = 0;
            bgParti[i]->pos = pos;
        }

    };
    
    
    
    // number == 2 addAttractionForce to Mouse +++++++++++++++++++++++++++++++++++++
    
    if(number==2)  {
        
        
        // background dwgParti
        
        sort( bgParti.begin(), bgParti.end(), comparisonFunction );
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->cohesion.strength = 0.76;
            bgParti[i]->cohesion.distance = 50;
            bgParti[i]->alignment.strength =  0.5;
            bgParti[i]->alignment.distance = 130;
            bgParti[i]->seperation.strength = 0.4;
            bgParti[i]->seperation.distance = 157;
            bgParti[i]->damping = 0.192;
        }
        
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->resetForce();
        }
        
        
        for (int i = 0; i < bgParti.size(); i++){
            for (int j = i-1; j >= 0; j--){
                if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) >	50) break;
                if (i != j){
                    bgParti[i]->addForFlocking(*bgParti[j]);
                }
            }
        }
        
        
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->addFlockingForce();
            bgParti[i]->addDampingForce();
            bgParti[i]->update();
        }
        
        
        // wrap torroidally.
        for (int i = 0; i < bgParti.size(); i++){
            ofVec2f pos = bgParti[i]->pos;
            if (pos.x < 0) pos.x = ofGetWidth();
            if (pos.x > ofGetWidth()) pos.x = 0;
            if (pos.y < 0) pos.y = ofGetHeight();
            if (pos.y > ofGetHeight()) pos.y = 0;
            bgParti[i]->pos = pos;
        }
    }
    
    
    // number == 3  addRepulsionForce to Mouse  +++++++++++++++++++++++++++++++++++++
    
    if(number==3)  {
        
        // background dwgParti
        
        sort( bgParti.begin(), bgParti.end(), comparisonFunction );
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->cohesion.strength = 0.2;
            bgParti[i]->cohesion.distance = 200;
            bgParti[i]->alignment.strength =  0.24;
            bgParti[i]->alignment.distance = 198;
            bgParti[i]->seperation.strength = 0.4;
            bgParti[i]->seperation.distance = 33;
            bgParti[i]->damping = 0.029;
        }
        
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->resetForce();
        }
        
        
        for (int i = 0; i < bgParti.size(); i++){
            for (int j = i-1; j >= 0; j--){
                if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) >	50) break;
                if (i != j){
                    bgParti[i]->addForFlocking(*bgParti[j]);
                }
            }
        }
        
        
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->addFlockingForce();
            bgParti[i]->addDampingForce();
            bgParti[i]->update();
        }
        
        
        // wrap torroidally.
        for (int i = 0; i < bgParti.size(); i++){
            ofVec2f pos = bgParti[i]->pos;
            if (pos.x < 0) pos.x = ofGetWidth();
            if (pos.x > ofGetWidth()) pos.x = 0;
            if (pos.y < 0) pos.y = ofGetHeight();
            if (pos.y > ofGetHeight()) pos.y = 0;
            bgParti[i]->pos = pos;
        }
        
        
        
         }
    // number == 4  seperation.distance +++++++++++++++++++++++++++++++++++++
    
    if(number == 4) {
        
        // background dwgParti
        
        sort( bgParti.begin(), bgParti.end(), comparisonFunction );
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->cohesion.strength = 0.19;
            bgParti[i]->cohesion.distance = 200;
            bgParti[i]->alignment.strength =  0.2;
            bgParti[i]->alignment.distance = 175;
            bgParti[i]->seperation.strength = 0.46;
            bgParti[i]->seperation.distance = 200;
            bgParti[i]->damping = 0.45;
        }
        
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->resetForce();
        }
        
        
        for (int i = 0; i < bgParti.size(); i++){
            for (int j = i-1; j >= 0; j--){
                if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) >	50) break;
                if (i != j){
                    bgParti[i]->addForFlocking(*bgParti[j]);
                }
            }
        }
        
        
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->addFlockingForce();
            bgParti[i]->addDampingForce();
            bgParti[i]->update();
        }
        
        
        // wrap torroidally.
        for (int i = 0; i < bgParti.size(); i++){
            ofVec2f pos = bgParti[i]->pos;
            if (pos.x < 0) pos.x = ofGetWidth();
            if (pos.x > ofGetWidth()) pos.x = 0;
            if (pos.y < 0) pos.y = ofGetHeight();
            if (pos.y > ofGetHeight()) pos.y = 0;
            bgParti[i]->pos = pos;
        }
        
        
         }
    
    
    
    // number == 5  +++++++++++++++++++++++++++++++++++++
    
    if(number == 5) {
        // background dwgParti
        
        sort( bgParti.begin(), bgParti.end(), comparisonFunction );
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->cohesion.strength = 0.5;
            bgParti[i]->cohesion.distance = 100;
            bgParti[i]->alignment.strength =  0.38;
            bgParti[i]->alignment.distance = 52;
            bgParti[i]->seperation.strength = 0.9;
            bgParti[i]->seperation.distance = 15;
            bgParti[i]->damping = 0.68;
        }
        
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->resetForce();
        }
        
        
        for (int i = 0; i < bgParti.size(); i++){
            for (int j = i-1; j >= 0; j--){
                if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) >	50) break;
                if (i != j){
                    bgParti[i]->addForFlocking(*bgParti[j]);
                }
            }
        }
        
        
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->addFlockingForce();
            bgParti[i]->addDampingForce();
            bgParti[i]->update();
        }
        
        
        // wrap torroidally.
        for (int i = 0; i < bgParti.size(); i++){
            ofVec2f pos = bgParti[i]->pos;
            if (pos.x < 0) pos.x = ofGetWidth();
            if (pos.x > ofGetWidth()) pos.x = 0;
            if (pos.y < 0) pos.y = ofGetHeight();
            if (pos.y > ofGetHeight()) pos.y = 0;
            bgParti[i]->pos = pos;
        }
        
        
      }
    
    
// number == 6 repulsion = sound +++++++++++++++++++++++++++++++++++++
    
    
        if(number == 6) {
            // background dwgParti
            
            sort( bgParti.begin(), bgParti.end(), comparisonFunction );
            
            for (int i = 0; i < bgParti.size(); i++){
                bgParti[i]->cohesion.strength = 0.20;
                bgParti[i]->cohesion.distance = 10;
                bgParti[i]->alignment.strength =  0.31;
                bgParti[i]->alignment.distance = 200;
                bgParti[i]->seperation.strength = 0.4;
                bgParti[i]->seperation.distance = 2;
                bgParti[i]->damping = 0.20;
            }
            
            
            for (int i = 0; i < bgParti.size(); i++){
                bgParti[i]->resetForce();
            }
            
            
            for (int i = 0; i < bgParti.size(); i++){
                for (int j = i-1; j >= 0; j--){
                    if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) >50) break;
                    if (i != j){
                        bgParti[i]->addForFlocking(*bgParti[j]);
                    }
                }
            }
            
            
            
            for (int i = 0; i < bgParti.size(); i++){
                bgParti[i]->addFlockingForce();
                bgParti[i]->addDampingForce();
                bgParti[i]->update();
            }
            
            
            // wrap torroidally.
            for (int i = 0; i < bgParti.size(); i++){
                ofVec2f pos = bgParti[i]->pos;
                if (pos.x < 0) pos.x = ofGetWidth();
                if (pos.x > ofGetWidth()) pos.x = 0;
                if (pos.y < 0) pos.y = ofGetHeight();
                if (pos.y > ofGetHeight()) pos.y = 0;
                bgParti[i]->pos = pos;
            }
            
            
        }
    
    
    
    
    // number == 7 repulsion  +++++++++++++++++++++++++++++++++++++
    
    if(number == 7) {
        
            // background dwgParti
            
            sort( bgParti.begin(), bgParti.end(), comparisonFunction );
            
            for (int i = 0; i < bgParti.size(); i++){
                bgParti[i]->cohesion.strength = 0.20;
                bgParti[i]->cohesion.distance = 100;
                bgParti[i]->alignment.strength =  0.31;
                bgParti[i]->alignment.distance = 20;
                bgParti[i]->seperation.strength = 0.4;
                bgParti[i]->seperation.distance = 2;
                bgParti[i]->damping = 0.8;
            }
            
            
            for (int i = 0; i < bgParti.size(); i++){
                bgParti[i]->resetForce();
            }
            
            
            for (int i = 0; i < bgParti.size(); i++){
                for (int j = i-1; j >= 0; j--){
                    if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) >50) break;
                    if (i != j){
                        bgParti[i]->addForFlocking(*bgParti[j]);
                    }
                }
            }
            
            
            
            for (int i = 0; i < bgParti.size(); i++){
                bgParti[i]->addFlockingForce();
                bgParti[i]->addDampingForce();
                bgParti[i]->update();
            }
            
            
            // wrap torroidally.
            for (int i = 0; i < bgParti.size(); i++){
                ofVec2f pos = bgParti[i]->pos;
                if (pos.x < 0) pos.x = ofGetWidth();
                if (pos.x > ofGetWidth()) pos.x = 0;
                if (pos.y < 0) pos.y = ofGetHeight();
                if (pos.y > ofGetHeight()) pos.y = 0;
                bgParti[i]->pos = pos;
            }
            
            
        }
        
    
    // number == 8  +++++++++++++++++++++++++++++++++++++
    
    if(number == 8) {
        
        // background dwgParti
        
        sort( bgParti.begin(), bgParti.end(), comparisonFunction );
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->cohesion.strength = 0.43;
            bgParti[i]->cohesion.distance = 13.3;
            bgParti[i]->alignment.strength =  0.2;
            bgParti[i]->alignment.distance = 16.7;
            bgParti[i]->seperation.strength = 0.73;
            bgParti[i]->seperation.distance = 105;
            bgParti[i]->damping = 0.3;
        }
        
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->resetForce();
        }
        
        
        for (int i = 0; i < bgParti.size(); i++){
            for (int j = i-1; j >= 0; j--){
                if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) >50) break;
                if (i != j){
                    bgParti[i]->addForFlocking(*bgParti[j]);
                }
            }
        }
        
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->addFlockingForce();
            bgParti[i]->addDampingForce();
            bgParti[i]->update();
        }
        
        
    }

    
    // number == 9  +++++++++++++++++++++++++++++++++++++
    
    if(number == 9) {
        
        // background dwgParti
        
        sort( bgParti.begin(), bgParti.end(), comparisonFunction );
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->cohesion.strength = 1;
            bgParti[i]->cohesion.distance = 200;
            bgParti[i]->alignment.strength =  0.5;
            bgParti[i]->alignment.distance = 200;
            bgParti[i]->seperation.strength = 0.77;
            bgParti[i]->seperation.distance = 84.4;
            bgParti[i]->damping = 0.2;
        }
        
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->resetForce();
        }
        
        
        for (int i = 0; i < bgParti.size(); i++){
            for (int j = i-1; j >= 0; j--){
                if ( fabs(bgParti[j]->pos.x - bgParti[i]->pos.x) >50) break;
                if (i != j){
                    bgParti[i]->addForFlocking(*bgParti[j]);
                }
            }
        }
        
        
        for (int i = 0; i < bgParti.size(); i++){
            bgParti[i]->addFlockingForce();
            bgParti[i]->addDampingForce();
            bgParti[i]->update();
        }
        
        
    }
    

    
    
       // number == 11 == draw +++++++++++++++++++++++++++++++++++++

    // font dwgParti
    
    
    if(number == 11) {
    
    for (int i = 0; i < dwgParti.size(); i++){
        dwgParti[i].resetForce();
    }
      blendMode = OF_BLENDMODE_SCREEN;
    for (int i = 0; i < dwgParti.size(); i++){
        
        dwgParti[i].addAttractionForce(mouseX, mouseY, 1000, 0.5);
        dwgParti[i].alignment.strength = scaledVol*2000;
        dwgParti[i].c.set(255,ofRandom(100,250),255);
        
        
        for (int j = 0; j < i; j++){
            if (bRepel){
                dwgParti[i].addRepulsionForce(dwgParti[j], radius, strength);
            } else {
                dwgParti[i].addAttractionForce(dwgParti[j], radius, strength);
            }
        }
    }
    
    for (int i = 0; i < dwgParti.size(); i++){
        dwgParti[i].addDampingForce();
        dwgParti[i].update();
    }
    

}

    
// number == 12 == draw +++++++++++++++++++++++++++++++++++++
    
    // font dwgParti
    
    if(number == 12) {

    
    // font dwgParti
    
    for (int i = 0; i < dwgParti.size(); i++){
        dwgParti[i].resetForce();
    }
    
    
    for (int i = 0; i < dwgParti.size(); i++){
        
        dwgParti[i].addAttractionForce(mouseX, mouseY, 1000, 0.5);
        // dwgParti[i].scl.x = 500;
        // dwgParti[i].scl.y = 500;
        
        for (int j = 0; j < i; j++){
            if (bRepel){
                dwgParti[i].addRepulsionForce(dwgParti[j], radius + smoothedVol * 3000, strength);
            } else {
                dwgParti[i].addAttractionForce(dwgParti[j], radius , strength);
            }
        }
    }
    
    for (int i = 0; i < dwgParti.size(); i++){
        dwgParti[i].addDampingForce();
        dwgParti[i].damping = 0.1;
        dwgParti[i].update();
    }
    }
    
    
// number == 13 == draw +++++++++++++++++++++++++++++++++++++
    
    // font dwgParti
    
    if(number == 13) {
  
    
    // font dwgParti 
    
    for (int i = 0; i < dwgParti.size(); i++){
        dwgParti[i].resetForce();
    }
    
    for (int i = 0; i < dwgParti.size(); i++){
        
        for (int j = 0; j < dwgParti.size(); j++){
            if (i != j){
                dwgParti[i].addForFlocking(dwgParti[j]);
            }
        }
        
    }
    
    
    
    for (int i = 0; i < dwgParti.size(); i++){
        
        dwgParti[i].damping = smoothedVol*200;
    }
    
    for (int i = 0; i < dwgParti.size(); i++){
        
        dwgParti[i].addFlockingForce();
        dwgParti[i].addDampingForce();
        dwgParti[i].update();
    }
    
    
    // wrap torroidally.
    for (int i = 0; i < dwgParti.size(); i++){
        ofVec2f pos = dwgParti[i].pos;
        if (pos.x < 0) pos.x = ofGetWidth();
        if (pos.x > ofGetWidth()) pos.x = 0;
        if (pos.y < 0) pos.y = ofGetHeight();
        if (pos.y > ofGetHeight()) pos.y = 0;
        dwgParti[i].pos = pos;
    }
    

}
    
   // number == 14 == draw +++++++++++++++++++++++++++++++++++++
    
    // font dwgParti
    
    if(number == 14) {
        
    for (int i = 0; i < dwgParti.size(); i++){
        dwgParti[i].resetForce();
    }
    
    
    for (int i = 0; i < dwgParti.size(); i++){
        for (int j = 0; j < dwgParti.size(); j++){
            if (i != j){
                dwgParti[i].addForFlocking(dwgParti[j]);
            }
        }
        
        // this was something we tried in class (partitcle move away from mouse...)
        dwgParti[i].addRepulsionForce(mouseX, mouseY, 40, 0.4);
    }
    
    for (int i = 0; i < dwgParti.size(); i++){
        dwgParti[i].addFlockingForce();
        dwgParti[i].addDampingForce();
        dwgParti[i].update();
    }
    
    
    // wrap torroidally.
    for (int i = 0; i < dwgParti.size(); i++){
        ofVec2f pos = dwgParti[i].pos;
        if (pos.x < 0) pos.x = ofGetWidth();
        if (pos.x > ofGetWidth()) pos.x = 0;
        if (pos.y < 0) pos.y = ofGetHeight();
        if (pos.y > ofGetHeight()) pos.y = 0;
        dwgParti[i].pos = pos;
    }
    
    for (int i = 0; i < dwgParti.size(); i++){
        dwgParti[i].seperation.distance = smoothedVol*1000 ;
        dwgParti[i].seperation.strength = 23;
        dwgParti[i].damping = 0.13;
        
        dwgParti[i].addAttractionForce(mouseX, mouseY, 1000, 0.5);
        
    }
}
    
    
    
    // number == 15 == Launch +++++++++++++++++++++++++++++++++++++
    
    if(number == 15) {
        
   
    for (int i = 0; i < dwgParti.size(); i++){
        dwgParti[i].resetForce();
    }
    
    for (int i = 0; i < dwgParti.size(); i++){
        for (int j = 0; j < dwgParti.size(); j++){
            if (i != j){
                dwgParti[i].addForFlocking(dwgParti[j]);
            }
        }
        
        
        // this was something we tried in class (partitcle move away from mouse...)
        dwgParti[i].addRepulsionForce(mouseX, mouseY, 40, 0.4);
    }
    
    for (int i = 0; i < dwgParti.size(); i++){
        
        
        dwgParti[i].addFlockingForce();
        dwgParti[i].cohesion.strength = smoothedVol*100;
        dwgParti[i].damping = 0.05;
        dwgParti[i].addDampingForce();
        dwgParti[i].update();
    }
    
    
    // wrap torroidally.
    for (int i = 0; i < dwgParti.size(); i++){
        ofVec2f pos = dwgParti[i].pos;
        if (pos.x < 0) pos.x = ofGetWidth();
        if (pos.x > ofGetWidth()) pos.x = 0;
        if (pos.y < 0) pos.y = ofGetHeight();
        if (pos.y > ofGetHeight()) pos.y = 0;
        dwgParti[i].pos = pos;
    }
    
}
    
    
    // number == 17 == Launch +++++++++++++++++++++++++++++++++++++
    
    if(number == 17) {
        
        for (int i = 0; i < dwgParti.size(); i++){
            dwgParti[i].resetForce();
        }
        
        for (int i = 0; i < dwgParti.size(); i++){
            
            dwgParti[i].addAttractionForce(mouseX, mouseY, 1000, 0.5);
            dwgParti[i].c.set(ofRandom(100,255), ofRandom(100,255), ofRandom(100,255));
            
            for (int j = 0; j < i; j++){
                if (bRepel){
                    dwgParti[i].addRepulsionForce(dwgParti[j], radius+200, strength);
                } else {
                    dwgParti[i].addAttractionForce(dwgParti[j], radius, strength);
                }
            }
        }
        
        for (int i = 0; i < dwgParti.size(); i++){
            dwgParti[i].addDampingForce();
            dwgParti[i].update();
        }
        
    }
    
    

    

    //tail testing
    timePoint temp;
    
  	temp.t = ofGetElapsedTimef() - startTime;
	pts.push_back(temp);
	
    
    if(number==0) {
        
        if (pts.size() > 750){
            pts.erase(pts.begin());
        }
        
    }

}
Ejemplo n.º 20
0
void
Faces::setFragLifeTimeBySec(unsigned long long lifetime)
{
    fragLifeTimeBySec = lifetime;
    fragLifeTime = fragLifeTimeBySec * ofGetFrameRate();
}
Ejemplo n.º 21
0
Faces::Faces(b2World* aWorld, b2Vec2* vertices, int maxVCount, float xx, float yy, int idx, bool _isReal, bool isOrigin, int dupIdx)
{
    

    for (int i = 0; i < kMAX_VERTICES; i++) {
        mVertice[i] = vertices[i];
    }
    
    mWorld = aWorld;
    posX = xx;
    posY = yy;
    maxVertexCount = maxVCount;
    index = idx;
    dupIndex = dupIdx;
    isOriginal = isOrigin;
    isBreaked = false;
    isReal = _isReal;
    
    fragLifeTimeBySec = 12.0f;
    fragLifeTime = fragLifeTimeBySec * ofGetFrameRate();
    
    
    if (isReal){
        
        isAlive = true;
        isThereMbodybool = true;
        fragNum = kMAX_VERTICES/kSAMPLING_INTV;

    //	// open an outgoing connection to HOST:PORT
    //    sender = new ofxOscSender();
    //	sender->setup(HOST, PORT);
        
        
        // Set Userdata
//        if (isOriginal){
//            pBodyUserData = (index * 100) + POLYGON_BODY;
//        }else{
//            pBodyUserData = (index * 10000) + (dupIndex * 100) + POLYGON_BODY;
//        }
        pBodyUserData = POLYGON_BODY;
        smallBodyUserData = OT_BODY;
        
        curSection = 0;
        curPointofSection = 0;

        
        // outline tarcker
        rotSpd = 1.0f;
        audioLen = 0.f;
        getSection();
        
        
        
        // vec direction check - CCw
    //    for (int i = 0; i < 4; i++){
    //        printf("vec[%d] x: %f, y: %f\n", i, vertices[i].x, vertices[i].y);
    //    }
        
        for (int i = 0; i < maxVertexCount; i++) {
            mPts[i].x = _toWorldX(vertices[i].x);
            mPts[i].y = _toWorldY(vertices[i].y);
        }
        
        
        b2BodyDef myBodyDef;
        myBodyDef.type = b2_dynamicBody;
        myBodyDef.position.Set(0, 0);
    //    myBodyDef.position.Set(_toWorldX(posX), _toWorldY(posY));
    //    myBodyDef.linearVelocity.Set(4.0f, 0);
        mBody = mWorld -> CreateBody(&myBodyDef);
    //    mBody2 = mWorld -> CreateBody(&myBodyDef);
        
        
    #ifdef POLYGON_BODY
        // Polygon body
        b2PolygonShape myPolygonShape;
        for (int i = 0; i < kMAX_VERTICES - 1; i++) {
            mPtsP[i].x = mPts[i].x * 1.0;
            mPtsP[i].y = mPts[i].y * 1.0;
        }
        
        myPolygonShape.Set(mPtsP, maxVertexCount);
    #else
        // Chain loop body
        b2ChainShape chain;
        chain.CreateLoop(mPts, maxVertexCount);
    #endif
        
        
        
        b2FixtureDef myFixtureDef;
    //	b2FixtureDef myFixtureDef2;
        
    #ifdef POLYGON_BODY
    //	myFixtureDef2.shape = &myPolygonShape;
        myFixtureDef.shape = &myPolygonShape;
    #else
        myFixtureDef.shape = &chain;

    #endif
        
        myFixtureDef.density = 1.f;
        myFixtureDef.restitution = 0.8f;
        mBody->CreateFixture(&myFixtureDef);
        mBody->SetUserData((void*)pBodyUserData);
    //    mBody->SetLinearVelocity(b2Vec2(1.f, 0));

        
    //	myFixtureDef2.density = 1.f;
    //    myFixtureDef2.restitution = 0.8f;
    //    mBody2->CreateFixture(&myFixtureDef2);
    //    mBody2->SetUserData((void*)pBodyUserData);
        
        
        // Set default status
        selected = true;
        //contactedColor = ofColor(0, 200, 25);
        contactedColor = ofColor(0, 200, 0);
//        normalColor = ofColor(0, 200, 25);
        normalColor = ofColor(0, 50, 120);

        outliner_rad = 5.f;
        
        fragOutlineColor = ofColor(255);
        
        /*
        // sub body
        b2BodyDef myBodyDef2;
    //	myBodyDef2.type = b2_dynamicBody;
        myBodyDef2.type = b2_staticBody;
    //	myBodyDef2.type = b2_kinematicBody;
        myBodyDef2.position.Set(0, 0);
        mBody2 = mWorld -> CreateBody(&myBodyDef2);
        
        mBody2_rad = 5.f;
        
        // Circle
        b2CircleShape myCircleShape;
        myCircleShape.m_p.Set(0, 0);
        myCircleShape.m_radius = _toWorldScale(mBody2_rad/2.f);
        
        myFixtureDef.shape = &myCircleShape;
        myFixtureDef.density = 100.f;
        myFixtureDef.restitution = 1.01f;
        myFixtureDef.friction = 0.7f;
        mBody2->CreateFixture(&myFixtureDef);
        mBody2->SetUserData((void*)smallBodyUserData);
        */
        
    //    cout << "count: " <<mWorld->GetBodyCount() << endl;
    //    cout << "list: " << mWorld->GetBodyList() << endl;
        
        isNewBorn = true;
    }
	
}
Ejemplo n.º 22
0
//--------------------------------------------------------------
void ofApp::draw() {
    /*
    kinectDepthImage.draw(640,480);
    kinectThresholdedImage.draw(640,0);
    ofPushMatrix();
    ofTranslate(640,0);
    contourFinder.draw();
    ofPopMatrix();
    
    ofDrawBitmapString( ofToString(record) , 20, 400);
    debugWindow.begin();
    ofBackground(0, 0, 0);
    glPointSize(1);
    //glLineWidth(1);
    easyCam.begin();
    ofPushMatrix();
    ofScale(1, -1, -1);
    //ofTranslate( 0 ,0 ,0);
    
    //ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
    ofEnableDepthTest();
    mesh.draw();
    //kinect.draw(0, 0, 640, 480);
    //kinect.drawDepth(0, 0, 640, 480);
    
    
    ofDisableDepthTest();
    ofPopMatrix();
    easyCam.end();
    
    debugWindow.end();
    
    */
    
    
    
    //-----oculus stufff
     if(oculusRift.isSetup()){
     
     if(showOverlay){
     
     oculusRift.beginOverlay(-230, 320,240);
     ofRectangle overlayRect = oculusRift.getOverlayRectangle();
     
     ofPushStyle();
     ofEnableAlphaBlending();
     ofFill();
     ofSetColor(255, 40, 10, 200);
     
     ofRect(overlayRect);
     
     ofSetColor(255,255);
     ofFill();
     ofDrawBitmapString("ofxOculusRift by\nAndreas Muller\nJames George\nJason Walters\nElie Zananiri\nFPS:"+ofToString(ofGetFrameRate())+"\nPredictive Tracking " + (oculusRift.getUsePredictiveOrientation() ? "YES" : "NO"), 40, 40);
     
     ofSetColor(0, 255, 0);
     ofNoFill();
     ofCircle(overlayRect.getCenter(), 20);
     
     ofPopStyle();
     oculusRift.endOverlay();
     }
     
     ofSetColor(255);
     glEnable(GL_DEPTH_TEST);
     
     
     oculusRift.beginLeftEye();
     drawScene();
     oculusRift.endLeftEye();
     
     oculusRift.beginRightEye();
     drawScene();
     oculusRift.endRightEye();
     
     oculusRift.draw();
     
     glDisable(GL_DEPTH_TEST);
     }
        /*
     else{
     easyCam.begin();
     drawScene();
     easyCam.end();
     }

     */
     
     //---- end of oculus stuff
    
    
    
    
}
Ejemplo n.º 23
0
//--------------------------------------------------------------
void ofApp::draw(){
    
    ofBackground(0);
    
    int totalLoaded = 0;
    for(int i = 0; i < MAX_AVATARS; i++){
        if(avatars[i].player.isLoaded()) totalLoaded++;
    }
    
    ofSetColor(255, 255, 255);
    if(bUseSets){
        
        if(avatars[currentPlaying].player.getIsMovieDone())
            ofSetColor(150,150,150);
        
        // only show if all loaded
        if(totalLoaded >= MAX_AVATARS) avatars[currentPlaying].draw();
        
        //cout << "totalLoaded " << totalLoaded << endl;
    }else
        avatar.draw();
    
    //---
    // show instructions
    if(bUseSets){
        ofSetColor(255, 255, 255);
        if(totalLoaded < MAX_AVATARS){
            string readyInfo = "Please Wait";
            ofRectangle bounds = font.getStringBoundingBox(readyInfo, 0, 0);
            font.drawString(readyInfo, ofGetWidth()*.5-bounds.width*.5, ofGetHeight()*.85-bounds.height*.5);
        }else if( !avatars[currentPlaying].player.isPlaying() && !avatars[currentPlaying].player.getIsMovieDone()){
            string readyInfo = "When the video begins,";
            ofRectangle bounds = font.getStringBoundingBox(readyInfo, 0, 0);
            font.drawString(readyInfo, ofGetWidth()*.5-bounds.width*.5, ofGetHeight()*.20-bounds.height*.5);
            readyInfo = "follow the dance movements";
            ofRectangle bounds2 = font.getStringBoundingBox(readyInfo, 0, 0);
            font.drawString(readyInfo, ofGetWidth()*.5-bounds2.width*.5, ofGetHeight()*.20-bounds2.height*.5+bounds.height);
        }else if( avatars[currentPlaying].player.getIsMovieDone() ){
            string readyInfo = "Wait a moment for your avatar to generate.";
            ofRectangle bounds = font.getStringBoundingBox(readyInfo, 0, 0);
            font.drawString(readyInfo, ofGetWidth()*.5-bounds.width*.5, ofGetHeight()*.85-bounds.height*.5);
        }
    }
    
    //-----
    if(bShowGui){
        
        ofSetColor(255, 255, 255);
        stringstream reportStream;
        reportStream << "0 - Load from file\n" << "g - toggle this text on/off\n"
        << "f - toggle fullscreen\n" <<  "fps: " << ofGetFrameRate() << endl << "RETURN - load sequence" << endl << "n - next sequence " << endl << "r - play and record" << endl;
    
        ofDrawBitmapString(reportStream.str(), ofGetWidth()-200, 10);
        
        if( (bLoadingNewSet && totalPreloaded>=0) || totalLoaded < MAX_AVATARS){
            
            //cout << totalPreloaded << endl;
            stringstream reportStream2;
            if(totalPreloaded > 0) reportStream2 << "Loading file: " << avatars[totalPreloaded-1].getDirectory() << endl;
            ofDrawBitmapString(reportStream2.str(), ofGetWidth()-200, 120);
        }
        
        gui.draw();
    }
    
    if(bHasUser){
        ofNoFill();
        ofSetColor(255, 0, 0);
        ofSetLineWidth(3);
        ofRect(0, 0, ofGetWidth(), ofGetHeight());
        ofSetLineWidth(1);
    }
}
Ejemplo n.º 24
0
//--------------------------------------------------------------
void testApp::draw(){

	// draw the incoming, the grayscale, the bg and the thresholded difference
	ofSetHexColor(0xffffff);
	//colorImg.draw(20,20);
	grayImage.draw(360,20);
	grayBg.draw(20,280);
	grayImage2.draw(360,280);
	grayDiff.draw(20,20);

	// then draw the contours:

	ofFill();
	ofSetHexColor(0x333333);
	ofRect(360,540,320,240);
	ofSetHexColor(0xffffff);

	// we could draw the whole contour finder
	//contourFinder.draw(360,540);

	// or, instead we can draw each blob individually,
	// this is how to get access to them:
	///*
    for (int i = 0; i < contourFinder.nBlobs; i++){
        contourFinder.blobs[i].draw(360,540);
    }
	// */

	// finally, a report:

	ofSetHexColor(0xffffff);
	char reportStr[1024];
	sprintf(reportStr, "bg subtraction and blob detection\npress ' ' to capture bg\nthreshold %i (press: +/-)\nnum blobs found %i, fps: %f", threshold, contourFinder.nBlobs, ofGetFrameRate());
	ofDrawBitmapString(reportStr, 20, 600);

}
Ejemplo n.º 25
0
//--------------------------------------------------------------
void testApp::draw()
{
    //draw OscWave GLSL
    float resolution[] = {320, 240};
    float mousePoint[] = {mouseX, mouseY};
    ofDisableBlendMode();
    oscFbo.begin();
    oscShader.begin();
    oscShader.setUniform1f("time", ofGetElapsedTimef() - oscStartTime);
    oscShader.setUniform1f("num", oscNum);
    int n = int(oscNum);
    float ffreq[100];
    for (int i = 0; i< oscFreq.size(); i++) {
        ffreq[i] = oscFreq[i];
    }
    oscShader.setUniform1fv("oscFreq", ffreq, 64);
    oscShader.setUniform2fv("resolution", resolution);
    oscShader.setUniform2fv("mouse", mousePoint);
    ofRect(0, 0, ofGetWidth(), ofGetHeight());
    oscShader.end();
    oscFbo.end();
    oscFbo.draw(0, 0, ofGetWidth(), ofGetHeight());
    ofEnableBlendMode(OF_BLENDMODE_ADD);   
    
    for (int i=0; i<rects.size(); i++) {
        rects[i]->draw();
    }
    
    if (glitchMode) {
        glitch->draw();
    }
    
    if (flickerMode) {
        flicker->draw();
    }
    
    for (int i = 0; i < saws.size(); i++) {
        saws[i]->draw();
    }
    
    ofSetLineWidth(1);
    
    // draw OscWave guide & log
    if (mode == 1) {
        ofVec2f currentPos;
        ofSetHexColor(0x666666);
        ofNoFill();
        if (bMousePressed) {
            float dist = drawPos.distance(ofVec2f(mouseX, mouseY));
            if (dist > 100.0) {
                dist = 100.0;
            }
            
            ofCircle(drawPos.x, drawPos.y, dist);
            ofLine(drawPos.x, drawPos.y, mouseX, mouseY);
            currentPos = drawPos;
        } else {
            currentPos = ofVec2f(mouseX, mouseY);
        }
        
        int note  = int(ofMap(currentPos.y, 0, ofGetHeight(), 85, 1));
        float freq = 20 + 20 * pow((13.0/12.0), note);
        float pan = ofMap(currentPos.x, 0, ofGetWidth(), -1.0, 1.0);
        ofLine(0, currentPos.y, ofGetWidth(), currentPos.y);
        ofLine(currentPos.x, 0, currentPos.x, ofGetWidth());
        
        ofSetHexColor(0xffffff);
        ofDrawBitmapString(ofToString(freq,2), 5, currentPos.y - 10);
        ofDrawBitmapString(ofToString(pan,2), currentPos.x + 5, 10);
        ofDrawBitmapString("nOsc: " + ofToString(oscils.size()), 10, 22);
        ofFill();
    }
    
    // draw MyRect or GlitchRect guide & log
    if (mode == 2 && bMousePressed) {
        ofNoFill();
        ofSetColor(255, 255, 255, 63);
        ofRect(drawPos.x, drawPos.y, mouseX - drawPos.x, mouseY-drawPos.y);
        ofFill();
    }
    
    // draw Glitch guide & log
    if (mode == 3) {
        ofSetHexColor(0xffffff);
        ofDrawBitmapString("amp: " + ofToString(glitch->amp, 4), 10, 22);
    }
    
    // draw Flickr guide & log
    if (mode == 4) {
        ofSetHexColor(0xffffff);
        ofDrawBitmapString("amp: " + ofToString(flicker->level, 4), 10, 22);
    }
    
    // Saw Lines
    if (mode == 5) {
        ofSetHexColor(0xffffff);
        ofDrawBitmapString("Num = " + ofToString(synthNum) , 10, 22);
    }
    
    // log
    ofSetHexColor(0xffffff);
    ofDrawBitmapString("mode: " + ofToString(mode) + ", frameRate: " + ofToString(ofGetFrameRate()), 10, 10);
}
Ejemplo n.º 26
0
//--------------------------------------------------------------
void ofApp::draw(){
	ofSetColor(255, 255, 255);
    
    ofPushMatrix();
    
    for (int deviceID = 0; deviceID < numDevices; deviceID++){
        ofTranslate(0, deviceID * 480);
        openNIDevices[deviceID].drawDebug(); // debug draw does the equicalent of the commented methods below
//        openNIDevices[deviceID].drawDepth(0, 0, 640, 480);
//        openNIDevices[deviceID].drawImage(640, 0, 640, 480);
//        openNIDevices[deviceID].drawSkeletons(640, 0, 640, 480);
        
    }

    // do some drawing of user clouds and masks
    ofPushMatrix();
    ofEnableBlendMode(OF_BLENDMODE_ALPHA);
    int numUsers = openNIDevices[0].getNumTrackedUsers();
    for (int nID = 0; nID < numUsers; nID++){
        ofxOpenNIUser & user = openNIDevices[0].getTrackedUser(nID);
        user.drawMask();
        ofPushMatrix();
        ofTranslate(320, 240, -1000);
        user.drawPointCloud();
        ofPopMatrix();
    }
    ofDisableBlendMode();
    ofPopMatrix();
    
	ofSetColor(0, 255, 0);
	string msg = " MILLIS: " + ofToString(ofGetElapsedTimeMillis()) + " FPS: " + ofToString(ofGetFrameRate());
	verdana.drawString(msg, 20, numDevices * 480 + 26);
}
Ejemplo n.º 27
0
//--------------------------------------------------------------
void testApp::update(){
    
    
    switch (aplicacionEnCurso) {
        case APP_STATE_HUNTER:
            updateStateHunter();
            break;
            
        case APP_STATE_PHOVIEWER:
            photoViewer.update();
            break;
        default:
            break;
    }
    


    ofSetWindowTitle(ofToString(ofGetFrameRate()));
    
    
    
    
    
    
    
    
    
    
    
    
    /// --  comprobamos que aplicacion queremos segun la hora
    ////

    

    if(ofGetHours() > (int)horaInicio && ofGetHours() < (int)horaFin && aplicacionEnCurso == APP_STATE_HUNTER)
    {
        //// es la hora del pasafotos
        
        //-- comprueba si hay algo en play;
        if(pidginLoop.isPlaying()) pidginLoop.stop();
        if(pidginFly.isPlaying()) pidginFly.stop();
        
        if(!photoViewer.isPlaying()) photoViewer.play();
        
        aplicacionEnCurso = APP_STATE_PHOVIEWER;
        
        cout << "APP_STATE_PHOVIEWER" << endl;
        
        
    }else if((ofGetHours() < (int)horaInicio || ofGetHours() > (int)horaFin) && aplicacionEnCurso == APP_STATE_PHOVIEWER){
        
        //// es la hora del dovehunter
        aplicacionEnCurso = APP_STATE_HUNTER;
        if(photoViewer.isPlaying()) photoViewer.stop();
        if(!pidginLoop.isPlaying()) pidginLoop.play();
        
        cout << "APP_STATE_HUNTER" << endl;
    }
    
}
Ejemplo n.º 28
0
	void CamaraLucida::render_screenlog()
	{
		if (!_debug) return;
		ofDrawBitmapString(_viewpoint_str()+" /fps: "+ofToString(ofGetFrameRate()), 10, ofGetHeight()-10);
	}
Ejemplo n.º 29
0
//--------------------------------------------------------------
void testApp::draw() {

	char str[256];
	ofSetColor(255);
	unsigned int width, height;
	char tempname[256]; // temp name
	
	// A render window must be available for Spout initialization
	// and might not be available in "update", so do it now 
	// when there is definitely a render window.
	//
	// INITIALIZE A RECEIVER
	//
	// The receiver will attempt to connect to the name it is sent.
	// Alternatively set the optional bUseActive flag to attempt to connect to the active sender. 
	// If the sender name is not initialized it will attempt to find the active sender
	// If the receiver does not find any senders the initialization will fail
	// and "CreateReceiver" can be called repeatedly until a sender is found.
	// "CreateReceiver" will update the passed name, and dimensions.
	if(!bInitialized) {
		// Specify true to attempt to connect to the active sender
		if(spoutreceiver->CreateReceiver(SenderName, width, height, true)) {
			// Is the size of the detected sender different ?
			if(width != g_Width || height != g_Height ) {
				// The sender dimensions have changed so update the global width and height
				g_Width  = width;
				g_Height = height;
				// Update the local texture to receive the new dimensions
				myTexture.allocate(g_Width, g_Height, GL_RGBA);
				// reset render window
				ofSetWindowShape(g_Width, g_Height);
			}
			bInitialized = true;
			return; // quit for next round
		} // receiver was initialized
		else {
			sprintf_s(str, "No sender detected");
			ofDrawBitmapString(str, 20, 20);
		}
	} // already initialized

	// The receiver has initialized so OK to draw
	if(bInitialized) {
		
		// Save current global width and height - they will be changed
		// by receivetexture if the sender changes dimensions
		width  = g_Width;
		height = g_Height;
		
		// Try to receive into the local the texture at the current size 
		// NOTE: If a host calls ReceiveTexture with a framebuffer object bound,
		// include the FBO id in the ReceiveTexture call so that the binding is restored
		// afterwards because Spout makes use of its own FBO for intermediate rendering.		
		if(spoutreceiver->ReceiveTexture(SenderName, width, height, myTexture.getTextureData().textureID, myTexture.getTextureData().textureTarget)) {

			//	width and height are changed. The local texture then has to be resized.
			if(width != g_Width || height != g_Height ) {
				// Update the global width and height
				g_Width  = width;
				g_Height = height;
				// Update the local texture to receive the new dimensions
				myTexture.allocate(g_Width, g_Height, GL_RGBA);
				// reset render window
				ofSetWindowShape(g_Width, g_Height);
				return; // quit for next round
			}
			double widthd = (double)width;
			widthd = widthd * 1.33334;
			width = (unsigned int)widthd;
			double heightd = (double)height;
			heightd = heightd * 1.0;
			height = (unsigned int)heightd;

			puffersphere->begin();
			myTexture.draw(0, -150, width, height);
			puffersphere->end();

			// Show what it is receiving
			if(!bMemoryShare) {
				sprintf_s(str, "Receiving from : [%s]", SenderName);
				ofDrawBitmapString(str, 20, 20);
				sprintf_s(str, "RH click select sender", SenderName);
				ofDrawBitmapString(str, 15, ofGetHeight()-20);
			}
			else {
				sprintf_s(str, "Memoryshare receiver");
				ofDrawBitmapString(str, 20, 20);
			}
		}
		else {
			// A texture read failure might happen if the sender
			// is closed. Release the receiver and start again.
			spoutreceiver->ReleaseReceiver();
			bInitialized = false;
			return;
		}
	}
	
	// Show fps
	sprintf_s(str, "fps: %3.3d", (int)ofGetFrameRate());
	ofSetColor(255); 
	ofDrawBitmapString(str, ofGetWidth()-120, 20);


	ofBackground(0);

//	puffersphere->draw(rot); <- TODO: use the rotation in this function

//	ofPushMatrix();

//	ofRotate(rot, 1.0, 1.0, 1.0);

	puffersphere->draw(rot);
//	ofPopMatrix();

	if (!hideGui){

		gui.draw();
		ofEnableAlphaBlending();

		ofDrawBitmapString("PRESS 'space' to hide GUI | 'd' to toggle fullscreen", 10, ofGetHeight() - 40);
		ofPopStyle();

	}



}
Ejemplo n.º 30
0
//--------------------------------------------------------------
void testApp::draw() {
	ofBackground(0);

	ofSetColor(255);
//	glPushMatrix();
//	glScalef(scaleWidth, scaleHeight, 0);
	cvImgGrayscale.draw(0, 0);

	for (unsigned int i = 0; i < polylines.size(); i++) {
		ofNoFill();

		ofSetColor(255, 0, 0);
		drawWithNormals(polylines[i], 0, 0, true);

		ofSetColor(0, 255, 0);
		drawWithNormals(smoothed[i], 0, 0, false);

		ofSetColor(0, 0, 255);
		drawWithNormals(resampled[i], 0, 0, true);

//		ofSetColor(0, 255, 255);
//		ofRect(boundingBoxes[i]);

//		ofSetColor(255, 0, 0);
//		ofLine(closestPoints[i], ofPoint(mouseX, mouseY));
		ofSetColor(0, 0, 255);
		ofLine(resampled[i][closestIndices[i]], ofPoint(mouseX, mouseY));
	}
//	glPopMatrix();

	ofSetColor(255, 0, 0);
	ofDrawBitmapString(ofToString((int) ofGetFrameRate()) + " fps", 10, 20);
	ofDrawBitmapString("Click and drag to set a new threshold.", 10, 40);
//	ofDrawBitmapString("Hold down any key to invert the thresholding.", 10, 60);

//---------------------------------------

//	ofDrawBitmapString("hit spacebar to load image from web", 10, ofGetHeight()/2);
//	if(loading)
//		ofDrawBitmapString("loading...", 10, ofGetHeight()+20);
//	float divider = ofMap( mouseX, 0, ofGetWidth(), 1, 48, true );
//
//	if(img.bAllocated()){
//		for(int y = 0; y < img.getHeight(); y+= divider){
//			for(int x = 0; x < img.getWidth(); x+=divider){
//				ofColor c = img.getColor(x, y);
//
//				ofSetColor( c.r, c.g, c.b );
//				ofCircle( x, y, divider/2 );
//			}
//		}
//
//		ofSetColor(255);
//		img.draw(img.getWidth(), 0);
//	}

//	maskLayers.draw(0, 0, maskLayers.getWidth(), maskLayers.getHeight());

	if (doVideoWrite) {
//		saveScreen.grabScreen(0, 0, ofGetWidth(), ofGetHeight());
//		TIS.saveThreaded(saveScreen);
//		doVideoWrite != doVideoWrite;
	}

}