void ant(unsigned char * pixels,int posX, int posY,float dir, int width, int height, int depth, senseMaker * senses[]) { if(depth> 0 && posX < width -10 && posY<height -10 && posX > 10 && posY > 10) { for(int i =0; i < ofRandom(200,600); i ++) { int value1 = pixels[(posY*width + posX)*3]+ pixels[(posY*width + posX)*3+1] + pixels[(posY*width + posX)*3+2] ; int pixelPos = (posY*width+posX)*3; pixels[pixelPos ] = 255; pixels[pixelPos+1] = 255; pixels[pixelPos+2] = 255; int smallestDiff = 100000; int tHor = round(cos(dir) * 1.0f); int tVer = round(sin(dir) * 1.0f); float tDir = dir; int tmpValue= 0; for(float b = -PI/2.0f; b < PI/2.0f;b = b + PI/4.0f) { int ver = round(cos(b+dir) * 1.0f); int hor = round(sin(b+dir) * 1.0f); tmpValue = pixels[((posY+ver)*width + posX+hor)*3 ]+ pixels[((posY+ver)*width + posX+hor)*3+1]+ pixels[((posY+ver)*width + posX+hor)*3+2]; if(abs(value1 - tmpValue) < smallestDiff && tmpValue < 255*3 ) { smallestDiff = abs(value1 - tmpValue); tHor = hor; tVer = ver; tDir = b; } } if(depth> 0 && posX < width -10 && posY<height -10 && posX > 10 && posY > 10) { dir = dir*0.4 + tDir*0.6; posY = posY + tVer; posX = posX + tHor; if(ofRandom(0,100)<1) { ant(pixels,posX, posY,dir+ofRandom(0,PI*2),width, height, depth-1,senses); } } else { break; } } } }
//-------------------------------------------------------------- void ofApp::update(){ // timer update timer.update(); // dmx if (enableDmx) { for (int i = 0; i < DMX_CHANNEL_NUMBER; i++) { dmxChannels[i].set(tween.update()); dmx.setLevel(i+1, dmxChannels[i]);// be careful, dmx channel starts from 1, not 0. } dmx.update(); if ((int)ofGetElapsedTimef() % DMX_TIMER_PER_SECONDS == 0){ // FIXME: hard code and use same tween to each dmx channel for (int i = 0; i < DMX_CHANNEL_NUMBER; i++) { doEase(dmxChannels[i], 10000, 0); } } } // kinect kinect.update(); if( kinect.isFrameNew() ){ if (showPanel) { texDepth.loadData(kinect.getDepthPixels()); texRGB.loadData(kinect.getRgbPixels()); } rawDepthPixels = kinect.getRawDepthPixels(); // bullet if (kinectBulletShape == NULL ) { updateKinectMesh(); setupWhenKinectIsReady(); }else if(enableScanPeople) { // scanning people feature if (!diffDepthTexture.isAllocated()) { diffDepthTexture.allocate(rawDepthPixels.getWidth(), rawDepthPixels.getHeight(), GL_RGB);// color texture diffDepthTexturePixels = new unsigned char[rawDepthPixels.getWidth()*rawDepthPixels.getHeight()*3]; } diffDepthPixels = rawDepthPixels; // copy float * diffDepthPixelsPointer = diffDepthPixels.getPixels(); modelStartPositions.clear(); for (int x = 0; x < rawDepthPixels.getWidth(); x++) { for (int y = 0; y < rawDepthPixels.getHeight(); y++) { diffDepthPixelsPointer[rawDepthPixels.getWidth()*y+x] = savedReferenceDepthPixels[rawDepthPixels.getWidth()*y+x]-rawDepthPixels[rawDepthPixels.getWidth()*y+x]; if (/* savedReferenceDepthPixels[rawDepthPixels.getWidth()*y+x] > kinect.minDistance && savedReferenceDepthPixels[rawDepthPixels.getWidth()*y+x] < kinect.maxDistance && */ rawDepthPixels[rawDepthPixels.getWidth()*y+x] > kinect.minDistance && rawDepthPixels[rawDepthPixels.getWidth()*y+x] < kinect.maxDistance) { if (diffDepthPixelsPointer[rawDepthPixels.getWidth()*y+x] > 0) { // calculate probability float probability = diffDepthPixelsPointer[rawDepthPixels.getWidth()*y+x] / probabilityFactor; // judge add or not bool judgeAdd = (ofRandomuf() < probability); if (judgeAdd) { modelStartPositions.push_back(ofVec3f(x, y, modelStartPosition->z)); } // set diffDepthTexturePixels with red color if (showPanel) { diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+0] = ofMap(diffDepthPixelsPointer[rawDepthPixels.getWidth()*y+x], 0, kinect.maxDistance-kinect.minDistance, 0, 255, true) ; // r diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+1] = 0; // g diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+2] = 0; // b } }else{ // set diffDepthTexturePixels with blue color if (showPanel) { diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+0] = 0; // r diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+1] = 0; // g diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+2] = ofMap(-1*diffDepthPixelsPointer[rawDepthPixels.getWidth()*y+x], 0, kinect.maxDistance-kinect.minDistance, 0, 255, true); // b } } }else{ // black if (showPanel) { diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+0] = 0; // r diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+1] = 0; // g diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+2] = 0; // b } } } } // grayscale diff texture // diffDepthTexture.loadData(diffDepthPixels); // draw RGB diff texture if (showPanel) { diffDepthTexture.loadData(diffDepthTexturePixels, rawDepthPixels.getWidth(), rawDepthPixels.getHeight(), GL_RGB); } }else{ updateKinectMesh(); } } // bullet if (!stopUpdatingKinectBullet && !enableScanPeople) { if (kinectHeight != 0 && kinectBulletShape != NULL) { kinectBulletShape->remove(); kinectBulletShape->create( world.world, kinectMesh, ofVec3f(0,0,0), 0.f, ofVec3f(0, 0, 0), ofVec3f(kinectWidth, kinectHeight, kinect.maxDistance.getMax()) ); kinectBulletShape->add(); kinectBulletShape->enableKinematic(); kinectBulletShape->setActivationState( DISABLE_DEACTIVATION ); } } // model if (enableAddModel) { // add model in modelStartPosition ofxBulletAssimpShape *bulletCustomShape; bulletCustomShape = new ofxBulletAssimpShape(currentModelSetId, rand()%(int)modelSetVector[currentModelSetId].size()); ofQuaternion startRot = ofQuaternion(1., 0., 0., PI); int modelId = modelSetVector[bulletCustomShape->getSetId()][bulletCustomShape->getIndex()]; bulletCustomShape->init((btCompoundShape*)referenceAssimpModelBulletShapes[modelId]->getCollisionShape(), referenceAssimpModelBulletShapes[modelId]->getCentroid()); bulletCustomShape->create(world.world, modelStartPosition, startRot, modelMass); bulletCustomShape->add(); ofVec3f frc(camera.getLookAtDir()); frc.normalize(); bulletCustomShape->applyCentralForce(frc*0.005); assimpModelBulletShapes.push_back(bulletCustomShape); } if (enableAddModelRandom && timer.getName() != "interval") { // add model in random x, random y and modelStartPosition.z ofxBulletAssimpShape *bulletCustomShape; bulletCustomShape = new ofxBulletAssimpShape(currentModelSetId, rand()%(int)modelSetVector[currentModelSetId].size()); ofQuaternion startRot = ofQuaternion(ofRandom(0, 1), ofRandom(0, 1), ofRandom(0, 1), ofRandom(-1*PI, PI)); int modelId = modelSetVector[bulletCustomShape->getSetId()][bulletCustomShape->getIndex()]; bulletCustomShape->init((btCompoundShape*)referenceAssimpModelBulletShapes[modelId]->getCollisionShape(), referenceAssimpModelBulletShapes[modelId]->getCentroid()); // random square // ofVec3f instantModelStartPosition(ofRandom(0, w), ofRandom(0, h), modelStartPosition->z); // random circle float instantRadius = ofRandom(0, 500); // float instantRadius = (ofRandom(-500, 500)+ofRandom(-500, 500)+ofRandom(-500, 500)+ofRandom(-500, 500)+ofRandom(-500, 500))/5.0; float instantTheta = ofRandom(-PI, PI); ofVec3f instantModelStartPosition(kinectWidth/2.0+instantRadius*cos(instantTheta), kinectHeight/2.0+instantRadius*sin(instantTheta), modelStartPosition->z); bulletCustomShape->create(world.world, instantModelStartPosition, startRot, modelMass); bulletCustomShape->add(); ofVec3f frc(camera.getLookAtDir()); frc.normalize(); bulletCustomShape->applyCentralForce(frc*ofRandom(-0.01, 0.01)); ofVec3f instantTorque(ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005)); bulletCustomShape->applyTorque(instantTorque); assimpModelBulletShapes.push_back(bulletCustomShape); } if (enableScanPeople) { // add models in modelStartPositioins // ofLogNotice("modelStartPositions"+ofToString(modelStartPositions.size())); for (int i = 0; i < modelStartPositions.size(); i++) { // add model in random x, random y and modelStartPosition.z ofxBulletAssimpShape *bulletCustomShape; bulletCustomShape = new ofxBulletAssimpShape(currentModelSetId, rand()%(int)modelSetVector[currentModelSetId].size()); ofQuaternion startRot = ofQuaternion(ofRandom(0, 1), ofRandom(0, 1), ofRandom(0, 1), ofRandom(-1*PI, PI)); int modelId = modelSetVector[currentModelSetId][rand()%(int)modelSetVector[currentModelSetId].size()]; bulletCustomShape->init((btCompoundShape*)referenceAssimpModelBulletShapes[modelId]->getCollisionShape(), referenceAssimpModelBulletShapes[modelId]->getCentroid()); bulletCustomShape->create(world.world, modelStartPositions[i], startRot, modelMass); bulletCustomShape->add(); ofVec3f frc(camera.getLookAtDir()); frc.normalize(); bulletCustomShape->applyCentralForce(frc*ofRandom(-0.01, 0.01)); ofVec3f instantTorque; switch (currentModelSetId) { case 0: instantTorque.set(ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005)); break; case 1: instantTorque.set(ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005)); break; case 2: instantTorque.set(ofRandom(-0.0001, 0.0001), ofRandom(-0.0001, 0.0001), ofRandom(-0.0001, 0.0001)); break; case 3: instantTorque.set(ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005)); break; case 4: instantTorque.set(ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005)); break; default: break; } bulletCustomShape->applyTorque(instantTorque); assimpModelBulletShapes.push_back(bulletCustomShape); } } // world world.setGravity(worldGravity); world.update(ofGetLastFrameTime()*2, 20); ofRectangle kinectRange(0, 0, kinectWidth, kinectHeight); for( int i = 0; i < assimpModelBulletShapes.size(); i++ ) { // erase model which is in out range(z < 0) if(assimpModelBulletShapes[i]->getPosition().z < 0) { assimpModelBulletShapes[i]->remove(); assimpModelBulletShapes.erase(assimpModelBulletShapes.begin() + i); // erase only one bullet shape // break; }else if(kinectIsReady && kinectRange.inside(assimpModelBulletShapes[i]->getPosition().x, assimpModelBulletShapes[i]->getPosition().y)){ // apply force to bullet shape inside the float instantKinectDepth = rawDepthPixels[(int)assimpModelBulletShapes[i]->getPosition().x + (int)assimpModelBulletShapes[i]->getPosition().y*kinectWidth]; if (instantKinectDepth > kinect.minDistance && instantKinectDepth < kinect.maxDistance && assimpModelBulletShapes[i]->getPosition().z > instantKinectDepth) { // add force to the model which is above the kinect mesh if (ofGetMousePressed()) { ofVec3f wind(0, 0, 0.001); // FIXME: hard code assimpModelBulletShapes[i]->applyCentralForce(wind); } } } } // camera if (enableMouseInput) { camera.enableMouseInput(); }else{ camera.disableMouseInput(); camera.setupPerspective(false, cameraFov, cameraNearDist, cameraFarDist, ofVec2f(0.0f, 0.0f)); camera.setPosition(cameraPosition); camera.lookAt(ofVec3f(cameraLookAt), ofVec3f(0, -1, 0)); } // camera target debugSphereCameraTarget.setPosition(cameraLookAt); // light light.setPosition(lightPosition); light.setSpecularColor(lightSpecularColor); light.setDiffuseColor(lightDissuseColor); light.setAmbientColor(lightAmbientColor); light.setAttenuation(lightAttenuation->x, lightAttenuation->y, lightAttenuation->z); // material material.setSpecularColor(materialSpecularColor); material.setDiffuseColor(materialDiffuseColor); material.setAmbientColor(materialAmbientColor); material.setEmissiveColor(materialEmissiveColor); material.setShininess(materialShininess); }
//------------------------------------------------------------------ void explosion::draw() { ofSetRectMode(OF_RECTMODE_CENTER); if(explode == false){ if(ofGetElapsedTimef()>17){ posa.x-=3; if(posa.x < 0){ posa.x = ofGetWidth(); } } if(ofGetElapsedTimef()<17){ posa.y+=3; if(posa.y > ofGetHeight()){ posa.y = 0; } } float timer = sin(ofGetElapsedTimef()*ofRandom(10)); float alph = ofMap(timer,-1,1, 128, 0); ofColor c2(c1,alph); ofSetColor(c2); ofRect(posa.x, posa.y, 15,15); } if(explode == true){ for(int i =0; i< num; i++){ posb.x = posa.x+ radius*cos(angle + PI*2/num*i); posb.y = posa.y+ radius*-sin(angle + PI*2/num*i); myPct += speed; if(myPct>1)myPct = 1; pct = powf(myPct, 1); pos.x = (1-pct)*posa.x + pct* posb.x; pos.y = (1-pct)*posa.y + pct* posb.y; float alph = ofMap(pct,0,1, 255, 0); ofColor c2(c3,alph); ofSetColor(c2); ofRect(pos.x, pos.y, rectsize,rectsize); if(myPct>1)myPct = 0; pct = powf(myPct, shaper); pos.x = (1-pct)*posa.x + pct* posb.x; pos.y = (1-pct)*posa.y + pct* posb.y; ofRect(pos.x, pos.y, rectsize,rectsize); } } }
void ContourSillhouetteApp::onAppSwitch() { ofColor bg = ofColor(ofRandom(0, 255), ofRandom(0, 255), ofRandom(0, 255)); bg.setSaturation(255); _colorManager.setBackground(bg); }
void AggParticle::reset(){ do { x = ofRandom(0, ofGetWidth()); y = ofRandom(0, ofGetHeight()); } while (field[y * ofGetWidth() + x]); }
void BasicScreenObject::setRandomColor() { setColor(ofRandom(0, 255), ofRandom(0, 255), ofRandom(0, 255)); }
//-------------------------------------------------------------- void GrainPlayer::setGrainSizeRandom(float _val){ grainLength = grainSize * (ofRandom(0.0,_val)+1), 0.025, 0.45; ofClamp(grainLength, 0.025, 0.45); }
void ofApp::keyPressed(int key){ bool bAlt = (key == OF_KEY_ALT); // bool bShift = (key == OF_KEY_SHIFT); does not work? switch(key){ case OF_KEY_UP: if(!bAlt) sequence_thread.change_sleep_time_microsec(sequence_thread.sleep_microsec -= 1000); else sequence_thread.master_delay++; break; case OF_KEY_DOWN: if(!bAlt) sequence_thread.change_sleep_time_microsec(sequence_thread.sleep_microsec += 1000); else sequence_thread.master_delay++; break; // case OF_KEY_RIGHT: sequence_thread.change_freq( sequence_thread.freq+1 ); break; // case OF_KEY_LEFT: sequence_thread.change_freq( sequence_thread.freq-1 ); break; case '1': sequence_thread.change_bpm(100); break; case '2': sequence_thread.change_bpm(200); break; case '3': sequence_thread.change_bpm(300); break; case '4': sequence_thread.change_bpm(400); break; case '5': sequence_thread.change_bpm(500); break; case '6': sequence_thread.change_bpm(600); break; case '7': sequence_thread.change_bpm(700); break; case '8': sequence_thread.change_bpm(800); break; case '9': sequence_thread.change_bpm(900); break; case '0': sequence_thread.change_bpm(1000); break; // play case ' ': dt_config::DT_PLAY_GEN_RHYTHM = !dt_config::DT_PLAY_GEN_RHYTHM; config.synch_param(); break; case OF_KEY_TAB: osc_recorder.toggle_play_fragment(); config.synch_param(); break; case 'q': if(bAlt) all_containers.change_speed_random_all(1, 1); else dt_config::DT_BEAT_SPEED_MAX = 1; config.synch_param(); break; case 'w': if(bAlt) all_containers.change_speed_random_all(1, 4); else dt_config::DT_BEAT_SPEED_MAX = 4; config.synch_param(); break; case 'r': if(bAlt)all_containers.change_speed_random_all(1, 8); else dt_config::DT_BEAT_SPEED_MAX = 8; config.synch_param(); break; case 't': if(bAlt) all_containers.change_speed_random_all(1, 16); else dt_config::DT_BEAT_SPEED_MAX = 16; config.synch_param(); break; case 'y': if(bAlt) all_containers.change_speed_random_all(1, 32); else dt_config::DT_BEAT_SPEED_MAX = 32; config.synch_param(); break; case 'u': if(bAlt) all_containers.change_speed_random_all(1, 64); else dt_config::DT_BEAT_SPEED_MAX = 64; config.synch_param(); break; case 'i': if(bAlt) all_containers.change_speed_random_all(1, 128); else dt_config::DT_BEAT_SPEED_MAX = 128; config.synch_param(); break; case 'o': if(bAlt) all_containers.change_speed_random_all(1, 256); else dt_config::DT_BEAT_SPEED_MAX = 256; config.synch_param(); break; case 'p': if(bAlt) all_containers.change_speed_random_all(1, 512); else dt_config::DT_BEAT_SPEED_MAX = 512; config.synch_param(); break; case '@': if(bAlt) all_containers.change_speed_random_all(1, 1024); else dt_config::DT_BEAT_SPEED_MAX = 1024; config.synch_param(); break; case 'a': all_containers.change_beat_resolution_all(4); break; case 's': all_containers.change_beat_resolution_all(8); break; case 'd': all_containers.change_beat_resolution_all(16); break; case 'f': all_containers.change_beat_resolution_all(32); break; case 'g': all_containers.change_beat_resolution_all(64); break; case 'h': all_containers.change_beat_resolution_all(128); break; case 'j': all_containers.change_beat_resolution_all(256); break; case 'k': all_containers.change_beat_resolution_all(512); break; case 'l': all_containers.change_beat_resolution_all(1024); break; case 'L': dt_config::DT_SHOW_LINER_DRAWER = !dt_config::DT_SHOW_LINER_DRAWER; config.synch_param(); break; case 'G': config.toggle(); break; case 'F': ofToggleFullscreen(); break; case 'B': all_containers.change_beat_all(floor(ofRandom(dt_config::DT_RHYTHM_SHAPE_SLOT_MIN, dt_config::DT_RHYTHM_SHAPE_SLOT_MAX-1))); break; case 'P': all_containers.change_position_all(); break; case 'R': dt_config::DT_SHOW_BUFFERED_RHYTHM = !dt_config::DT_SHOW_BUFFERED_RHYTHM; config.synch_param(); break; case OF_KEY_RETURN: touch.make_random_circle(ofRandom(0, ofGetWidth()), ofRandom(0, ofGetHeight()), 100); break; default: break; } }
//-------------------------------------------------------------- void testApp::setup(){ //cairo.setup("3d.pdf",ofCairoRenderer::PDF); renderer.renderers.push_back(&gl); //renderer.renderers.push_back(&cairo); ofSetDefaultRenderer(&renderer); //ofSetFrameRate( 12 ); //each frame generates a page nCurveVertexes = 7; curveVertices[0].x = 326; curveVertices[0].y = 209; curveVertices[1].x = 306; curveVertices[1].y = 279; curveVertices[2].x = 265; curveVertices[2].y = 331; curveVertices[3].x = 304; curveVertices[3].y = 383; curveVertices[4].x = 374; curveVertices[4].y = 383; curveVertices[5].x = 418; curveVertices[5].y = 309; curveVertices[6].x = 345; curveVertices[6].y = 279; for (int i = 0; i < nCurveVertexes; i++){ curveVertices[i].bOver = false; curveVertices[i].bBeingDragged = false; curveVertices[i].radius = 4; } //------(a)-------------------------------------- // // draw a star // // use poly winding odd, the default rule // // info about the winding rules is here: // http://glprogramming.com/red/images/Image128.gif // shapeA.setHexColor(0xe0be21); shapeA.setFilled(true); shapeA.setPolyWindingMode(OF_POLY_WINDING_ODD); // this is the normal mode shapeA.moveTo(200,135); shapeA.lineTo(15,135); shapeA.lineTo(165,25); shapeA.lineTo(105,200); shapeA.lineTo(50,25); //------(b)-------------------------------------- // // draw a star // // use poly winding nonzero // // info about the winding rules is here: // http://glprogramming.com/red/images/Image128.gif // shapeB.setHexColor(0xb5de10); shapeB.setFilled(true); shapeB.setPolyWindingMode(OF_POLY_WINDING_NONZERO); shapeB.moveTo(400,135); shapeB.lineTo(215,135); shapeB.lineTo(365,25); shapeB.lineTo(305,200); shapeB.lineTo(250,25); shapeB.close(); //------------------------------------- //------(c)-------------------------------------- // // draw a star dynamically // // use the mouse position as a pct // to calc nPoints and internal point radius // float xPct = (float)(200) / (float)(ofGetWidth()); float yPct = (float)(400) / (float)(ofGetHeight()); int nTips = 5 + xPct * 60; int nStarPts = nTips * 2; float angleChangePerPt = TWO_PI / (float)nStarPts; float innerRadius = 0 + yPct*80; float outerRadius = 80; float origx = 525; float origy = 100; float angle = 0; shapeC.setHexColor(0xa16bca); shapeC.setFilled(true); for (int i = 0; i < nStarPts; i++){ if (i % 2 == 0) { // inside point: float x = origx + innerRadius * cos(angle); float y = origy + innerRadius * sin(angle); shapeC.lineTo(x,y); } else { // outside point float x = origx + outerRadius * cos(angle); float y = origy + outerRadius * sin(angle); shapeC.lineTo(x,y); } angle += angleChangePerPt; } //------------------------------------- //------(d)-------------------------------------- // // poylgon of random points // // lots of self intersection, 500 pts is a good stress test // // shapeD.setHexColor(0x0cb0b6); shapeD.setFilled(true); shapeD.setPolyWindingMode(OF_POLY_WINDING_ODD); for (int i = 0; i < 10; i++){ shapeD.lineTo(ofRandom(650,850), ofRandom(20,200)); } //------------------------------------- //------(e)-------------------------------------- // // use sin cos and time to make some spirally shape // shapeE.setHexColor(0xff2220); shapeE.setFilled( true ); shapeE.setPolyWindingMode(OF_POLY_WINDING_ODD); float angleStep = TWO_PI/(100.0f + sin(35/5.0f) * 60); float radiusAdder = 0.5f; float radius = 0; for (int i = 0; i < 200; i++){ float anglef = (i) * angleStep; float x = radius * cos(anglef) + 100; float y = radius * sin(anglef) + 300; shapeE.lineTo(x,y); radius += radiusAdder; } shapeE.close(); //------------------------------------- //------(f)-------------------------------------- // // addCurveVertex // // because it uses catmul rom splines, we need to repeat the first and last // items so the curve actually goes through those points // shapeF.setHexColor(0x2bdbe6); shapeF.setFilled(true); for (int i = 0; i < nCurveVertexes; i++){ // sorry about all the if/states here, but to do catmull rom curves // we need to duplicate the start and end points so the curve acutally // goes through them. // for i == 0, we just call the vertex twice // for i == nCurveVertexes-1 (last point) we call vertex 0 twice // otherwise just normal ofCurveVertex call if (i == 0){ shapeF.curveTo(curveVertices[0].x, curveVertices[0].y); // we need to duplicate 0 for the curve to start at point 0 shapeF.curveTo(curveVertices[0].x, curveVertices[0].y); // we need to duplicate 0 for the curve to start at point 0 } else if (i == nCurveVertexes-1){ shapeF.curveTo(curveVertices[i].x, curveVertices[i].y); shapeF.curveTo(curveVertices[0].x, curveVertices[0].y); // to draw a curve from pt 6 to pt 0 shapeF.curveTo(curveVertices[0].x, curveVertices[0].y); // we duplicate the first point twice } else { shapeF.curveTo(curveVertices[i].x, curveVertices[i].y); } } shapeF.close(); // show a faint the non-curve version of the same polygon: shapeFNonCurve.setFilled( false ); shapeFNonCurve.setColor( ofColor(0,0,0,40) ); for (int i = 0; i < nCurveVertexes; i++){ shapeFNonCurve.lineTo(curveVertices[i].x, curveVertices[i].y); } shapeFNonCurve.close(); //------------------------------------- //------(g)-------------------------------------- // // addBezierVertex // // with addBezierVertex we can draw a curve from the current vertex // through the the next three vertexes we pass in. // (two control points and the final bezier point) // float x0 = 500; float y0 = 300; float x1 = 550+50*cos(5.8*1.0f); float y1 = 300+100*sin(5.8/3.5f); float x2 = 600+30*cos(5.8*2.0f); float y2 = 300+100*sin(5.8); float x3 = 650; float y3 = 300; shapeG.setFilled(true); shapeG.setHexColor(0xFF9933); shapeG.lineTo(x0,y0); shapeG.bezierTo(x1,y1,x2,y2,x3,y3); //------(h)-------------------------------------- // // holes / nextContour // // with nextContour we can create multi-contour shapes // this allows us to draw holes, for example... // shapeH.setFilled(true); shapeH.setHexColor( 0xff00ff ); shapeH.lineTo(100,500); shapeH.lineTo(180,550); shapeH.lineTo(100,600); shapeH.close(); shapeH.lineTo(120,520); shapeH.lineTo(160,550); shapeH.lineTo(120,580); shapeH.close(); //------------------------------------- //------(i)-------------------------------------- // // CSG / nextContour // // with different winding rules, you can even use nextContour to // perform constructive solid geometry // // be careful, the clockwiseness or counter clockwisenss of your multiple // contours matters with these winding rules. // // for csg ideas, see : http://glprogramming.com/red/chapter11.html // // info about the winding rules is here: // http://glprogramming.com/red/images/Image128.gif // shapeIa.setFilled(false); shapeIa.setPolyWindingMode(OF_POLY_WINDING_ODD); shapeIa.setHexColor(0xff00ff); shapeIa.lineTo(300,500); shapeIa.lineTo(380,550); shapeIa.lineTo(300,600); shapeIa.close(); shapeIa.arc(340,550,30,30,0,360); shapeIb.setPolyWindingMode(OF_POLY_WINDING_NONZERO); shapeIb.setHexColor(0xff00ff); shapeIb.setFilled(false); shapeIb.lineTo(400,500); shapeIb.lineTo(480,550); shapeIb.lineTo(400,600); shapeIb.close(); shapeIb.arc(440,550,30,60,0,360); shapeIc.setPolyWindingMode(OF_POLY_WINDING_ABS_GEQ_TWO); shapeIc.setHexColor(0xff00ff); shapeIc.setFilled(false); shapeIc.lineTo(500,500); shapeIc.lineTo(580,550); shapeIc.lineTo(500,600); shapeIc.close(); shapeIc.arc(540,550,30,20,0,360); selectedDraggableVertex.arc(0,0,4,4,0,360); selectedDraggableVertex.setFilled(true); selectedDraggableVertex.setColor(ofColor(0,0,0,80)); unselectedDraggableVertex.arc(0,0,4,4,0,360); unselectedDraggableVertex.setFilled(false); unselectedDraggableVertex.setColor(ofColor(0,0,0,80)); }
void testApp::setup(){ ofSetVerticalSync(true); ofSetFrameRate(60); ofBackground(0, 0, 0); p.setInitialCondition(300,300,ofRandom(-1,1), ofRandom(-1,1)); }
void testApp::mousePressed(int x, int y, int button){ p.setInitialCondition(x,y,ofRandom(-10,10), ofRandom(-10,10)); }
void Line::setup() { xPos = (ofGetWidth()/2); yPos = (ofGetHeight()/2); lineLength = ofRandom(50, 200); lineWidth = ofRandom(20, 50); lineColor = ofColor(ofRandom(0,20), ofRandom(100,150), ofRandom(0,255)); //connor's stuff rotation = ofRandom(0,360); stemLength = ofRandom(50,100); stemWidth = ofRandom(2,4); leafLength = ofRandom(150,300); leafWidth = ofRandom(80,200); leafCurvature = ofRandom(1, 5); }
void LetterParticle::kill() { BaseParticle::kill(); // call the super /parent class! std::vector<ofTTFCharacter> paths = font.getStringAsPoints(text); std::vector<ofTTFCharacter>::iterator pathsIter = paths.begin(); while(pathsIter != paths.end()) { std: vector<ofPolyline> polylines = (*pathsIter).getOutline(); std::vector<ofPolyline>::const_iterator polyIter = polylines.begin(); while(polyIter != polylines.end()) { if((*polyIter).size() > 0) { ofPolyline resampled = (*polyIter).getResampledBySpacing(2); // this number tells us how many particles if(resampled.size() > 0) { const ofPolyline poly = resampled.getVertices(); auto centroid = poly.getCentroid2D(); // find the middle // create a particle group std::shared_ptr<BaseParticleGroup> particleGroup(new BaseParticleGroup()); // add particles to the particle system AND to the particle group for(int i = 0; i < poly.size(); ++i) { std::shared_ptr<ParticleGroupMember> particle(new ParticleGroupMember()); // this is how we get the particle to move away from the center // of the group (as calculated by the centroid) auto newVelocity = glm::normalize(poly[i] - centroid) * ofRandom(.5,2); particle->position = position + poly[i]; particle->velocity = velocity + newVelocity; particle->acceleration = acceleration; particle->maxAge = ofRandom(50,100); particle->particleSystem = particleSystem; // make a link back to the particle system particleSystem->addParticle(particle); particleGroup->members.push_back(particle); } // add the particle group to the particle system particleSystem->addParticleGroup(particleGroup); } } ++polyIter; } ++pathsIter; } }
void customTriangles::setup() { pos.set(0); triangleColor.set(ofRandom(255), ofRandom(255), ofRandom(255)); }
void testApp::generateTexture() { int currentDay = panel.getValueI("currentDay"); int currentTime = panel.getValueI("currentTime"); int meaningful = panel.getValueI("meaningful"); int maxDays = panel.getValueI("maxDays"); int multi = 5; // size multiplier ofPolyline currentMeaning; ofPolyline theTime; ofPolyline avgTime; bool bIsPastCurrentDate = false; for(int days=1; days<=maxDays; days++) { for(int hours=0; hours<23; hours++) { int index = ((hours+1)/24) + days; //This randomly generates a meanginful time bool bNoMoreMeaning=false; int fakeMeaning = fakeMeaning + ofRandom(3); if( ofRandom(4) == 0 ) { bNoMoreMeaning = true; } if(days==currentDay) { if( hours == currentTime ) { bIsPastCurrentDate = true; } } if(!bIsPastCurrentDate) { theTime.addVertex(index*multi,0); } else { theTime.addVertex(index*multi,buffer.getHeight()); } if(!bNoMoreMeaning) { currentMeaning.addVertex(index*multi, fakeMeaning*multi); } else { currentMeaning.addVertex(index*multi,0); } // Alright, enough fake meaning. On to time. } } currentMeaning.addVertex(points.size() * multi, 0); currentMeaning.addVertex(0,0); currentMeaning.setClosed(true); theTime.addVertex(points.size() * multi, 0); theTime.addVertex(0,0); theTime.setClosed(true); avgTime.addVertex(points.size() * multi, 0); avgTime.addVertex(0,0); avgTime.setClosed(true); //Begin writing to the FbO buffer.begin(); ofBackground(255); /*for(int i=0;i<buffer.getWidth();i++){ ofSetColor(ofRandom(255),ofRandom(255),ofRandom(255)); ofLine(i,i,ofRandom(i),buffer.getHeight()+ofRandom(buffer.getHeight())); } */ int scaleX = panel.getValueF("scaleX"); int scaleY = panel.getValueF("scaleY"); glPushMatrix(); ofFill(); ofSetLineWidth(5); ofScale(scaleX,scaleY); ofSetColor(255,0,0); theTime.draw(); ofSetColor(0,255,0); avgTime.draw(); ofSetColor(0,0,255); currentMeaning.draw(); glPopMatrix(); ofSetLineWidth(1); buffer.end(); graph = buffer.getTextureReference(); }
ofxSimpleSpline* Maze::createSimpleSpline(int sx, int sy, int length) { bool cellSearched[NUM_CELLS_X][NUM_CELLS_Y] = {false}; std::stack<MazeCell*> solveStack; MazeCell* cell = cells[sx][sy]; solveStack.push(cell); for (int i=0; i<length; i++) { // this is one step // add available direction from the current cell vector<int> dirs; if (!cell->top) dirs.push_back(0); if (!cell->right) dirs.push_back(1); if (!cell->bottom) dirs.push_back(2); if (!cell->left) dirs.push_back(3); bool found = false; while(!found) { int x = cell->getX(); int y = cell->getY(); int dirIdx = (int)ofRandom(dirs.size()); int dir = dirs[dirIdx]; switch (dir) { case 0: if (y>0 && !cellSearched[x][y-1]) { cell = cells[x][y-1]; solveStack.push(cell); cellSearched[x][y-1] = true; found=true; } else { dirs.erase(dirs.begin() + dirIdx); } break; case 1: if (x<NUM_CELLS_X-1 && !cellSearched[x+1][y]) { cell = cells[x+1][y]; solveStack.push(cell); cellSearched[x+1][y] = true; found=true; } else { dirs.erase(dirs.begin() + dirIdx); } break; case 2: if (y<NUM_CELLS_Y-1 && !cellSearched[x][y+1]) { cell = cells[x][y+1]; solveStack.push(cell); cellSearched[x][y+1] = true; found=true; } else { dirs.erase(dirs.begin() + dirIdx); } break; case 3: if (x>0 && !cellSearched[x-1][y]) { cell = cells[x-1][y]; solveStack.push(cell); cellSearched[x-1][y] = true; found=true; } else { dirs.erase(dirs.begin() + dirIdx); } break; } if (!found && dirs.size()==0) { // we got to an end point, pop from the stack (backtracing) i--; solveStack.pop(); cell = solveStack.top(); found = true; } } } // create the path curve based on solveStack vector<ofVec3f> points; while (!solveStack.empty()) { cell = solveStack.top(); //cout<<"cell["<<cell->getX()<<"]["<<cell->getY()<<"]\n"; points.push_back(ofVec3f(cell->getX()*cellSize+cellSize/2, settings->ballRadius, cell->getY()*cellSize+cellSize/2)); solveStack.pop(); } ofxSimpleSpline* curve = new ofxSimpleSpline(); curve->setSubdivisions(10); curve->addControlVertices(points); curve->update(); return curve; }
//-------------------------------------------------------------- void testApp::update(){ for ( int i=0; i < 30; i ++){ if(i<5){ float sinOfTime = sin(ofGetElapsedTimef() * (0.3)); //for the speed of on/off float sinOfTimeMapped = ofMap(sinOfTime, -1, 1, 0, 255); ofEnableAlphaBlending(); //para cambiar la transparencia myCircle[i].color = (255, 250, 205, sinOfTimeMapped); //initial color amarillo un poco if(sinOfTimeMapped <= 50){ myCircle[i].x = ofRandom(ofGetWindowWidth()); myCircle[i].y = ofRandom(ofGetWindowHeight()); } else{ // // myCircle[i].y --; // myCircle[i].x ++; } if(myCircle[i].x > ofGetWindowWidth() || myCircle[i].x < 0) { myCircle[i].x = ofRandom(ofGetWindowWidth()); } if( myCircle[i].y > ofGetWindowHeight() || myCircle[i].y < 0) { myCircle[i].y = ofRandom(ofGetWindowHeight()); } } else { float sinOfTime = sin( ofGetElapsedTimef() * (i/3)); //sino es muy rapido el cambio float sinOfTimeMapped = ofMap( sinOfTime, -1, 1, 0, 255); ofEnableAlphaBlending(); //para cambiar la transparencia myCircle[i].color = (255, 250, 205, sinOfTimeMapped); //initial color amarillo un poco if(sinOfTimeMapped == 0){ myCircle[i].x = ofRandom(ofGetWindowWidth()); myCircle[i].y = ofRandom(ofGetWindowHeight()); } else{ // myCircle[i].y --; // myCircle[i].x ++; } if( myCircle[i].x > ofGetWindowWidth() || myCircle[i].x < 0) { myCircle[i].x = ofRandom(ofGetWindowWidth()); } if( myCircle[i].y > ofGetWindowHeight() || myCircle[i].y < 0) { myCircle[i].y = ofRandom(ofGetWindowHeight()); } } } }
void Maze::generateStep() { if (finishedGenerating) { return; } bool valid = false; std::vector<int> available_dirs; for (int i=0;i<4;i++) { available_dirs.push_back(i); } while (!valid) { int curx = currentCell->getX(); int cury = currentCell->getY(); int dir_idx = (int)ofRandom(available_dirs.size()); int dir = available_dirs[dir_idx]; switch(dir) { case 0: if (cury > 0 && cells[curx][cury-1]->notVisited()) { currentCell->top = false; currentCell = cells[curx][cury-1]; currentCell->visit(); currentCell->bottom = false; cellStack.push(currentCell); valid = true; } else { available_dirs.erase(available_dirs.begin() + dir_idx); } break; case 1: if (curx < NUM_CELLS_X-1 && cells[curx+1][cury]->notVisited()) { currentCell->right = false; currentCell = cells[curx+1][cury]; currentCell->visit(); currentCell->left = false; cellStack.push(currentCell); valid = true; } else { available_dirs.erase(available_dirs.begin() + dir_idx); } break; case 2: if (cury < NUM_CELLS_Y-1 && cells[curx][cury+1]->notVisited()) { currentCell->bottom = false; currentCell = cells[curx][cury+1]; currentCell->visit(); currentCell->top = false; cellStack.push(currentCell); valid = true; } else { available_dirs.erase(available_dirs.begin() + dir_idx); } break; case 3: if (curx > 0 && cells[curx-1][cury]->notVisited()) { currentCell->left = false; currentCell = cells[curx-1][cury]; currentCell->visit(); currentCell->right = false; cellStack.push(currentCell); valid = true; } else { available_dirs.erase(available_dirs.begin() + dir_idx); } break; } // end switch if (!valid && available_dirs.size() == 0) { if (!cellStack.empty()) { currentCell = cellStack.top(); cellStack.pop(); } else { finishedGenerating = true; currentCell = NULL; } valid = true; } } // end while }
//-------------------------------------------------------------- void GrainPlayer::setPositionRandom(float _val){ grainPosition = ofWrap(playHead + (ofRandom(0.0,_val)),0.0,1.0); }
// Make a random ruleset void CA::randomize(){ for (int i = 0; i < 8; i++){ ruleset[i] = int(ofRandom(2)); } }
//-------------------------------------------------------------- void GrainPlayer::setPitchRandom(float _val){ grainPitch = pitch * (ofRandom(0.0, ofMap(_val, 0.0, 1.0, 0.0, 4.0))+1); }
//-------------------------------------------------------------- void testApp::draw(){ ofSetColor(ofRandom(0,255), ofRandom(0,255), ofRandom(0,255), ofRandom(0,255)); myRectangle.draw(); newRectangle.draw(); }
vector<ofPoint> FacadeBoxRipple::getFacadeLine(ofPoint ptA, ofPoint ptB, ofPoint pp) { newPoints.clear(); newExPoints.clear(); vPtA = ofxVec2f( ptA.x, ptA.y ); vPtB = ofxVec2f( ptB.x, ptB.y ); ofxVec2f vPP = (vPtB-vPtA).normalize();//ofxVec2f( pp.x, pp.y ); // generate a number of points based on length of line float length = sqrt( (ptA.x-ptB.x)*(ptA.x-ptB.x)+(ptA.y-ptB.y)*(ptA.y-ptB.y) );//.length(); int maxPts = length / minLong; int minPts = length / maxLong; float tLength = 0; int nPts = 0; // create a random number of points between what is possible int totalPts = ofRandom(minPts, maxPts); // generate random lengths for each between min/max length possible vector<float> rLens; for( int i = 0; i < totalPts; i++) { rLens.push_back( ofRandom(minLong, maxLong)); tLength += rLens[i]; } // adjust the lngths so that it is more proportional, last one is not too short or too long float lengthLast = length-tLength; // check if we are not long enough cout << "length : " << length << " tlength: " << tLength << " difflen: " << lengthLast << endl; if(tLength == 0 ) return newLinePoints; if( lengthLast < minLong ) { while( (length-tLength) < minLong) { tLength = 0; for( int i = 0; i < totalPts; i++) { rLens[i] *= .999; if(rLens[i] < minLong) rLens[i] = minLong; tLength += rLens[i]; } } }else if( lengthLast > maxLong ) { while( (length-tLength) > maxLong) { tLength = 0; for( int i = 0; i < totalPts; i++) { rLens[i]*=1.0001; if(rLens[i] > maxLong) rLens[i] = maxLong; tLength += rLens[i]; } } } // insert the first newPoints.push_back( ofPoint(ptA.x,ptA.y) ); // create points at the new length tLength = 0; for( int i = 0; i < totalPts; i++) { tLength += rLens[i]; newPoints.push_back( ofPoint(ptA.x + tLength*vPP.x, ptA.y + tLength*vPP.y) ); } // insert the last newPoints.push_back( ofPoint(ptB.x,ptB.y) ); // ??!! save the extrusions, and use to create the next point, or do all the points here?? // create extrusions for( int i = 0; i < newPoints.size()-1; i++) { // get a random extrude float extrude = ofRandom(minExtrude,maxExtrude); // newExPoints.push_back( ofPoint( newPoints[i].x + extrude * pp.x, newPoints[i].y + extrude * pp.y) ); newExPoints.push_back( ofPoint( newPoints[i+1].x + extrude * pp.x, newPoints[i+1].y + extrude * pp.y) ); } // create line newLinePoints.clear(); // insert first newLinePoints.push_back(newExPoints[0]); int t = 1; for( int i = 1; i < newExPoints.size(); i++) { newLinePoints.push_back( newExPoints[i] ); //ofPoint(newExPoints[i].x,newExPoints[i-1].y) ); //newLinePoints.push_back(newExPoints[i]); } //insert last //int lst = newExPoints.size()-1; //newLinePoints.push_back(ofPoint(newExPoints[lst].x,newExPoints[lst-1].y) ); return newLinePoints; }
//assigns IDs to each blob in the contourFinder void BlobTracker::track(ContourFinder* newBlobs) { printf("1\n"); //initialize ID's of all blobs for(int i=0; i<newBlobs->nBlobs; i++) newBlobs->blobs[i].id=-1; //go through all tracked blobs to compute nearest new point for(int i=0; i<trackedBlobs.size(); i++) { /****************************************************************** * *****************TRACKING FUNCTION TO BE USED******************* * Replace 'trackKnn(...)' with any function that will take the * current track and find the corresponding track in the newBlobs * 'winner' should contain the index of the found blob or '-1' if * there was no corresponding blob *****************************************************************/ int winner = trackKnn(newBlobs, &(trackedBlobs[i]), 3, 0); if(winner==-1) //track has died, mark it for deletion { //SEND BLOB OFF EVENT TouchEvents.messenger = trackedBlobs[i]; if(isCalibrating){ TouchEvents.RAWmessenger = trackedBlobs[i]; TouchEvents.notifyRAWTouchUp(NULL); } calibrate->transformDimension(TouchEvents.messenger.boundingRect.width, TouchEvents.messenger.boundingRect.height); calibrate->cameraToScreenPosition(TouchEvents.messenger.centroid.x, TouchEvents.messenger.centroid.y); //erase calibrated blob from map calibratedBlobs.erase(TouchEvents.messenger.id); TouchEvents.notifyTouchUp(NULL); //mark the blob for deletion trackedBlobs[i].id = -1; } else //still alive, have to update { //if winning new blob was labeled winner by another track\ //then compare with this track to see which is closer if(newBlobs->blobs[winner].id!=-1) { //find the currently assigned blob int j; //j will be the index of it for(j=0; j<trackedBlobs.size(); j++) { if(trackedBlobs[j].id==newBlobs->blobs[winner].id) break; } if(j==trackedBlobs.size())//got to end without finding it { newBlobs->blobs[winner].id = trackedBlobs[i].id; newBlobs->blobs[winner].age = trackedBlobs[i].age; newBlobs->blobs[winner].sitting = trackedBlobs[i].sitting; newBlobs->blobs[winner].downTime = trackedBlobs[i].downTime; newBlobs->blobs[winner].color = trackedBlobs[i].color; newBlobs->blobs[winner].lastTimeTimeWasChecked = trackedBlobs[i].lastTimeTimeWasChecked; trackedBlobs[i] = newBlobs->blobs[winner]; } else //found it, compare with current blob { double x = newBlobs->blobs[winner].centroid.x; double y = newBlobs->blobs[winner].centroid.y; double xOld = trackedBlobs[j].centroid.x; double yOld = trackedBlobs[j].centroid.y; double xNew = trackedBlobs[i].centroid.x; double yNew = trackedBlobs[i].centroid.y; double distOld = (x-xOld)*(x-xOld)+(y-yOld)*(y-yOld); double distNew = (x-xNew)*(x-xNew)+(y-yNew)*(y-yNew); //if this track is closer, update the ID of the blob //otherwise delete this track.. it's dead if(distNew<distOld) //update { newBlobs->blobs[winner].id = trackedBlobs[i].id; newBlobs->blobs[winner].age = trackedBlobs[i].age; newBlobs->blobs[winner].sitting = trackedBlobs[i].sitting; newBlobs->blobs[winner].downTime = trackedBlobs[i].downTime; newBlobs->blobs[winner].color = trackedBlobs[i].color; newBlobs->blobs[winner].lastTimeTimeWasChecked = trackedBlobs[i].lastTimeTimeWasChecked; //TODO-------------------------------------------------------------------------- //now the old winning blob has lost the win. //I should also probably go through all the newBlobs //at the end of this loop and if there are ones without //any winning matches, check if they are close to this //one. Right now I'm not doing that to prevent a //recursive mess. It'll just be a new track. //SEND BLOB OFF EVENT TouchEvents.messenger = trackedBlobs[j]; if(isCalibrating){ TouchEvents.RAWmessenger = trackedBlobs[j]; TouchEvents.notifyRAWTouchUp(NULL); } calibrate->transformDimension(TouchEvents.messenger.boundingRect.width, TouchEvents.messenger.boundingRect.height); calibrate->cameraToScreenPosition(TouchEvents.messenger.centroid.x, TouchEvents.messenger.centroid.y); //erase calibrated blob from map calibratedBlobs.erase(TouchEvents.messenger.id); TouchEvents.notifyTouchUp(NULL); //mark the blob for deletion trackedBlobs[j].id = -1; //------------------------------------------------------------------------------ } else //delete { //SEND BLOB OFF EVENT TouchEvents.messenger = trackedBlobs[i]; if(isCalibrating){ TouchEvents.RAWmessenger = trackedBlobs[i]; TouchEvents.notifyRAWTouchUp(NULL); } calibrate->transformDimension(TouchEvents.messenger.boundingRect.width, TouchEvents.messenger.boundingRect.height); calibrate->cameraToScreenPosition(TouchEvents.messenger.centroid.x, TouchEvents.messenger.centroid.y); //erase calibrated blob from map calibratedBlobs.erase(TouchEvents.messenger.id); TouchEvents.notifyTouchUp(NULL); //mark the blob for deletion trackedBlobs[i].id = -1; } } } else //no conflicts, so simply update { newBlobs->blobs[winner].id = trackedBlobs[i].id; newBlobs->blobs[winner].age = trackedBlobs[i].age; newBlobs->blobs[winner].sitting = trackedBlobs[i].sitting; newBlobs->blobs[winner].downTime = trackedBlobs[i].downTime; newBlobs->blobs[winner].color = trackedBlobs[i].color; newBlobs->blobs[winner].lastTimeTimeWasChecked = trackedBlobs[i].lastTimeTimeWasChecked; } } } //--Update All Current Tracks //remove every track labeled as dead (ID='-1') //find every track that's alive and copy it's data from newBlobs for(int i=0; i<trackedBlobs.size(); i++) { if(trackedBlobs[i].id==-1) //dead { //erase track trackedBlobs.erase(trackedBlobs.begin()+i, trackedBlobs.begin()+i+1); i--; //decrement one since we removed an element } else //living, so update it's data { for(int j=0; j<newBlobs->nBlobs; j++) { if(trackedBlobs[i].id==newBlobs->blobs[j].id) { //update track ofPoint tempLastCentroid = trackedBlobs[i].centroid; // assign the new centroid to the old trackedBlobs[i]=newBlobs->blobs[j]; trackedBlobs[i].lastCentroid = tempLastCentroid; //get the Differences in position trackedBlobs[i].D.set((trackedBlobs[i].centroid.x - trackedBlobs[i].lastCentroid.x) / (ofGetElapsedTimef() - trackedBlobs[i].lastTimeTimeWasChecked), (trackedBlobs[i].centroid.y - trackedBlobs[i].lastCentroid.y) / (ofGetElapsedTimef() - trackedBlobs[i].lastTimeTimeWasChecked)); //printf("D(%f, %f)\n", trackedBlobs[i].D.x, trackedBlobs[i].D.y); //if( abs((int)trackedBlobs[i].D.x) > 1 || abs((int)trackedBlobs[i].D.y) > 1) { // printf("\nUNUSUAL BLOB @ %f\n-----------------------\ntrackedBlobs[%i]\nD = (%f, %f)\nXY= (%f, %f)\nlastTimeTimeWasChecked = %f\nsitting = %f\n", // ofGetElapsedTimef(), // i, // trackedBlobs[i].D.x, trackedBlobs[i].D.y, // trackedBlobs[i].centroid.x, trackedBlobs[i].centroid.y, // trackedBlobs[i].lastTimeTimeWasChecked, // trackedBlobs[i].downTime, // trackedBlobs[i].sitting // ); // } //calculate the accelleration ofPoint tD = trackedBlobs[i].D; trackedBlobs[i].maccel = sqrtf((tD.x* tD.x)+(tD.y*tD.y)/(ofGetElapsedTimef() - trackedBlobs[i].lastTimeTimeWasChecked)); trackedBlobs[i].lastTimeTimeWasChecked = ofGetElapsedTimef(); //calculate the age trackedBlobs[i].age = ofGetElapsedTimef() - trackedBlobs[i].downTime; //if not moving more than min_movement_threshold then set to same position as last frame if(trackedBlobs[i].maccel < MIN_MOVEMENT_THRESHOLD) { //this helps avoid jittery blobs trackedBlobs[i].centroid.x = trackedBlobs[i].lastCentroid.x; trackedBlobs[i].centroid.y = trackedBlobs[i].lastCentroid.y; } //set sitting (held length) if(trackedBlobs[i].maccel < 7) { //1 more frame of sitting if(trackedBlobs[i].sitting != -1) trackedBlobs[i].sitting = ofGetElapsedTimef() - trackedBlobs[i].downTime; } else { trackedBlobs[i].sitting = -1; } //printf("time: %f\n", ofGetElapsedTimef()); //printf("%i age: %f, downTimed at: %f\n", i, trackedBlobs[i].age, trackedBlobs[i].downTime); //if blob has been 'holding/sitting' for 1 second send a held event if(trackedBlobs[i].sitting > 1.0f){ //SEND BLOB HELD EVENT TouchEvents.messenger = trackedBlobs[i]; if(isCalibrating){ TouchEvents.RAWmessenger = trackedBlobs[i]; TouchEvents.notifyRAWTouchHeld(NULL); } //calibrated values calibrate->transformDimension(TouchEvents.messenger.boundingRect.width, TouchEvents.messenger.boundingRect.height); calibrate->cameraToScreenPosition(TouchEvents.messenger.centroid.x, TouchEvents.messenger.centroid.y); calibrate->cameraToScreenPosition(TouchEvents.messenger.lastCentroid.x, TouchEvents.messenger.lastCentroid.y); //Calibrated dx/dy TouchEvents.messenger.D.set((TouchEvents.messenger.centroid.x - TouchEvents.messenger.lastCentroid.x) / (ofGetElapsedTimef() - TouchEvents.messenger.lastTimeTimeWasChecked), (TouchEvents.messenger.centroid.y - TouchEvents.messenger.lastCentroid.y) / (ofGetElapsedTimef() - TouchEvents.messenger.lastTimeTimeWasChecked)); TouchEvents.messenger.lastTimeTimeWasChecked = ofGetElapsedTimef(); //calibrated accelleration ofPoint tD2 = TouchEvents.messenger.D; TouchEvents.messenger.maccel = sqrtf((tD2.x* tD2.x)+(tD2.y*tD2.y)/(ofGetElapsedTimef() - trackedBlobs[i].lastTimeTimeWasChecked)); //add to calibration map calibratedBlobs[TouchEvents.messenger.id] = TouchEvents.messenger; //held event only happens once so set to -1 trackedBlobs[i].sitting = -1; TouchEvents.notifyTouchHeld(NULL); } else { //printf("(%f, %f) -> (%f, %f) \n", trackedBlobs[i].lastCentroid.x, trackedBlobs[i].lastCentroid.y, trackedBlobs[i].centroid.x, trackedBlobs[i].centroid.y); //SEND BLOB MOVED EVENT TouchEvents.messenger = trackedBlobs[i]; if(isCalibrating){ TouchEvents.RAWmessenger = trackedBlobs[i]; TouchEvents.notifyRAWTouchMoved(NULL); } //calibrated values calibrate->transformDimension(TouchEvents.messenger.boundingRect.width, TouchEvents.messenger.boundingRect.height); calibrate->cameraToScreenPosition(TouchEvents.messenger.centroid.x, TouchEvents.messenger.centroid.y); calibrate->cameraToScreenPosition(TouchEvents.messenger.lastCentroid.x, TouchEvents.messenger.lastCentroid.y); //Calibrated dx/dy TouchEvents.messenger.D.set((TouchEvents.messenger.centroid.x - TouchEvents.messenger.lastCentroid.x) / (ofGetElapsedTimef() - TouchEvents.messenger.lastTimeTimeWasChecked), (TouchEvents.messenger.centroid.y - TouchEvents.messenger.lastCentroid.y) / (ofGetElapsedTimef() - TouchEvents.messenger.lastTimeTimeWasChecked)); TouchEvents.messenger.lastTimeTimeWasChecked = ofGetElapsedTimef(); //printf("d(%0.4f, %0.4f)\n", TouchEvents.messenger.D.x, TouchEvents.messenger.D.y); //calibrated accelleration ofPoint tD2 = TouchEvents.messenger.D; TouchEvents.messenger.maccel = sqrtf((tD2.x* tD2.x)+(tD2.y*tD2.y)/(ofGetElapsedTimef() - trackedBlobs[i].lastTimeTimeWasChecked)); //add to calibration map calibratedBlobs[TouchEvents.messenger.id] = TouchEvents.messenger; TouchEvents.notifyTouchMoved(NULL); } } } } } //--Add New Living Tracks //now every new blob should be either labeled with a tracked ID or\ //have ID of -1... if the ID is -1... we need to make a new track for(int i=0; i<newBlobs->nBlobs; i++) { if(newBlobs->blobs[i].id==-1) { //add new track newBlobs->blobs[i].id=IDCounter++; newBlobs->blobs[i].downTime = ofGetElapsedTimef(); //newBlobs->blobs[i].lastTimeTimeWasChecked = ofGetElapsedTimef(); //random color for blob. Could be useful? int r = ofRandom(0, 255); int g = ofRandom(0, 255); int b = ofRandom(0, 255); //Convert to hex int rgbNum = ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); //Set color newBlobs->blobs[i].color = rgbNum; //Add to blob messenger TouchEvents.messenger = newBlobs->blobs[i]; if(isCalibrating){ TouchEvents.RAWmessenger = newBlobs->blobs[i]; TouchEvents.notifyRAWTouchDown(NULL); } calibrate->transformDimension(TouchEvents.messenger.boundingRect.width, TouchEvents.messenger.boundingRect.height); calibrate->cameraToScreenPosition(TouchEvents.messenger.centroid.x, TouchEvents.messenger.centroid.y); //add to calibrated blob map calibratedBlobs[TouchEvents.messenger.id] = TouchEvents.messenger; //Send Event TouchEvents.notifyTouchDown(NULL); trackedBlobs.push_back(newBlobs->blobs[i]); } } }
//-------------------------------------------------------------- void testApp::setup(){ amplitude = 100; ofSetBackgroundAuto(false); period = 50; pointX, pointY = 0; targetX = ofGetWidth(); targetY = ofGetHeight(); easing = 0.01; ofBackground(0, 0, 0); ofSetFrameRate(30); yellowBall.x = ofRandomWidth(); yellowBall.y = ofRandomHeight(); yellowBall.vx = ofRandom(-10,10); yellowBall.vy = ofRandom(-10,10); whiteBall.x = ofRandomWidth(); whiteBall.y = ofRandomHeight(); whiteBall.vx = ofRandom(-10,10); whiteBall.vy = ofRandom(-10,10); redBall.x = ofRandomWidth(); redBall.y = ofRandomHeight(); redBall.vx = ofRandom(-30,10); redBall.vy = ofRandom(-30,10); greenBall.x = ofRandomWidth(); greenBall.y = ofRandomHeight(); greenBall.vx = ofRandom(-15,10); greenBall.vy = ofRandom(-15,10); grayBall.x = ofRandomWidth(); grayBall.y = ofRandomHeight(); grayBall.vx = ofRandom(-20,10); grayBall.vy = ofRandom(-20,10); purpleBall.x = ofRandomWidth(); purpleBall.y = ofRandomHeight(); purpleBall.vx = ofRandom(-75,10); purpleBall.vy = ofRandom(-75,10); orangeBall.x = ofRandomWidth(); orangeBall.y = ofRandomHeight(); orangeBall.vx = ofRandom(-20,10); orangeBall.vy = ofRandom(-20,10); blueBall.x = ofRandomWidth(); blueBall.y = ofRandomHeight(); blueBall.vx = ofRandom(-15,10); blueBall.vy = ofRandom(-15,10); }
//-------------------------------------------------------------- void testApp::setup(){ ofSetVerticalSync(true); ofSetFrameRate(60); ofSetCircleResolution(30); //goal for (int i; i<3; i++) { ofImage img; img.loadImage("xiaoren"+ofToString(i)+".png"); xiaoren.push_back(img); } // saver.loadImage("xiaoren.png"); for (int i = 0; i < 30; i++){ particle * p = new particle(); goals.push_back(p); goals[i]->drawWhat =2; goals[i]->setInitialCondition(ofRandom(-ofGetWidth()*0.8,ofGetWidth()*2*0.8),ofRandom(-ofGetWidth()*0.8, ofGetWidth()*2)*0.8,0,0); goals[i]->vel.set(0,0); goals[i]->saver = & xiaoren[ofRandom(0,2)]; } firstTime=ofGetElapsedTimeMillis(); bStartTime = true; bWaitTowin = false; bGameStatus = false; //ship shipExplode=false; ship.setInitialCondition(ofGetWidth()/2, ofGetHeight()/2, 0, 0); ship.drawWhat = 1; ship.damping = 0.03f; shipImag.loadImage("ship001.png"); shipImagFire.loadImage("fire.png"); shipRadiance = 40; ship.img = &shipImag; ship.imgFire = &shipImagFire; //particles asteroid.loadImage("asteroid.png"); for (int i = 0; i < 200; i++){ float scale = ofRandom(1,3); particle * p = new particle(); myParticles.push_back(p); myParticles[i]->pos.set(ofRandom(-ofGetWidth(),ofGetWidth()*2),ofRandom(-ofGetWidth(),ofGetWidth()*2)); myParticles[i]->vel.set(0,0); myParticles[i]->asteroid =& asteroid; myParticles[i]->scale = scale; } shield=3; //bg backgroundImage.loadImage("universe.jpg"); bgPos.set(0, 0); bgMusic.loadSound("backgroundMusic.mp3"); bgMusic.setLoop(true); bgMusic.play(); bgMusic.setVolume(1.5); //text verdana.loadFont("Visitor-TT1--BRK-.ttf", 15); verdana2.loadFont("Visitor-TT1--BRK-.ttf", 40); score = 0; }
//-------------------------------------------------------------- void ofApp::setup(){ if( !ofFile::doesFileExist("11to16.bin") ){ ofSystemAlertDialog("Make sure you have 11to16.bin, xTable.bin and zTable.bin in your data folder!"); ofExit(); } ofBackground(0, 0, 0); // kinect kinectIsReady = false; kinect.open(); kinectWidth = 512; kinectHeight = 424; kinectDepth = (int)kinect.maxDistance.getMax(); // listener reset.addListener(this, &ofApp::resetPressed); enableSmoothLighting.addListener(this, &ofApp::enableSmoothLightingChanged); enableScanPeople.addListener(this, &ofApp::enableScanPeopleChanged); saveReferenceDepthPixels.addListener(this, &ofApp::saveReferenceDepthPixelsPressed); ofAddListener(ofxSimpleTimer::TIMER_COMPLETE, this, &ofApp::timerComplete); // gui showPanel = true; panel.setup("distance in mm", "settings.xml", 0, 0); // - kinect panel.add(kinect.minDistance); panel.add(kinect.maxDistance); panel.add(step.set("step", 5, 3, 30)); panel.add(stopUpdatingKinectBullet.set("stopUpdatingKinectBullet", false)); // - debug panel.add(enableDrawDebug.set("enableDrawDebug", true)); panel.add(enableDrawKinectWireFrame.set("enableDrawKinectWireFrame", true)); panel.add(enableDrawAssimpModelWireFrame.set("enableDrawAssimpModelWireFrame", false)); panel.add(hideKinectMesh.set("hideKinectMesh", false)); panel.add(enableDrawGuideLine.set("enableDrawGuideLine", false)); panel.add(enableMouseInput.set("enableMouseInput", true)); panel.add(enableDrawDebugSpheres.set("enableDrawDebugSpheres", false)); panel.add(enableScanPeople.set("enableScanPeople", false)); panel.add(saveReferenceDepthPixels.setup("saveReferenceDepth")); panel.add(probabilityFactor.set("probabilityFactor", kinect.maxDistance, 1*PROBABILITY_FACTOR_MIN_FACTOR, kinect.maxDistance.getMax()*PROBABILITY_FACTOR_MAX_FACTOR)); panel.add(reset.setup("reset")); // - dmx panel.add(enableDmx.set("enableDmx", false)); for (int i = 0; i < DMX_CHANNEL_NUMBER; i++) { panel.add(dmxChannels[i].set("DMX Channel "+ofToString(i+1), 127, 0, 255)); } // - light panel.add(lightSpecularColor.set("lightSpecularColor", ofFloatColor::red, ofFloatColor::black, ofFloatColor::white)); panel.add(lightDissuseColor.set("lightDiffuseColor", ofFloatColor::green, ofFloatColor::black, ofFloatColor::white)); panel.add(lightAmbientColor.set("lightAmbientColor", ofFloatColor::blue, ofFloatColor::black, ofFloatColor::white)); panel.add(lightAttenuation.set("lightAttenuation", ofVec3f(1.0, 0.0, 0.0), ofVec3f(0.0, 0.0, 0.0), ofVec3f(5.0, 0.01, 0.0001))); panel.add(enableSmoothLighting.set("enableSmoothLighting", true)); panel.add(enableSeparateSpecularLight.set("enableSeparateSpecularLight", false)); panel.add(lightPosition.set("lightPosition", ofVec3f(kinectWidth/2.0, kinectHeight/2.0, kinect.minDistance/2.0), ofVec3f(0, 0, -kinectDepth), ofVec3f(kinectWidth, kinectHeight, kinectDepth))); // - material panel.add(materialSpecularColor.set("materialSpecularColor", ofFloatColor::red, ofFloatColor::black, ofFloatColor::white)); panel.add(materialDiffuseColor.set("materialDiffuseColor", ofFloatColor::green, ofFloatColor::black, ofFloatColor::white)); panel.add(materialAmbientColor.set("materialAmbientColor", ofFloatColor::blue, ofFloatColor::black, ofFloatColor::white)); panel.add(materialEmissiveColor.set("materialEmissiveColor", ofFloatColor::black, ofFloatColor::black, ofFloatColor::white)); panel.add(materialShininess.set("materialShininess", 64, 0, 128)); // camera panel.add(cameraFov.set("cameraFov", 60, 1, 180)); panel.add(cameraNearDist.set("cameraNearDist", 6.65107, 0, 100)); panel.add(cameraFarDist.set("cameraFarDist", 6651.07, 0, kinectDepth)); panel.add(cameraPosition.set("cameraPosition", ofVec3f(kinectWidth/2.0, kinectHeight/2.0, 0), ofVec3f(0, 0, -kinectDepth), ofVec3f(kinectWidth, kinectHeight, kinectDepth))); panel.add(cameraLookAt.set("cameraLookAt", ofVec3f(kinectWidth/2.0, kinectHeight/2.0, kinect.minDistance), ofVec3f(0, 0, -kinectDepth), ofVec3f(kinectWidth, kinectHeight, kinectDepth))); // world panel.add(modelStartPosition.set("modelStartPosition", ofVec3f(cameraPosition), cameraPosition.getMin(), cameraPosition.getMax())); panel.add(worldGravity.set("worldGravity", ofVec3f(0, 0, 15.0), ofVec3f(-100, -100, -100), ofVec3f(30, 30, 30))); panel.add(modelMass.set("modelMass", 0.000005, 0.000005, 1)); // 1 is 1 kg panel.add(enableAddModel.set("enableAddModel", false)); panel.add(enableAddModelRandom.set("enableAddModelRandom", false)); // load saved settings data panel.loadFromFile("settings.xml"); // minimize all guis panel.minimizeAll(); // dmx dmx.connect("tty.usbserial-ENY46L4I"); // use the name //dmx.connect(0); // or use a number // caemera camera.setAutoDistance(false); if (!enableMouseInput) camera.disableMouseInput(); camera.setPosition(cameraPosition); ofVec3f upVector(0, -1, 0); camera.lookAt(ofVec3f(cameraLookAt), upVector); // bullet world.setup(); world.enableGrabbing(); world.setCamera(&camera); world.setGravity(worldGravity); // model // assimpModelLoaders // - sakura assimpModelLoaders[0].loadModel("models/sakura/sakura2/sakura2.3ds", true); assimpModelLoaders[0].setPosition(ofGetWidth()/2, ofGetHeight()/2, 0); assimpModelLoaders[0].setScale(1.0, 1.0, 1.0); // - bitcoin assimpModelLoaders[1].loadModel("models/bitcoin/bitcoin4/bitcoin_v02.3ds", true); assimpModelLoaders[1].setPosition(ofGetWidth()/2, ofGetHeight()/2, 0); assimpModelLoaders[1].setScale(1.0, 1.0, 1.0); // - dna assimpModelLoaders[2].loadModel("models/dna/dna6/dna_low_green.3ds", true); assimpModelLoaders[2].setPosition(ofGetWidth()/2, ofGetHeight()/2, 0); assimpModelLoaders[2].setScale(2.0, 2.0, 2.0); // - dgcoin assimpModelLoaders[3].loadModel("models/bitcoin/bitcoin6/DGbitcoin_low_blue_0_180_235.3ds", true); assimpModelLoaders[3].setPosition(ofGetWidth()/2, ofGetHeight()/2, 0); assimpModelLoaders[3].setScale(2.0, 2.0, 2.0); // - maple assimpModelLoaders[4].loadModel("models/maple/maple1/maple_orange.3ds", true); assimpModelLoaders[4].setPosition(ofGetWidth()/2, ofGetHeight()/2, 0); assimpModelLoaders[4].setScale(0.65, 0.65, 0.65); // modelSetVector modelSetVector.resize(4); // - sakura modelSetVector[0].push_back(0); // - bitcoin & dgcoin modelSetVector[1].push_back(1); modelSetVector[1].push_back(3); // - dna modelSetVector[2].push_back(2); // - maple modelSetVector[3].push_back(4); // referenceAssimpModelBulletShapes ofQuaternion startRot = ofQuaternion(1., 0., 0., PI); for (int i = 0; i < MODEL_NUMBER; i++) { for (int j = 0; j < assimpModelLoaders[i].getNumMeshes(); j++) { referenceAssimpModelBulletShapes[i] = new ofxBulletCustomShape; referenceAssimpModelBulletShapes[i]->addMesh(assimpModelLoaders[i].getMesh(j), assimpModelLoaders[i].getScale(), true); ofVec3f startLoc = ofVec3f( ofRandom(-5, 5), ofRandom(0, -10), ofRandom(-5, 5) ); referenceAssimpModelBulletShapes[i]->create(world.world, startLoc, startRot, 3.); referenceAssimpModelBulletShapes[i]->add(); } } currentModelSetId = 0; // light light.setSpecularColor(lightSpecularColor); light.setDiffuseColor(lightDissuseColor); light.setAmbientColor(lightAmbientColor); light.setAttenuation(lightAttenuation->x, lightAttenuation->y, lightAttenuation->z); ofSetSmoothLighting(enableSmoothLighting); light.setPosition(lightPosition); light.setPointLight(); // timer timer.setName("play"); timer.setTime(MODEL_PLAY_SECONDS*1000, 1); timer.start(); // debug ofSetVerticalSync(false); ofSetFrameRate(0); // - camera target debugSphereCameraTarget.set(10, 3); // - debug spheres float debugSphereRadius = 5; int debugSphereResolution = 3; float samplingNumber = 100; ofVec3f debugSphereNumber(kinectWidth/samplingNumber, kinectHeight/samplingNumber, kinectDepth/samplingNumber); ofVec3f gapBetweenSpheres(kinectWidth/debugSphereNumber.x, kinectHeight/debugSphereNumber.y, kinectDepth/debugSphereNumber.z); for (int x = 0; x < debugSphereNumber.x; x++) { for (int y = 0; y < debugSphereNumber.y; y++) { for (int z = 0; z < debugSphereNumber.z; z++) { ofSpherePrimitive instantSphere; instantSphere.set(debugSphereRadius, debugSphereResolution); instantSphere.setPosition(x*gapBetweenSpheres.x, y*gapBetweenSpheres.y, z*gapBetweenSpheres.z); debugSpheres.push_back(instantSphere); } } } }
//-------------------------------------------------------------- void testApp::update(){ ofSoundUpdate(); //SpaceShip if(shipMoveForward){ shipForce+=0.001; if(shipForce>=0.05){ shipForce=0.05; } } if(shipMoveBack){ shipForce-=0.001; if(shipForce<=0.002){ shipForce=-0.002; } } if (shipRotateLeft) { shipAngle+=3; } if (shipRotateRight) { shipAngle-=3; } shipFrcX= cos(ofDegToRad(shipAngle))*shipForce; shipFrcY= sin(ofDegToRad(shipAngle))*shipForce; ship.alpha = shipForce; ship.angle = shipAngle; ship.resetForce(); ship.addForce(shipFrcX, shipFrcY); ship.addDampingForce(); ship.moveOffWalls(); ship.update(); orginPos.x += ship.vel.x; orginPos.y += ship.vel.y; ship._posx = orginPos.x; ship._posy = orginPos.y; ship.bounceOffWalls(); cout<<ship.vel<<endl; //Goal for (int i = 0; i < goals.size(); i++){ goals[i]->resetForce(); goals[i]->addForce(0, 0); goals[i]->addDampingForce(); goals[i]->update(); goals[i]->pos-=ship.vel*2; ofPoint terminal; terminal = goals[i]->pos-ship.pos; if (terminal.length()<30) { score+=1; // goals[i]->setInitialCondition(ofRandom(-ofGetWidth(),ofGetWidth()*2),ofRandom(-ofGetWidth(), ofGetWidth()*2),0,0); goals.erase(goals.begin()+i); shipRadiance+=10; if(shipRadiance>=300){ shipRadiance=300; } } } //bg bgPos-=ship.vel/4; // particle sort( myParticles.begin(), myParticles.end(), comparisonFunction ); // sort them! for (int i = 0; i < myParticles.size(); i++){ myParticles[i]->resetForce(); myParticles[i]->radius = shipRadiance; } for (int i = 0; i < myParticles.size(); i++){ for (int j = i-1; j >= 0; j--){ if ( fabs(myParticles[j]->pos.x - myParticles[i]->pos.x) > 30) break; float speed; speed = ofMap(myParticles[i]->scale, 0, myParticles[i]->scale+myParticles[j]->scale, 0, 2.4f); myParticles[i]->addRepulsionForce( *myParticles[j],20,speed); } } for (int i = 0; i < myParticles.size(); i++){ for (int j = 0; j < goals.size(); j++){ myParticles[i]->addRepulsionForce(goals[j]->pos.x,goals[j]->pos.y,70,0.02f); } } float diffTime2 = ofGetElapsedTimeMillis()- firstTime; for (int i = 0; i < myParticles.size(); i++){ myParticles[i]->addForce(0,0); myParticles[i]->addAttractionForce(ship.pos.x,ship.pos.y,shipRadiance*myParticles[i]->scale,0.02f/myParticles[i]->scale); if (diffTime2<1000) { myParticles[i]->addRepulsionForce(ship.pos.x, ship.pos.y, 200, 0.2f); } myParticles[i]->addDampingForce(); myParticles[i]->update(); myParticles[i]->pos.x-=ship.vel.x*2; myParticles[i]->pos.y-=ship.vel.y*2; ofPoint dis; dis = ship.pos - myParticles[i]->pos; if (dis.length()<23+(myParticles[i]->asteroid->width/6*myParticles[i]->scale)) { orginPos.set(0, 0); shipExplode = true; ship.setInitialCondition(ofGetWidth()/2, ofGetHeight()/2, 0, 0); firstTime = ofGetElapsedTimeMillis(); score =0; shipRadiance = 30; myParticles.clear(); for (int i = 0; i < 200; i++){ float scale = ofRandom(1,3); particle * p = new particle(); myParticles.push_back(p); myParticles[i]->pos.set(ofRandom(-ofGetWidth(),ofGetWidth()*2),ofRandom(-ofGetWidth(),ofGetWidth()*2)); myParticles[i]->vel.set(0,0); myParticles[i]->asteroid =& asteroid; myParticles[i]->scale = scale; } goals.clear(); for (int i = 0; i < 30; i++){ particle * p = new particle(); goals.push_back(p); goals[i]->drawWhat =2; goals[i]->setInitialCondition(ofRandom(-ofGetWidth()*0.8,ofGetWidth()*2*0.8),ofRandom(-ofGetWidth()*0.8, ofGetWidth()*2)*0.8,0,0); goals[i]->vel.set(0,0); goals[i]->saver = & xiaoren[ofRandom(0,2)]; } bgPos.set(0, 0); shield =3; } } }
void MediaPlayer::shuffleFrame(){ if (shuffleFrames == true){ groups[groupIndex]->media[mediaIndex]->setPosition(ofRandom(0,1)); } }
//-------------------------------------------------------------- void ofApp::setup(){ ofSetFrameRate(60); ofSetVerticalSync(true); cam.setupPerspective(true,60,0.1,2000); vtfShader.load("shaders/vtf.vert","shaders/render.frag"); light1.setPointLight(); light1.setAmbientColor(ofFloatColor(0.3,0.3,0.3,1.0)); light1.setDiffuseColor(ofFloatColor(0.6,0.6,0.6,1.0)); light1.setSpecularColor(ofFloatColor(1.0,1.0,1.0,1.0)); light1.setPosition(500, -500, 500); ofBoxPrimitive b; b.set(1, 1, 1, 1, 1, 1); object = b.getMesh(); textureRes = NUM_OBJECTS_SQRT; target.set(0,0,0); lookAtSphere=false; for(int i=0;i<textureRes;i++){ for(int j=0;j<textureRes;j++){ size[i][j].set(10,ofRandom(10,150),10); float x = ofMap(i,0,textureRes,-500,500); float y = 100-size[i][j].y/2; float z = ofMap(j,0,textureRes,-500,500); pos[i][j].set(x,y,z); hue[i][j] = ofRandom(0.3,0.6); color[i][j].setHsb(hue[i][j], 0.8, 1); } } float posArray[textureRes*textureRes*3]; float sizeArray[textureRes*textureRes*3]; float rotArray[textureRes*textureRes*4]; float colorArray[textureRes*textureRes*4]; for (int x = 0; x < textureRes; x++){ for (int y = 0; y < textureRes; y++){ int i = textureRes * y + x; posArray[i*3 + 0] = pos[x][y].x; posArray[i*3 + 1] = pos[x][y].y; posArray[i*3 + 2] = pos[x][y].z; sizeArray[i*3 + 0] = size[x][y].x; sizeArray[i*3 + 1] = size[x][y].y; sizeArray[i*3 + 2] = size[x][y].z; rotArray[i*4 + 0] = 0; rotArray[i*4 + 1] = 0; rotArray[i*4 + 2] = 0; rotArray[i*4 + 3] = 1; colorArray[i*4 + 0] = color[x][y].r; colorArray[i*4 + 1] = color[x][y].g; colorArray[i*4 + 2] = color[x][y].b; colorArray[i*4 + 3] = 1; } } posTex.allocate(textureRes, textureRes, GL_RGB32F); posTex.loadData(posArray, textureRes, textureRes, GL_RGB); sizeTex.allocate(textureRes, textureRes, GL_RGB32F); sizeTex.loadData(sizeArray, textureRes, textureRes, GL_RGB); rotTex.allocate(textureRes, textureRes, GL_RGBA32F); rotTex.loadData(rotArray, textureRes, textureRes, GL_RGBA); colorTex.allocate(textureRes, textureRes, GL_RGBA32F); colorTex.loadData(colorArray, textureRes, textureRes, GL_RGBA); }