예제 #1
0
//--------------------------------------------------------------
void testApp::keyPressed(int key){
    if(key == 'c') {
		float r = ofRandom(4, 20);		// a random radius 4px - 20px
		circles.push_back(ofPtr<ofxBox2dCircle>(new ofxBox2dCircle));
		circles.back().get()->setPhysics(3.0, 0.53, 0.1);
		circles.back().get()->setup(box2d.getWorld(), mouseX, mouseY, r);
		
	}
	
	if(key == 'b') {
		float w = ofRandom(4, 20);
		float h = ofRandom(4, 20);
		boxes.push_back(ofPtr<ofxBox2dRect>(new ofxBox2dRect));
		boxes.back().get()->setPhysics(3.0, 0.53, 0.1);
		boxes.back().get()->setup(box2d.getWorld(), mouseX, mouseY, w, h);
	}
	
	if(key == 'z') {
        
		customParticles.push_back(ofPtr<CustomParticle>(new CustomParticle));
        CustomParticle * p = customParticles.back().get();
		float r = ofRandom(3, 10);		// a random radius 4px - 20px
		p->setPhysics(0.4, 0.53, 0.31);
		p->setup(box2d.getWorld(), mouseX, mouseY, r);
		p->color.r = ofRandom(20, 100);
		p->color.g = 0;
		p->color.b = ofRandom(150, 255);
	}
    
	if(key == 'f') bMouseForce = !bMouseForce;
	if(key == 't') ofToggleFullscreen();
}
예제 #2
0
파일: testApp.cpp 프로젝트: silky/Feedback
//--------------------------------------------------------------
void testApp::keyPressed(int key) {

    if(key == 'c') {
        float r = ofRandom(4, 20);		// a random radius 4px - 20px
        ofxBox2dCircle circle;
        circle.setPhysics(3.0, 0.53, 0.1);
        circle.setup(box2d.getWorld(), mouseX, mouseY, r);
        circles.push_back(circle);
    }
    if(key == 'z') {
        float r = ofRandom(3, 10);		// a random radius 4px - 20px
        CustomParticle p;
        p.setPhysics(0.4, 0.53, 0.31);
        p.setup(box2d.getWorld(), mouseX, mouseY, r);
        p.color.r = ofRandom(20, 100);
        p.color.g = 0;
        p.color.b = ofRandom(150, 255);
        customParticles.push_back(p);
    }
    if(key == 'b') {
        float w = ofRandom(4, 20);
        float h = ofRandom(4, 20);
        ofxBox2dRect rect;
        rect.setPhysics(3.0, 0.53, 0.1);
        rect.setup(box2d.getWorld(), mouseX, mouseY, w, h);
        boxes.push_back(rect);
    }

    if(key == 's') bDrawLines = !bDrawLines;
    if(key == 'f') bMouseForce = !bMouseForce;
}
예제 #3
0
//--------------------------------------------------------------
void testApp::keyPressed(int key) {

    if(key == 'c') {
        float r = ofRandom(4, 20);		// a random radius 4px - 20px
        ofxBox2dCircle circle;
        circle.setPhysics(3.0, 0.53, 0.1);
        circle.setup(box2d.getWorld(), mouseX, mouseY, r);
        circles.push_back(circle);
    }
    if(key == 'z') {
        float r = ofRandom(3, 10);		// a random radius 4px - 20px
        CustomParticle p;
        p.setPhysics(0.4, 0.53, 0.31);
        p.setup(box2d.getWorld(), mouseX, mouseY, r);
        p.color.r = ofRandom(20, 100);
        p.color.g = 0;
        p.color.b = ofRandom(150, 255);
        customParticles.push_back(p);
    }

    // add some lines
    if(key == '0') {
        ofPoint p1(ofRandomWidth(), 20);
        ofPoint p2(p1.x+ofRandom(5, 120), ofRandom(20, 130));

        ofxBox2dLine line;
        line.setPhysics(1.0, 0.4, 0.3);;
        line.setup(box2d.getWorld(), p1, p2);
        lines.push_back(line);
    }

    if(key == '1') {
        ofxBox2dCircle circle;
        circle.setPhysics(1.0, 0.4, 0.3);;
        circle.setup(box2d.getWorld(), ofGetMouseX(), ofGetMouseY(), ofRandom(3, 10));
        circles.push_back(circle);
    }


    if(key == '2') {
        float w = ofRandom(4, 20);
        float h = ofRandom(4, 20);
        ofxBox2dRect rect;
        rect.setPhysics(3.0, 0.53, 0.1);
        rect.setup(box2d.getWorld(), mouseX, mouseY, w, h);
        boxes.push_back(rect);
    }


    if(key == 's') bDrawLines = !bDrawLines;
    if(key == 'f') bMouseForce = !bMouseForce;
    if(key == 't') ofToggleFullscreen();
}
예제 #4
0
//--------------------------------------------------------------
void box2dScene::addObject(){
    
    for(int i = 0; i < 600; i ++){
        customParticles.push_back(shared_ptr<CustomParticle>(new CustomParticle));
        CustomParticle * p = customParticles.back().get();
        //        float r = ofRandom(size-1, size);
        p->setPhysics(density,bounce,friction);
        p->setup(box2d.getWorld(),ofRandom(w),ofRandom(RM->getRectForScreen(SCREEN_LEFT).y, RM->getRectForScreen(SCREEN_LEFT).y + 300),scale);
        
        p->color = 180;
        
    }
    
}
//--------------------------------------------------------------
void testApp::keyPressed(int key) {
	
	
	if(key == 'z') {
		float r = ofRandom(3, 10);		// a random radius 4px - 20px
		CustomParticle p;
		p.setPhysics(0.4, 0.1, 0.9);
		p.setup(box2d.getWorld(), mouseX, mouseY, r);
		p.color.r = ofRandom(20, 100);
		p.color.g = 0;//ofRandom(0, 255);
		p.color.b = ofRandom(150, 255);
		customParticles.push_back(p);
	}	
	
	
	if(key == 's') bDrawLines = !bDrawLines;
	if(key == 'f') bMouseForce = !bMouseForce;
}
예제 #6
0
//--------------------------------------------------------------
void TuioKinect::draw()
{
	float height = (float)ofGetHeight();
	float width = (float)ofGetWidth() ; 
	
	ofSetColor(0,0,0,200) ; 
	
	//Additive blend mode
	glBlendFunc(GL_SRC_COLOR, GL_ONE);
	
	ofSetColor(255, 255, 255) ; 
	ofEnableSmoothing();
	
	for(int i=0; i< customParticles.size(); i++) 
	{
		customParticles[i].draw(0);
	}
	
	box2d.draw();
	box2d.drawGround() ;

	ofSetColor(255, 255, 255);
	std::list<TuioCursor*> alive_cursor_list = tuioServer->getTuioCursors();
	std::list<TuioCursor*>::iterator alive_cursor;
	
	for (alive_cursor=alive_cursor_list.begin(); alive_cursor!= alive_cursor_list.end(); alive_cursor++) 
	{
		TuioCursor *ac = (*alive_cursor);
		
		float absXSpeed = ac->getXSpeed() ;
		float absYSpeed = ac->getYSpeed() ;
		float xpos = ac->getX() * (float)ofGetWidth() ; 
		float ypos = ac->getY() * (float)ofGetHeight() ; 
		
		absXSpeed = ( absXSpeed < 0 ) ? absXSpeed * -1 : absXSpeed ; 
		absYSpeed = ( absYSpeed < 0 ) ? absYSpeed * -1 : absYSpeed ; 
			
		if ( absXSpeed > .30 || absYSpeed > .30 ) 
		{	
			int _size  = customParticles.size() ;
			if ( _size < 20 ) 
			{
				CustomParticle p;
				
				if ( _size % 2 == 0 ) 
				{
					p.changeIsFire(true);
				}
				else {
					p.changeIsFire(false) ; 
				}

				float r = ofRandom(.25f, 1.0f); //normalized diff
				p.setPhysics(4.0 * r, .2 * r, .45 * r );
				p.setup(box2d.getWorld(), xpos, ypos, (r*30) );
				p.setVelocity( ac->getXSpeed()*10 , ac->getYSpeed()*10 ) ; 
				customParticles.push_back(p);
			}
		}
		
		//Draw that path!
		drawTuioPath( ac->getPath() ) ; 
	}
	
	//Debug Text
	ofSetColor(255, 255, 255);
	char reportStr[1024];
	sprintf(reportStr, "set near threshold %i (press: + -)\nset far threshold %i (press: < >)\nnum blobs found %i, fps: %i", nearThreshold, farThreshold, (int)contourFinder.blobs.size(), (int)ofGetFrameRate());
	ofDrawBitmapString(reportStr, 20, 650);
	ofEnableAlphaBlending() ; 

	ofSetColor ( 10 , 10 , 10 ); 
	ofFill() ; 
	ofSetLineWidth( 2 ) ;
	ofRect(0, 0, 40, 40 ) ; 
		
	ofSetColor(255, 255, 255 ) ; 
	ofFill() ;

	grayImage.draw(5, 5, 192, 144 );
	contourFinder.draw(5, 5, 192, 144 );
	ofFill() ;
	ofDisableAlphaBlending() ; 
}
예제 #7
0
void testApp::setLevel(int lvl){
  ofLog()<<"NEW LEVEL" +ofToString(level)+" "+ofToString(lvl);
  switch(lvl){
    case 0:{
      customParticles.push_back(ofPtr<CustomParticle>(new CustomParticle(1, 0, 100)));
      CustomParticle * p = customParticles.back().get();
      
      float r = ofRandom(3, 10);		// a random radius 4px - 20px
      p->setPhysics(0.4, 0.53, 0.31);
      p->setup(box2d.getWorld(), (int)ofRandom(100,600), 400, p->width, p->height);
      
      
      SoundData * s = new SoundData();
      p->setData(s);
      SoundData * sd = (SoundData*)p->getData();
      sd->type = GUY;
      sd->bHit	= false;
      
      
    }
      break;
    case 1:{
      bullets.clear();
      apples.clear();
      customParticles.push_back(ofPtr<CustomParticle>(new CustomParticle(1, 1, 150)));
      CustomParticle * p = customParticles.back().get();
      
      float r = ofRandom(3, 10);		// a random radius 4px - 20px
      p->setPhysics(0.4, 0.53, 0.31);
      p->setup(box2d.getWorld(), (int)ofRandom(100,600), 300, p->width, p->height);
      
      
      SoundData * s = new SoundData();
      p->setData(s);
      SoundData * sd = (SoundData*)p->getData();
      sd->type = GUY;
      sd->bHit	= false;
    }
      
      break;
    case 2:{
      bullets.clear();
      apples.clear();
      customParticles.push_back(ofPtr<CustomParticle>(new CustomParticle(1, 2, 200)));
      CustomParticle * p = customParticles.back().get();
      
      float r = ofRandom(3, 10);		// a random radius 4px - 20px
      p->setPhysics(0.4, 0.53, 0.31);
      p->setup(box2d.getWorld(),(int)ofRandom(100,600), 400, p->width, p->height);
      
      
      SoundData * s = new SoundData();
     
      p->setData(s);
      SoundData * sd = (SoundData*)p->getData();
      sd->type = GUY;
      sd->bHit	= false;
    }
      
      break;
    case 3:{
      bullets.clear();
      apples.clear();
      customParticles.push_back(ofPtr<CustomParticle>(new CustomParticle(1, 3, 300)));
      CustomParticle * p = customParticles.back().get();
      
      float r = ofRandom(3, 10);		// a random radius 4px - 20px
      p->setPhysics(0.4, 0.53, 0.31);
      p->setup(box2d.getWorld(), mouseX, mouseY, p->width, p->height);
      
      
      SoundData * s = new SoundData();
     
      p->setData(s);
      
      SoundData * sd = (SoundData*)p->getData();
      sd->type = GUY;
      sd->bHit	= false;
    }
      break;
    case 4:{
      bullets.clear();
      apples.clear();
      edgeLine.addVertex(ofGetWidth(), 0);
      edgeLine.addVertex(ofGetWidth(), ofGetHeight()-30);
      
      
      
      edgeLine.setPhysics(0.0, 0.5, 0.5);
      edgeLine.create(box2d.getWorld());
      
      customParticles.push_back(ofPtr<CustomParticle>(new CustomParticle(1, 4, 350)));
      CustomParticle * p = customParticles.back().get();
      movePt.x=(int)ofRandom(100,600);
      movePt.y=(int)ofRandom(10,400);
      
      float r = ofRandom(3, 10);		// a random radius 4px - 20px
      p->setPhysics(0.1, 0.53, 0.31);
      p->setup(box2d.getWorld(), movePt.x, movePt.y, p->width, p->height);
      
      
      SoundData * s = new SoundData();
            p->setData(s);
   
      SoundData * sd = (SoundData*)p->getData();
      sd->type = BIGGUY;
      sd->bHit	= false;
    }
      break;

      
  }

  
}
예제 #8
0
void testApp::addParticles(int scope, int type, int num, float density, float bounce, float friction) {    

    ofVec2f attract;
    switch(scope) {
        case PERSONAL: 
            attract.set(personalCenter.x, personalCenter.y);
            break;
        case NEIGHBORHOOD: 
            attract.set(neighborhoodCenter.x, neighborhoodCenter.y);
            break;
        case CITY: 
            attract.set(cityCenter.x, cityCenter.y);
            break;
    }
    
    int deltaX = 120;
    int typeY = 0;
    switch(type) {
        case NEGATIVE:
            typeY = attract.y + 100;
            break;
        case NEUTRAL:
            typeY = attract.y - 100;
            break;
        case POSITIVE:
            typeY = attract.y - 100;
            break;
    }

    for(int i = 0; i < num ; i++) {
        
    // MARK: create particle
        CustomParticle p;        
        
        //density, restitution/bounce, friction
        p.setPhysics(density, bounce, friction);

        float x = ofRandom(attract.x - deltaX, attract.x + deltaX);
        float y = typeY;
        
        switch(scope) {
            case PERSONAL:
                p.setup(box2d.getWorld(), x, y, personalMinParticleSize);
                break;
            case NEIGHBORHOOD:
                p.setup(box2d.getWorld(), x, y, neighborhoodMinParticleSize);
                break;
            case CITY:
                p.setup(box2d.getWorld(), x, y, cityMinParticleSize);
                break;                
        }
        p.setupTheCustomData(scope, type, attract.x, attract.y);
        
        
    // MARK: create joints        
		ofxBox2dJoint jointLeft;
        ofxBox2dJoint jointRight;
		
        float jointLength    = 100.0f; //50;
        float jointDamping   = 0.2f; //0.2;
        float jointFrequency = 1.0f; //1.0
        
        switch(scope) {
            case PERSONAL: 
                jointLeft.setup(box2d.getWorld(), personalAnchorLeft.body, p.body);		
                jointRight.setup(box2d.getWorld(), personalAnchorRight.body, p.body);
                if( type == NEGATIVE ) {
                    ofxBox2dJoint jointBottom;
                    jointBottom.setup(box2d.getWorld(), personalAnchorBottom.body, p.body);
                    jointBottom.setDamping(jointDamping);
                    jointBottom.setFrequency(jointFrequency);
                    jointBottom.setLength(jointLength);
                    b2dJoints.push_back(jointBottom);
                } else if( type == POSITIVE ) {
                    ofxBox2dJoint jointTop;
                    jointTop.setup(box2d.getWorld(), personalAnchorTop.body, p.body);
                    jointTop.setDamping(jointDamping);
                    jointTop.setFrequency(jointFrequency);
                    jointTop.setLength(jointLength);
                    b2dJoints.push_back(jointTop);
                }
                break;
            case NEIGHBORHOOD: 
                jointLeft.setup(box2d.getWorld(), neighborhoodAnchorLeft.body, p.body);		
                jointRight.setup(box2d.getWorld(), neighborhoodAnchorRight.body, p.body);		
                if( type == NEGATIVE ) {
                    ofxBox2dJoint jointBottom;
                    jointBottom.setup(box2d.getWorld(), neighborhoodAnchorBottom.body, p.body);
                    jointBottom.setDamping(jointDamping);
                    jointBottom.setFrequency(jointFrequency);
                    jointBottom.setLength(jointLength);
                    b2dJoints.push_back(jointBottom);
                } else if( type == POSITIVE ) {
                    ofxBox2dJoint jointTop;
                    jointTop.setup(box2d.getWorld(), neighborhoodAnchorTop.body, p.body);
                    jointTop.setDamping(jointDamping);
                    jointTop.setFrequency(jointFrequency);
                    jointTop.setLength(jointLength);
                    b2dJoints.push_back(jointTop);
                }
                break;
            case CITY: 
                jointLeft.setup(box2d.getWorld(), cityAnchorLeft.body, p.body);		
                jointRight.setup(box2d.getWorld(), cityAnchorRight.body, p.body);		
                if( type == NEGATIVE ) {
                    ofxBox2dJoint jointBottom;
                    jointBottom.setup(box2d.getWorld(), cityAnchorBottom.body, p.body);
                    jointBottom.setDamping(jointDamping);
                    jointBottom.setFrequency(jointFrequency);
                    jointBottom.setLength(jointLength);
                    b2dJoints.push_back(jointBottom);
                } else if( type == POSITIVE ) {
                    ofxBox2dJoint jointTop;
                    jointTop.setup(box2d.getWorld(), cityAnchorTop.body, p.body);
                    jointTop.setDamping(jointDamping);
                    jointTop.setFrequency(jointFrequency);
                    jointTop.setLength(jointLength);
                    b2dJoints.push_back(jointTop);
                }
                break;
        }
		
        jointLeft.setDamping(jointDamping);
        jointLeft.setFrequency(jointFrequency);
		jointLeft.setLength(jointLength);

        jointRight.setDamping(jointDamping);
        jointRight.setFrequency(jointFrequency);
		jointRight.setLength(jointLength);
        
        
    // MARK: add joints and particle to relative vectors
		b2dJoints.push_back(jointLeft);
		b2dJoints.push_back(jointRight);
        b2dParticles.push_back(p);
    }
    
}