void ofxCircOSC::isOnDrawInfo(int xMouse,int yMouse,int x, int y){//init in Draw with mousePos values //This func shows the an info particle if the mouse is on if(ofDist(X,Y,xMouse,yMouse)<tamano)myfont.drawString(nombre, x,y); }
// Update & draw void Faces::update() { if (isThereMbodybool){ b2Vec2 bodyPos = mBody->GetPosition(); // cout << "bodypos: x: " << bodyPos.x << " y: " << bodyPos.y << endl; // cout << "bodypos: x: " << _toPixelX(bodyPos.x) << " y: " << _toPixelY(bodyPos.y) << endl; ofVec2f curPoint = ofVec2f(mVertice[curSection].x, mVertice[curSection].y); ofVec2f nextPoint = ofVec2f( mVertice[curSection].x + (addDist[curSection].x * rotSpd * (curPointofSection + 1)), mVertice[curSection].y + (addDist[curSection].y * rotSpd * (curPointofSection + 1))); float distBetweenPoint = ofDist(curPoint.x, curPoint.y, nextPoint.x, nextPoint.y); if (distBetweenPoint < dists[curSection]){ // ofxOscMessage m; // m.setAddress("/fromOF_pBody"); // m.addIntArg(index); // m.addFloatArg(bodyPos.x * BOX2D_SCALE + nextPoint.x); // m.addFloatArg(bodyPos.y * BOX2D_SCALE + nextPoint.y); // sender.sendMessage(m); ofPushStyle(); ofSetColor(10, 200, 100); ofFill(); ofPushMatrix(); ofTranslate(bodyPos.x * BOX2D_SCALE, bodyPos.y * BOX2D_SCALE * (-1)); ofSetColor(20, 200, 150); ofCircle(nextPoint.x, nextPoint.y, outliner_rad); // Outline vector<ofPoint> lines; for (int i = 0; i < curSection + 1; i++){ ofPoint point = ofPoint(mVertice[i].x, mVertice[i].y); lines.push_back(point); } ofPolyline outline(lines); ofSetLineWidth(2.f); outline.draw(); ofLine(curPoint.x, curPoint.y, nextPoint.x, nextPoint.y); ofPopMatrix(); ofPopStyle(); curPointofSection++; // cout << "curPointofSection: " << curPointofSection << endl; }else{ curSection++; // cout << "curSection: " << curSection << endl; if (curSection == (kMAX_VERTICES - 1) ) { curSection = 0; } curPointofSection = 0; } } }
// --------------------------------------- void miniaturas::creaGrid(ofColor _color) { /////// arreglo de Patricio /////// thanks !!!!! int cuantas = thumbs.size(); int numColumnas = 9; // Crear una tabla de punteros donde re organizar los elementos // vector< vector<thumb*> > tabla; for (int i = 0; i < numColumnas; i++ ) { vector<thumb*> newColum; tabla.push_back(newColum); } int anchoMini = 49; int altoMini = 49; // Posicionar los elementos y popular los punteros en la tabla // int col = 0; int row = 0; for (int i = 0; i < cuantas; i++) { col = i % numColumnas; row = i / numColumnas; // Ponerlo en la tabla // tabla[col].push_back( thumbs[i] ); // Ubicarlo en el espacio // thumbs[i]->x = origen.x -( (anchoMini + 10) * col); // las colocamos de izda a derecha thumbs[i]->y = origen.y + ( (altoMini + 10) * row); // los movemos al origen, deberias de hacerlo en el de antes thumbs[i]->color.set(_color.r, _color.g, _color.b); thumbs[i]->cambiate(_color.r, _color.g, _color.b, 0.1*i); } // Ahora que esta en la tabla podemos recorrerlo de forma más sencilla // for (int x = 0; x < numColumnas; x++) { // Spring Verticales // for( int y = 0; y < tabla[x].size(); y++) { // A [ x,y ] ---- [ x+1,y ] B // / // | / // | / // // C [ x,y+1 ] [ x+1, y+1 ] D bool hayB = false; bool hayC = false; bool hayD = false; // Si A tiene un C // if ( y != tabla[x].size()-1 ) { //vertical hayC = true; Spring * sp = new Spring(); sp->k = k; sp->rectA = tabla[x][y]; //A sp->rectB = tabla[x][y+1]; //C sp->indiceA = 4; sp->indiceB = 4; sp->dist = ofDist(tabla[x][y]->getCenter().x, tabla[x][y]->getCenter().y, tabla[x][y+1]->getCenter().x, tabla[x][y+1]->getCenter().y); //sp->visible = true; springs.push_back(sp); } // Si no es la ultima columna... // if ( x < numColumnas-1 ) { // ... y tiene un elemento a la misma altura en Y // if ( y < tabla[x+1].size() ) { //horisontal hayB = true; Spring * sp = new Spring(); sp->k = k; sp->rectA = tabla[x][y]; //A sp->rectB = tabla[x+1][y]; //B sp->indiceA = 4; sp->indiceB = 4; sp->dist = ofDist(tabla[x][y]->getCenter().x, tabla[x][y]->getCenter().y, tabla[x+1][y]->getCenter().x, tabla[x+1][y]->getCenter().y); //sp->visible = true; sp->horizontal = true; springs.push_back(sp); if ( y+1 < tabla[x+1].size() ) { hayD = true; } } } // Si tiene B y C puede agregar la diagonal que le da estabilidad // if ( hayB && hayC ) { //DIAGONAL Spring * sp = new Spring(); sp->k = k; sp->rectA = tabla[x][y+1]; // C sp->rectB = tabla[x+1][y]; // B sp->indiceA = 4; sp->indiceB = 4; sp->dist = ofDist(tabla[x][y+1]->getCenter().x, tabla[x][y+1]->getCenter().y, tabla[x+1][y]->getCenter().x, tabla[x+1][y]->getCenter().y); //sp->visible = true; sp->diagonal = true; springs.push_back(sp); } if ( hayD ) { //DIAGONAL Spring * sp = new Spring(); sp->k = k; sp->rectA = tabla[x][y]; //A sp->rectB = tabla[x+1][y+1]; // D sp->indiceA = 4; sp->indiceB = 4; sp->dist = ofDist(tabla[x][y]->getCenter().x, tabla[x][y]->getCenter().y, tabla[x+1][y+1]->getCenter().x, tabla[x+1][y+1]->getCenter().y); //sp->visible = true; sp->diagonal = true; springs.push_back(sp); } } } //anclamos las miniaturas al visualizador /* p0 ---------- p1 | | | p4 | | | p3 -p5-p6-p7- p2 */ //reverse de los muelles para Spring * anclaP3 = new Spring(); anclaP3->k = k; anclaP3->rectA = thumbs[0]; // D anclaP3->rectB = anclaVisualizador; anclaP3->indiceA = 4; anclaP3->indiceB = 15; anclaP3->visible = false; anclaP3->dist = 80; springs.push_back(anclaP3); if(thumbs.size()>1) { /// si hay mas de una sigue //if(thumbs.size()>1){ Spring * anclaP5 = new Spring(); anclaP5->k = k; anclaP5->rectA = thumbs[1]; // D anclaP5->rectB = anclaVisualizador; anclaP5->indiceA = 4; anclaP5->indiceB = 14; anclaP5->visible = false; anclaP5->dist = 80; springs.push_back(anclaP5); Spring * diago0 = new Spring(); diago0->k = k; diago0->rectA = anclaVisualizador; diago0->rectB = thumbs[1]; // D diago0->indiceA = 15; diago0->indiceB = 4; diago0->visible = false; diago0->diagonal = true; diago0->dist = 100; springs.push_back(diago0); Spring * diago3 = new Spring(); diago3->k = k; diago3->rectA = anclaVisualizador; diago3->rectB = thumbs[1]; // D diago3->indiceA = 13; diago3->indiceB = 4; diago3->visible = false; diago3->diagonal = true; diago3->dist = 100; springs.push_back(diago3); //} if(thumbs.size()>2) { Spring * anclaP6 = new Spring(); anclaP6->k = k; anclaP6->rectA = thumbs[2]; // D anclaP6->rectB = anclaVisualizador; anclaP6->indiceA = 4; anclaP6->indiceB = 13; anclaP6->visible = false; anclaP6->dist = 80; springs.push_back(anclaP6); Spring * diago2 = new Spring(); diago2->k = k; diago2->rectA = anclaVisualizador; diago2->rectB = thumbs[2]; // D diago2->indiceA = 14; diago2->indiceB = 4; diago2->visible = false; diago2->diagonal = true; diago2->dist = 100; springs.push_back(diago2); Spring * diago5 = new Spring(); diago5->k = k; diago5->rectA = anclaVisualizador; diago5->rectB = thumbs[2]; // D diago5->indiceA = 12; diago5->indiceB = 4; diago5->visible = false; diago5->diagonal = true; diago5->dist = 100; springs.push_back(diago5); } if(thumbs.size()>3) { Spring * anclaP7 = new Spring(); anclaP7->k = k; anclaP7->rectA = thumbs[3]; // D anclaP7->rectB = anclaVisualizador; anclaP7->indiceA = 4; anclaP7->indiceB = 12; anclaP7->visible = false; anclaP7->dist = 80; springs.push_back(anclaP7); Spring * diago4 = new Spring(); diago4->k = k; diago4->rectA = anclaVisualizador; diago4->rectB = thumbs[3]; // D diago4->indiceA = 13; diago4->indiceB = 4; diago4->visible = false; diago4->diagonal = true; diago4->dist = 100; springs.push_back(diago4); Spring * diago7 = new Spring(); diago7->k = k; diago7->rectA = anclaVisualizador; diago7->rectB = thumbs[3]; // D diago7->indiceA = 2; diago7->indiceB = 4; diago7->diagonal = true; diago7->visible = false; diago7->dist = 100; springs.push_back(diago7); } if(thumbs.size()>4) { Spring * diago6 = new Spring(); diago6->k = k; diago6->rectA = anclaVisualizador; diago6->rectB = thumbs[4]; // D diago6->indiceA = 12; diago6->indiceB = 4; diago6->visible = false; diago6->diagonal = true; diago6->dist = 100; springs.push_back(diago6); //} //if(thumbs.size()>4){ Spring * anclaP2 = new Spring(); anclaP2->k = k; anclaP2->rectA = thumbs[4]; // D anclaP2->rectB = anclaVisualizador; anclaP2->indiceA = 4; anclaP2->indiceB = 2; anclaP2->visible = false; anclaP2->dist = 80; springs.push_back(anclaP2); } if(thumbs.size()>5) { Spring * diago6 = new Spring(); diago6->k = k; diago6->rectA = anclaVisualizador; diago6->rectB = thumbs[5]; // D diago6->indiceA = 2; diago6->indiceB = 4; diago6->visible = false; diago6->diagonal = true; diago6->dist = 100; springs.push_back(diago6); //} //if(thumbs.size()>4){ Spring * anclaP2 = new Spring(); anclaP2->k = k; anclaP2->rectA = thumbs[5]; // D anclaP2->rectB = anclaVisualizador; anclaP2->indiceA = 4; anclaP2->indiceB = 7; anclaP2->visible = false; anclaP2->dist = 80; springs.push_back(anclaP2); } if(thumbs.size()>6) { Spring * diago6 = new Spring(); diago6->k = k; diago6->rectA = anclaVisualizador; diago6->rectB = thumbs[6]; // D diago6->indiceA = 7; diago6->indiceB = 4; diago6->visible = false; diago6->diagonal = true; diago6->dist = 100; springs.push_back(diago6); //} //if(thumbs.size()>4){ Spring * anclaP2 = new Spring(); anclaP2->k = k; anclaP2->rectA = thumbs[6]; // D anclaP2->rectB = anclaVisualizador; anclaP2->indiceA = 4; anclaP2->indiceB = 6; anclaP2->visible = false; anclaP2->dist = 80; springs.push_back(anclaP2); } if(thumbs.size()>7) { Spring * diago6 = new Spring(); diago6->k = k; diago6->rectA = anclaVisualizador; diago6->rectB = thumbs[7]; // D diago6->indiceA = 6; diago6->indiceB = 4; diago6->visible = false; diago6->diagonal = true; diago6->dist = 100; springs.push_back(diago6); //} //if(thumbs.size()>4){ Spring * anclaP2 = new Spring(); anclaP2->k = k; anclaP2->rectA = thumbs[7]; // D anclaP2->rectB = anclaVisualizador; anclaP2->indiceA = 4; anclaP2->indiceB = 5; anclaP2->visible = false; anclaP2->dist = 80; springs.push_back(anclaP2); } if(thumbs.size()>8) { Spring * diago6 = new Spring(); diago6->k = k; diago6->rectA = anclaVisualizador; diago6->rectB = thumbs[8]; // D diago6->indiceA = 5; diago6->indiceB = 4; diago6->visible = false; diago6->diagonal = true; diago6->dist = 100; springs.push_back(diago6); //} //if(thumbs.size()>4){ Spring * anclaP2 = new Spring(); anclaP2->k = k; anclaP2->rectA = thumbs[8]; // D anclaP2->rectB = anclaVisualizador; anclaP2->indiceA = 4; anclaP2->indiceB = 3; anclaP2->visible = false; anclaP2->dist = 80; springs.push_back(anclaP2); } } Spring * diago1 = new Spring(); diago1->k = k; diago1->rectA = anclaVisualizador; diago1->rectB = thumbs[0]; // D diago1->indiceA = 14; diago1->indiceB = 4; diago1->visible = false; diago1->diagonal = true; diago1->dist = 100; springs.push_back(diago1); /* Spring * anclaP3 = new Spring(); anclaP3->k = k; anclaP3->rectA = thumbs[0]; // D anclaP3->rectB = anclaVisualizador; anclaP3->indiceA = 4; anclaP3->indiceB = 3; anclaP3->visible = false; anclaP3->dist = 80; springs.push_back(anclaP3); if(thumbs.size()>1){ /// si hay mas de una sigue //if(thumbs.size()>1){ Spring * anclaP5 = new Spring(); anclaP5->k = k; anclaP5->rectA = thumbs[1]; // D anclaP5->rectB = anclaVisualizador; anclaP5->indiceA = 4; anclaP5->indiceB = 5; anclaP5->visible = false; anclaP5->dist = 80; springs.push_back(anclaP5); Spring * diago0 = new Spring(); diago0->k = k; diago0->rectA = anclaVisualizador; diago0->rectB = thumbs[1]; // D diago0->indiceA = 3; diago0->indiceB = 4; diago0->visible = false; diago0->diagonal = true; diago0->dist = 100; springs.push_back(diago0); Spring * diago3 = new Spring(); diago3->k = k; diago3->rectA = anclaVisualizador; diago3->rectB = thumbs[1]; // D diago3->indiceA = 6; diago3->indiceB = 4; diago3->visible = false; diago3->diagonal = true; diago3->dist = 100; springs.push_back(diago3); //} if(thumbs.size()>2){ Spring * anclaP6 = new Spring(); anclaP6->k = k; anclaP6->rectA = thumbs[2]; // D anclaP6->rectB = anclaVisualizador; anclaP6->indiceA = 4; anclaP6->indiceB = 6; anclaP6->visible = false; anclaP6->dist = 80; springs.push_back(anclaP6); Spring * diago2 = new Spring(); diago2->k = k; diago2->rectA = anclaVisualizador; diago2->rectB = thumbs[2]; // D diago2->indiceA = 5; diago2->indiceB = 4; diago2->visible = false; diago2->diagonal = true; diago2->dist = 100; springs.push_back(diago2); Spring * diago5 = new Spring(); diago5->k = k; diago5->rectA = anclaVisualizador; diago5->rectB = thumbs[2]; // D diago5->indiceA = 7; diago5->indiceB = 4; diago5->visible = false; diago5->diagonal = true; diago5->dist = 100; springs.push_back(diago5); } if(thumbs.size()>3){ Spring * anclaP7 = new Spring(); anclaP7->k = k; anclaP7->rectA = thumbs[3]; // D anclaP7->rectB = anclaVisualizador; anclaP7->indiceA = 4; anclaP7->indiceB = 7; anclaP7->visible = false; anclaP7->dist = 80; springs.push_back(anclaP7); Spring * diago4 = new Spring(); diago4->k = k; diago4->rectA = anclaVisualizador; diago4->rectB = thumbs[3]; // D diago4->indiceA = 6; diago4->indiceB = 4; diago4->visible = false; diago4->diagonal = true; diago4->dist = 100; springs.push_back(diago4); Spring * diago7 = new Spring(); diago7->k = k; diago7->rectA = anclaVisualizador; diago7->rectB = thumbs[3]; // D diago7->indiceA = 2; diago7->indiceB = 4; diago7->diagonal = true; diago7->visible = false; diago7->dist = 100; springs.push_back(diago7); } if(thumbs.size()>4){ Spring * diago6 = new Spring(); diago6->k = k; diago6->rectA = anclaVisualizador; diago6->rectB = thumbs[4]; // D diago6->indiceA = 7; diago6->indiceB = 4; diago6->visible = false; diago6->diagonal = true; diago6->dist = 100; springs.push_back(diago6); //} //if(thumbs.size()>4){ Spring * anclaP2 = new Spring(); anclaP2->k = k; anclaP2->rectA = thumbs[4]; // D anclaP2->rectB = anclaVisualizador; anclaP2->indiceA = 4; anclaP2->indiceB = 2; anclaP2->visible = false; anclaP2->dist = 80; springs.push_back(anclaP2); } } Spring * diago1 = new Spring(); diago1->k = k; diago1->rectA = anclaVisualizador; diago1->rectB = thumbs[0]; // D diago1->indiceA = 5; diago1->indiceB = 4; diago1->visible = false; diago1->diagonal = true; diago1->dist = 100; springs.push_back(diago1); */ /// /// PONGO LA TENSION UNA VEZ COLOCADOS LOS MUELLES cambiaKDiagonal(_kMuellesDiagonales); cambiaKHorizontal(_kHorizontal); cambiaK(_kmuelles); cambiaDampMiniaturas(_dampCajasMiniaturas); /// marcas la primera como activa thumbs[0]->activala(); // cargas la url de la primera thumb en el visualizador switch (lenguaje) { case IDIOMA_CAST: anclaVisualizador->ponTexto(titular_cast_mini[0], pies_cast_cuerpo_mini[0], txt_cast_mini[0]); //anclaVisualizador->ponTexto(pies_cast_titular_mini[0], pies_cast_cuerpo_mini[0], txt_cast_mini[0]); break; case IDIOMA_GAL: anclaVisualizador->ponTexto(titular_gal_mini[0], pies_gal_cuerpo_mini[0], txt_gal_mini[0]); //anclaVisualizador->ponTexto(pies_gal_titular_mini[0], pies_gal_cuerpo_mini[0], txt_gal_mini[0]); break; case IDIOMA_ENG: anclaVisualizador->ponTexto(titular_eng_mini[0], pies_eng_cuerpo_mini[0], txt_eng_mini[0]); //anclaVisualizador->ponTexto(pies_eng_titular_mini[0], pies_eng_cuerpo_mini[0], txt_eng_mini[0]); break; case IDIOMA_FR: anclaVisualizador->ponTexto(titular_fr_mini[0], pies_fr_cuerpo_mini[0], txt_fr_mini[0]); //anclaVisualizador->ponTexto(pies_fr_titular_mini[0], pies_fr_cuerpo_mini[0], txt_fr_mini[0]); break; default: break; } anclaVisualizador->cargaImagen(urls_mini.at(0)); }
bool kUsersApp::analyseUser( ofxOpenNIUser * user ) { if ( !testUser( user ) ) return false; ofMesh & mesh = user->getPointCloud(); vector< ofVec3f > & vertices = mesh.getVertices(); bb.min.set( 0,0,0 ); bb.max.set( 0,0,0 ); bb.center.set( 0,0,0 ); vector< ofVec3f >::iterator itv; for ( itv = vertices.begin(); itv != vertices.end(); itv++ ) { ofVec3f & v = (*itv); bb.center += v; if ( itv == vertices.begin() ) { bb.min.set( v ); bb.max.set( v ); continue; } if ( v.x < bb.min.x ) bb.min.x = v.x; if ( v.y < bb.min.y ) bb.min.y = v.y; if ( v.z < bb.min.z ) bb.min.z = v.z; if ( v.x > bb.max.x ) bb.max.x = v.x; if ( v.y > bb.max.y ) bb.max.y = v.y; if ( v.z > bb.max.z ) bb.max.z = v.z; } bb.center /= vertices.size(); if ( ofDist( -rep.pos.x, rep.pos.z, bb.center.x, bb.center.z ) < rep.radius ) { bb.inside = true; if ( bb.current != user ) bb.starttime = ofGetElapsedTimeMillis(); bb.current = user; return true; } // resetting bounding box bb.current = NULL; bb.inside = false; bb.starttime = 0; bb.size = 0; return false; }
float wlaBullet::getDistanceBetweenShipAndBullet() const { return ofDist(tempStartPosition.x,tempStartPosition.y, position.x, position.y); }
void JTLine::step(){ x2 += (dest_x2 - x2) * 0.1; y2 += (dest_y2 - y2) * 0.1; ballPosition = ((ticks % ballSpeed) / (float)ballSpeed); //find sufficient extender length float hyp = ofDist(ofGetScreenWidth(),ofGetScreenHeight(),0,0); //get angles in both directions float theta1 = atan2(y-y2,x-x2); float theta2 = atan2(y2-y,x2-x); //define rendering segment x3 = x + cos(theta2) * hyp; y3 = y + sin(theta2) * hyp; x4 = x2 + cos(theta1) * hyp; y4 = y2 + sin(theta1) * hyp; //find ball position based on time ballX = x3 + (x4-x3) * ballPosition; ballY = y3 + (y4-y3) * ballPosition; //update math calculations slope = (y4 - y3) / (x4 - x3); elevation = y4 - slope * x4; vector<JTLine*>::iterator it; float screenW = ofGetScreenWidth(); float screenH = ofGetScreenHeight(); for(it = SceneLines::instance->lines.begin(); it != SceneLines::instance->lines.end() ; it ++ ){ if( (*it) != this){ if(ballX > 0 && ballX < screenW && ballY > 0 && ballY < screenH ){ bool side = (*it)->pointAbove(ballX,ballY); if(sides[*it] == 2 ){ if(side){ sides[*it] = 3; radius += 20; (*it)->crossed(); sound(); } }else{ if(!side){ sides[*it] = 2; radius += 20; (*it)->crossed(); sound(); } } }else{ sides[*it] = 2; } } } pluckCounter = max(0,pluckCounter-1); radius = fmin(fmax(lineWidth, radius-5),50); ticks++; }
void Vehicle::follow(Path & p){ radius = p.radius; // Predict location 25 (arbitrary choice) frames ahead ofVec2f predict(velocity); predict.normalize(); predict *= 25; predictLoc = location + predict; worldRecord = 1000000; // Loop through all points of the path for (unsigned int i = 0; i < p.points.size()-1; i++) { // Look at a line segment ofVec2f a(p.points[i]); ofVec2f b(p.points[i+1]); // Get the normal point to that line ofVec2f normalPoint = getNormalPoint(predictLoc, a, b); if (normalPoint.x <= a.x || normalPoint.x >= b.x) { // This is something of a hacky solution, but if it's not within the line segment // consider the normal to just be the end of the line segment (point b) normalPoint.set(b.x, b.y); } // How far away are we from the path? float distance = ofDist(predictLoc.x, predictLoc.y, normalPoint.x, normalPoint.y); if (distance < worldRecord) { worldRecord = distance; normal = normalPoint; ofVec2f dir = b - a; dir.normalize(); dir *= 10; // This could be based on velocity instead of just an arbitrary 10 pixels target.set(normalPoint); target += dir; } } if (worldRecord > p.radius) { seek(target); } cout << target.x << endl; }
//-------------------------------------------------------------- void shadow::drawBackShadow(ofVec2f posLight, float shadowSpread){ pos.set(posLight); //ofClear(255); //ofBackgroundGradient(ofColor(255, 0, 0), ofColor(0, 0, 255), OF_GRADIENT_LINEAR); ofEnableAlphaBlending(); ofSetColor(255, 255, 255); fbo.begin(); ofClear(255); //ofClear(255); ofBackground(255, 255, 255); //cam2.begin(); for (int i = 0; i < pathsShaderBackS.size();i++) { // for (int j = 0; j < pathsShaderS[i].size();j++) {[j] vector<ofPolyline>poly= pathsShaderBackS[i].getOutline(); ofVec2f pathCenter(0,0); for (int k = 0;k < poly.size();k++) { pathCenter += poly[k].getCentroid2D(); } pathCenter.x = pathCenter.x / poly.size(); pathCenter.y = pathCenter.y / poly.size(); float distanceToLight = ofDist(pos.x, pos.y, pathCenter.x, pathCenter.y); ofVec2f pushFromOrigin = pos - pathCenter ; pushFromOrigin.normalize(); pushFromOrigin.scale(-1); pushFromOrigin.scale(ofMap(distanceToLight, 0, 1400,0 , shadowSpread, true)); //pushFromOrigin.x = ofMap(distanceToLight, -1.0, 1.0, 100, 0, true); //pushFromOrigin.y = ofMap(distanceToLight, -1.0, 1.0, 100, 0, true); //ofColor tCol=pathsShader[i][j].getFillColor();[j][j] //pathsShaderBackS[i].setColor(ofColor(0, 0, 0)); ofPushMatrix(); ofTranslate(pushFromOrigin.x, pushFromOrigin.y, 0);//zPosition[i] pathsShaderBackS[i].draw(); ofPopMatrix(); // pathsShaderS[i][j].setColor(tCol); //} } //shader.end(); //cam2.end(); fbo.end(); ofSetColor(255, 255, 255); //fbo.begin(); //ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight()); //fbo.draw(0, 0); //fbo.end(); blurHShader.begin(); blurHShader.setUniformTexture("blurSampler", fbo.getTextureReference(0),0); blurHShader.setUniform1f("sigma",blurFactor); blurHShader.setUniform1f("blurSize", texelSize); //blurHShader.setUniform2f("posLight", pos.x, ofMap(pos.y, 0, ofGetHeight(), ofGetHeight(), 0)); blurHShader.setUniform2f("posLight", pos.x, pos.y);//ofMap(pos.y, 0, ofGetHeight(), ofGetHeight(), 0));//; blurHShader.setUniform2f("resolution", ofGetWidth(),ofGetHeight()); blurVShader.begin(); blurVShader.setUniformTexture("blurSampler", fbo.getTextureReference(0), 0); blurVShader.setUniform1f("sigma", blurFactor); blurVShader.setUniform1f("blurSize", texelSize); //blurVShader.setUniform2f("posLight", pos.x, ofMap(pos.y, 0, ofGetHeight(), ofGetHeight(), 0));//;pos.y blurHShader.setUniform2f("posLight", pos.x, pos.y); blurVShader.setUniform2f("resolution", ofGetWidth(), ofGetHeight()); ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight()); fbo.draw(0, 0); blurVShader.end(); blurHShader.end(); /* cam2.begin(); for (int i = 0; i < pathsShader.size();i++) { ofPushMatrix(); ofTranslate(0, 0, zPosition[i]);// for (int j = 0; j < pathsShader[i].size();j++) { pathsShader[i][j].draw(); } ofPopMatrix(); } cam2.end(); */ // // gui.draw(); }
//-------------------------------------------------------------- void testApp::update() { //move blue for(int i = 0; i < NUMBER_OF_BLUE; i++) { blues[i].move(); } for(int i = 0; i < NUMBER_OF_RED; i++) { reds[i].move(); } for(int i = 0; i < NUMBER_OF_GREEN; i++) { greens[i].move(); } //check for blue intersections with circles and do transactions for(int i = 0; i<NUMBER_OF_BLUE; i++) { for(int j = 0; j<NUMBER_OF_CIRCLES; j++) { float distance = ofDist(circles[j].position.x, circles[j].position.y, blues[i].position.x, blues[i].position.y); if(distance < circles[j].size && blues[i].lastTransfer != j) { if(blues[i].full == true && circles[j].color.b < 255) { circles[j].addBlue(); blues[i].full = false; blues[i].lastTransfer = j; } else if(blues[i].full == false && circles[j].color.b > 0) { circles[j].removeBlue(); blues[i].full = true; blues[i].lastTransfer = j; } } } } for(int i = 0; i<NUMBER_OF_RED; i++) { for(int j = 0; j<NUMBER_OF_CIRCLES; j++) { float distance = ofDist(circles[j].position.x, circles[j].position.y, reds[i].position.x, reds[i].position.y); if(distance < circles[j].size && reds[i].lastTransfer != j) { if(reds[i].full == true && circles[j].color.r < 255) { circles[j].addRed(); reds[i].full = false; reds[i].lastTransfer = j; } else if(reds[i].full == false && circles[j].color.r > 0) { circles[j].removeRed(); reds[i].full = true; reds[i].lastTransfer = j; } } } } for(int i = 0; i<NUMBER_OF_GREEN; i++) { for(int j = 0; j<NUMBER_OF_CIRCLES; j++) { float distance = ofDist(circles[j].position.x, circles[j].position.y, greens[i].position.x, greens[i].position.y); if(distance < circles[j].size && greens[i].lastTransfer != j) { if(greens[i].full == true && circles[j].color.g < 255) { circles[j].addGreen(); greens[i].full = false; greens[i].lastTransfer = j; } else if(greens[i].full == false && circles[j].color.g > 0) { circles[j].removeGreen(); greens[i].full = true; greens[i].lastTransfer = j; } } } } }
void ofApp::polygons(){ if (camActive) { myCam.begin(); ofPushMatrix(); ofTranslate(-ofGetWidth()/2, -ofGetHeight()/2); } /////////////////////////////////////////////////////////////////////////////////// // if drawing the lines the polygon is open if(open){ ableClick=true; // if the polygone it's open activate the click function for(int k=0;k<curveVertices.size();k++){ distance= ofDist(curveVertices[k].x, curveVertices[k].y, curveVertices[0].x, curveVertices[0].y); if(k>=0){ ofSetColor(selectedColor[0]); ofSetLineWidth(3); ofNoFill(); ofBeginShape(); //shape for (int i = 0; i < curveVertices.size(); i++){ ofVertex(curveVertices[i].x, curveVertices[i].y); } ofEndShape(false); //handle circle for (int i = 0; i < curveVertices.size(); i++){ if (curveVertices[i].bOver == true) ofFill(); else ofNoFill(); ofCircle(curveVertices[i].x, curveVertices[i].y,4); } } //checking the distance mousePos and first point if ( mouseX - curveVertices[0].x<=handlerRadius*5 && mouseY - curveVertices[0].y<=handlerRadius*5 && curveVertices[0].x - mouseX<=handlerRadius*5 && curveVertices[0].y - mouseY<=handlerRadius*5 ) { ofSetColor(0); string mouseMessage; //CLOSE MESSAGE // mouseMessage = "close the pattern"; // if (curveVertices.size()>1) { // ofDrawBitmapString(mouseMessage, mouseX-mouseMessage.length()*10,mouseY+10); // // } // handle blink for (int i=1; i<ofGetFrameNum()%40; i++) { ofNoFill(); ofSetColor(selectedColor[0],200/i+10); ofSetLineWidth(5/i); ofCircle(curveVertices[0].x,curveVertices[0].y,(i*(i+1)/100)); } } } // } if (distance>0 && distance<=handlerRadius*2) { // ofSetColor(selectedColor[0]); // ofDrawBitmapString("Press C to make " + curvedVal + " shape", 30,ofGetHeight()/2); //handles for (int i = 0; i < curveVertices.size(); i++){ if (curveVertices[i].bOver == true) ofFill(); else ofNoFill(); ofCircle(curveVertices[i].x, curveVertices[i].y,5); } ////////THIS IS THE OLD BEGIN SHAPE ofBeginShape(); for(int i=0;i<curveVertices.size();i++){ ofSetColor(selectedColor[0]); ofFill(); //curved shape if (curved) { if (i == 0){ ofCurveVertex(curveVertices[0].x, curveVertices[0].y); // we need to duplicate 0 for the curve to start at point 0 ofCurveVertex(curveVertices[0].x, curveVertices[0].y); // we need to duplicate 0 for the curve to start at point 0 } else if (i == curveVertices.size()-1){ ofCurveVertex(curveVertices[i].x, curveVertices[i].y); ofCurveVertex(curveVertices[0].x, curveVertices[0].y); // to draw a curve from pt 6 to pt 0 ofCurveVertex(curveVertices[0].x, curveVertices[0].y); // we duplicate the first point twice } else { ofCurveVertex(curveVertices[i].x, curveVertices[i].y); } }else{ //straight shape ofVertex(curveVertices[i].x,curveVertices[i].y); curved=false; } } ofEndShape(); open=false; // ableClick=false; // if the polygone it's closed deactivate the click function if (camActive) { // myCam.setTarget(ofVec3f(ofGetWidth(),ofGetHeight())); ofPopMatrix(); myCam.end(); } ///END///// } }
void PointFitter::removePointsFarFromAverage() { //check the points very far(error) from average. int startPoint = 0; vector <int> bigErrorPoints; for (int i = 0; i < nDivisionsHeight; i++) { for (int j = 0; j < nDivisionsWidth; j++) { // make average point. ofPoint tempAverage; tempAverage.x = 0; tempAverage.y = 0; for (int k = 0; k < nPtsInPoints[j+i*nDivisionsWidth]; k++) { tempAverage.x += eyePoints[k + startPoint].x; tempAverage.y += eyePoints[k + startPoint].y; } tempAverage /= nPtsInPoints[j+i*nDivisionsWidth]; // make average distance from average point float distAverage = 0; for (int k = 0; k < nPtsInPoints[j+i*nDivisionsWidth]; k++) { distAverage += ofDist(eyePoints[k + startPoint].x, eyePoints[k + startPoint].y, tempAverage.x, tempAverage.y); } distAverage /= nPtsInPoints[j+i*nDivisionsWidth]; // check distance, check if the error is big. int nErrors = 0; for (int k = 0; k < nPtsInPoints[j+i*nDivisionsWidth]; k++) { if (distAverage * 1.7 < ofDist(eyePoints[k + startPoint].x, eyePoints[k + startPoint].y, tempAverage.x, tempAverage.y)) { int temp = k + startPoint; bigErrorPoints.push_back(temp); nErrors++; } } startPoint += nPtsInPoints[j+i*nDivisionsWidth]; nPtsInPoints[j+i*nDivisionsWidth] -= nErrors; } } // remove error Points. for (int i = 0; i < bigErrorPoints.size(); i++) { //!!!: temp eyePoints.erase(eyePoints.begin() + bigErrorPoints[i] - i); screenPoints.erase(screenPoints.begin() + bigErrorPoints[i] - i); } startPoint = 0; }
//-------------------------------------------------------------- void ofApp::keyPressed(int key){ ///screen false/true if(key=='a'){ ofColor transpaColor(colorPicked.r,colorPicked.g,colorPicked.b,ofRandom(20,150)); selectedColor.clear(); selectedColor.push_back(transpaColor); ofSetBackgroundAuto(false); } //easycam if(key=='z'){ camActive=true; randomZ=ofRandom(-1000,1000); }else{ camActive=false; } // ///close path with spacebar // if(key==' '){ // if(ofFill){ // ofNoFill(); // }else{ // ofFill; // } // } ///DELETE LAST POINT if(key=='b' && curveVertices.size()>0){ open=true; curveVertices.pop_back(); myPoints.pop_back(); ableClick=true; saveXml(); //saving Xml file } //DELETE ALL if(key==OF_KEY_BACKSPACE){ curveVertices.clear(); myPoints.clear(); distance=0; open=true; ableClick=true; saveXml(); //saving Xml file } ///MAKE IT CURVE if(key=='c' && curveVertices.size()>0){ if (curved) { curved=false; curvedVal= "Curved"; } else { curved=true; curvedVal= "Straight"; } saveXml(); //saving Xml file } ///FULLSCREEN if(key=='f'){ ofToggleFullscreen(); // set fullscreen } ///TEST RANDOM if(key=='k'){ if (curved) { // ofBackground(15); ofColor randomColor(ofRandom(255), ofRandom(255),ofRandom(255),curveVertices.size()*10); selectedColor.clear(); selectedColor.push_back(randomColor); for (int i = 0; i < curveVertices.size(); i++){ curveVertices[i].x=ofRandom(ofGetWidth()); curveVertices[i].y=ofRandom(ofGetHeight()); } } else { ofColor randomColor(ofRandom(255), ofRandom(255),ofRandom(255),curveVertices.size()*10); selectedColor.clear(); selectedColor.push_back(randomColor); // ofSetBackgroundAuto(false); for (int i = 0; i < curveVertices.size(); i++){ ofPoint position(curveVertices[i].x,curveVertices[i].y); ofPoint centre(ofGetWidth()/2,ofGetHeight()/2); float dist = ofDist(position.x,position.y , centre.x,centre.y); if (stage.inside(curveVertices[i].x,curveVertices[i].y)) { directionX=ofMap(mouseX, 0, ofGetWidth(), -100, 100); directionY=ofMap(mouseY, 0, ofGetHeight(), -100, 100); curveVertices[i].x+=ofRandom(directionX); curveVertices[i].y+=ofRandom(directionY); } else { curveVertices[i].x=ofGetWidth() - curveVertices[i].x; curveVertices[i].y=ofGetHeight() - curveVertices[i].y; curveVertices[i].x+=ofRandom(directionX); curveVertices[i].y+=ofRandom(directionY); } } } saveXml(); //saving Xml file } }
//-------------------------------------------------------------- void ofApp::setup(){ sender.setup(HOST, PORT); stage.set(0, 0, ofGetWidth(), ofGetHeight()); ofSetFullscreen(true); // set fullscreen open=true; // set the polygon true at the beginning running=true; ableClick=true; // ofSetBackgroundAuto(false); ofBackground(15); //background white handlerRadius = 5; // radius of the handler of the polygon ///////////COLOR PICKER//////// //setting up the color picker float w = ofGetWidth()/6; float h = ofGetHeight()/6; float cx = w/2; float cy = h/2; img.allocate(w,h,OF_IMAGE_COLOR); for (float y=0; y<h; y++) { for (float x=0; x<w; x++) { float angle = atan2(y-cy,x-cy)+PI; float dist = ofDist(x,y,cx,cy); float hue = angle/TWO_PI*255; float sat = ofMap(dist,0,w/4,0,255,true); float bri = ofMap(dist,w/4,w/2,255,0,true); img.setColor(x,y,ofColor::fromHsb(hue,sat,bri)); } } img.reloadTexture(); ofPoint mousePos(mouseX,mouseY); colorPickerRect.set((ofGetWidth()-ofGetWidth()/6),(ofGetHeight()-ofGetHeight()/6), ofGetWidth(), ofGetHeight()); ////////////////////////////// curvedVal= "Curved"; ////////////////// fbo color picker ///////////////// // pickerFbo.allocate(w, h,GL_RGB); // // pickerFbo.begin(); // ofClear(255,255,255); // pickerFbo.end(); ofSetRectMode(OF_RECTMODE_CORNER); // img.draw(ofGetWidth()-ofGetWidth()/6,ofGetHeight()-ofGetHeight()/6); if (colorPickerRect.inside(mouseX, mouseY)) { ofPopMatrix(); ofSetRectMode(OF_RECTMODE_CENTER); ofSetColor(255,255,255,200); ofRect(mouseX+10, mouseY, 30, 30); colorPicked.set(img.getColor(mouseX-(ofGetWidth()-ofGetWidth()/6), mouseY-(ofGetHeight()-ofGetHeight()/6))); // colorPicked.set(colorPicked.r,colorPicked.g,colorPicked.b,curveVertices.size()*10); ofSetColor(colorPicked); ofRect(mouseX+10, mouseY, 20, 20); ofFill(); ofSetColor(255); ofPushMatrix(); ofDrawBitmapString(ofToString( colorPicked), 50,500); } ////////////////// end fbo color picker ///////////////// //temp coordinates for (int i = 0; i < curveVertices.size(); i++){ xt = curveVertices[i].x; yt = curveVertices[i].y; } ///////////////// maximilian////////////// /* some standard setup stuff*/ ofEnableAlphaBlending(); ofSetupScreen(); ofBackground(0, 0, 0); ofSetVerticalSync(true); /* This is stuff you always need.*/ sampleRate = 44100; /* Sampling Rate */ initialBufferSize = 512; /* Buffer Size. you have to fill this buffer with sound*/ /* Now you can put anything you would normally put in maximilian's 'setup' method in here. */ beat.load(ofToDataPath("beat2.wav")); beat.getLength(); ofSoundStreamSetup(2,0,this, sampleRate, initialBufferSize, 4);/* Call this last ! */ randomZ=0; }
//-------------------------------------------------------------- void testApp::update(){ simpleHands = leap.getSimpleHands(); leap.updateGestures(); // check for gesture updates for(int i = 0; i < simpleHands.size(); i++){ //simpleHands[i].debugDraw(); tempX = ofMap (simpleHands[i].handPos.x, -120.0, 120.0, 0, ofGetWindowWidth()); tempY = ofMap (simpleHands[i].handPos.y, 400, 100, 0, ofGetWindowHeight()); } //IMPORTANT! - tell ofxLeapMotion that the frame is no longer new. leap.markFrameAsOld(); //start sequencer update oscReceiver(); //sequencer update prevRotation = rotation; rotation += inc; hue += 1; if (rotation > 360) rotation = 0; if (rotation < 0) rotation = 360-rotation; if (hue > 255) hue = 0; ofPoint diff ; //Difference between particle and mouse float dist ; //distance from particle to mouse ( as the crow flies ) float ratio ; //Ratio of how strong the effect is = 1 + (-dist/maxDistance) ; const ofPoint mousePosition = ofPoint( tempX , tempY ) ; //Allocate and retrieve mouse values once. //Create an iterator to cycle through the vector std::vector<Particle>::iterator p ; for ( p = particles.begin() ; p != particles.end() ; p++ ) { ratio = 1.0f ; p->velocity *= friction ; //reset acceleration every frame p->acceleration = ofPoint() ; diff = mousePosition - p->position ; dist = ofDist( 0 , 0 , diff.x , diff.y ) ; //If within the zone of interaction if ( dist < forceRadius ) { ratio = -1 + dist / forceRadius ; //Repulsion if ( cursorMode == 0 ) p->acceleration -= ( diff * ratio) ; //Attraction else p->acceleration += ( diff * ratio ) ; } if ( springEnabled ) { //Move back to the original position p->acceleration.x += springFactor * (p->spawnPoint.x - p->position.x); p->acceleration.y += springFactor * (p->spawnPoint.y - p->position.y) ; } p->velocity += p->acceleration * ratio ; p->position += p->velocity ; p->defineAngleNote(); } }
void medical::draw() { // ofSetColor(0, 0, 255); // verdana.drawString("Framerate: " + ofToString(ofGetFrameRate()), 20, 50); ofDrawBitmapString(buf, 20, 50); // kinect.drawDepth(10, 10, 400, 300); // kinect.draw(420, 10, 400, 300); int x; int y; if (gestureFinder.blobs.size() == 1) { // ofSetColor(0, 0, 255); ofFill(); ofxCvBlob &blob = gestureFinder.blobs[0]; x = blob.centroid.x; y = blob.centroid.y; if (!isActivated) hoverWidget(x, y); else { if (HW_FIRST_LEG == DIRECTION_UP && HW_SECOND_LEG == DIRECTION_RIGHT) { X_STATE = x; Y_STATE = y; sender.send_stack(x, y, ZOOM, STACK); ofSetColor(255, 0, 255); } if (HW_FIRST_LEG == DIRECTION_DOWN && HW_SECOND_LEG == DIRECTION_LEFT) { sender.send_pen(sender.PEN_UNDO, x, y, 1, 1); ofSetColor(0, 255, 0); } if (HW_FIRST_LEG == DIRECTION_LEFT && HW_SECOND_LEG == DIRECTION_DOWN) { if (HW_CURRENT_DIRECTION != -1) { HW_FIRST_Y = y; HW_CURRENT_DIRECTION = -1; } int distance = y - HW_FIRST_Y; // cout << "Raw distance: " << distance << endl; distance = distance / 10; // cout << "Divided Distance: " << distance << endl; int speed = 0; if (distance < -4) { // cout << "Scroll speed -2" << endl; speed = -4; } else if (distance < -2) { // cout << "Scroll speed -1" << endl; speed = -1; } else if (distance > 4) { // cout << "Scroll speed 2" << endl; speed = 4; } else if (distance > 2) { // cout << "Scroll speed 1" << endl; speed = 1; } else { // cout << "Scroll speed 0" << endl; speed = 0; } STACK += speed; if (STACK >= 25) STACK = 25; else if (STACK <= 0) STACK = 0; cout << "STACK: " << STACK << endl; sender.send_stack(X_STATE, Y_STATE, ZOOM, STACK); } } ofCircle(x, y, 10); } else if (gestureFinder.blobs.size() == 2) { float euclidean; ofxCvBlob &first = gestureFinder.blobs[0]; ofxCvBlob &second = gestureFinder.blobs[1]; int x1 = first.centroid.x; int y1 = first.centroid.y; int x2 = second.centroid.x; int y2 = second.centroid.y; ofCircle(x1, y1, 10); ofCircle(x2, y2, 10); euclidean = ofDist(x1, y1, x2, y2); // cout << "Distance (Raw): " << euclidean << endl; float zoom = ofMap(euclidean, 0, 800, 0, 1); // cout << "Zoom (Mapped: " << zoom << endl; ZOOM = zoom; sender.send_stack(X_STATE, Y_STATE, ZOOM, STACK); } else if (isActivated) { isActivated = false; HW_FIRST_LEG = -1; HW_SECOND_LEG = -1; HW_CURRENT_DIRECTION = -1; } else { HW_FIRST_LEG = -1; HW_SECOND_LEG = -1; HW_CURRENT_DIRECTION = -1; HW_FIRST_Y = -1; HW_FIRST_X = -1; } switch (imageDisplayNumber) { case 1: image1.draw(10, 320, 400, 300); break; case 2: image2.draw(10, 320, 400, 300); break; default: break; } ofNoFill(); ofSetColor(255, 255, 255); gestureImage.draw(700, 20, 400, 300); gestureFinder.draw(700, 20, 400, 300); }
void View::Draw(const Model &model) const { ofPushMatrix(); SetupViewpoint(); ofBackground(ofColor::white); //CHASERS------------------- for (int i = 0; i < model.nChasers; i++){ model.topChaser[i]->draw(); model.botChaser[i]->draw(); model.rightChaser[i]->draw(); model.leftChaser[i]->draw(); } DrawGravity(model); DrawPlayers(model); ofColor ball_color = model.last_hit_player == 1 ? color_p1 : model.last_hit_player == 2 ? color_p2 : ofColor::white; DrawBallTrail(model, model.ball_trail, ball_color); DrawStrikeIndicator(model); DrawBall(model.ball, ball_color); for (float x=-10; x<GRID_W; x+=(1.0/6.0)) { for (float y=-5; y<GRID_H; y+=(1.0/6.0)) { if (ofDist(model.ball->GetPosition().x, model.ball->GetPosition().y, x, y)<0.3) { if (ball_color==color_p1){ ofSetColor(color_p1.r,ofRandom(10,60),color_p1.b, 100); }else if(ball_color==color_p2){ ofSetColor(ofRandom(10,60),color_p2.g,color_p2.b, 100); }else{ ofSetColor(ofRandom(200,250),ofRandom(200,250),ofRandom(200,250), 200); } ofCircle(x, y, 0.1); } else if (ofDist(model.player1_top->GetPosition().x, model.player1_top->GetPosition().y, x, y)<0.4 || ofDist(model.player1_bottom->GetPosition().x, model.player1_bottom->GetPosition().y, x, y)<0.4) { ofSetColor(color_p1.r,ofRandom(10,60),color_p1.b, 155); ofCircle(x, y, 0.12); } else if (ofDist(model.player2_top->GetPosition().x, model.player2_top->GetPosition().y, x, y)<0.4 || ofDist(model.player2_bottom->GetPosition().x, model.player2_bottom->GetPosition().y, x, y)<0.4) { ofSetColor(ofRandom(10,60),color_p2.g,color_p2.b, 155); ofCircle(x, y, 0.12); } else if (ofDist(model.ball->GetPosition().x, model.ball->GetPosition().y, x, y)< model.p1glowMax){ ofNoFill(); ofSetColor(color_p1.r,ofRandom(10,60),color_p1.b, 135); ofCircle(x, y, 0.12); ofFill(); } else if (ofDist(model.ball->GetPosition().x, model.ball->GetPosition().y, x, y)< model.p2glowMax){ ofNoFill(); ofSetColor(ofRandom(10,60),color_p2.g,color_p2.b, 135); ofCircle(x, y, 0.12); ofFill(); } else { ofFill(); ofSetColor(ofRandom(0,10),ofRandom(0,10),ofRandom(10,20), 20); ofTriangle(x, y+0.7, x-0.6, y-0.6, x+0.6, y-0.6); } } } DrawCourt(model); DrawScore(model); if (model.show_winning_state) { DrawTriangles(model); } ofPopMatrix(); //DrawFramesPerSecond(model); }
//------------------------------------------------------------ void Foe::update(){ if (! *paused){ bool frozen=false; if (freezeTimer>0 && freezeTimer%2==0) frozen=true; if (route.size()>2 && !frozen){ //reset the particle p.resetForce(); //atract the controler to the next node float atraction=moveAtraction; p.addAttractionForce(moveParticle, p.pos.distance(moveParticle.pos)*1.5, atraction); moveAtraction+=moveAtractionIncrease; //get force from the vector field. ofVec2f frc; frc = VF->getForceFromPos(p.pos.x, p.pos.y); //stealth gets almost no resistance from walls if (type=="stealth") frc*=0.3; p.addForce(frc.x, frc.y); //dampen and update the particle p.addDampingForce(); p.update(); } //see if we're ready to go to the next node if (p.pos.distance(moveParticle.pos)<nextNodeRad){ setNextNode(); } //if we're at the end, bolt off screen if (ofDist(p.pos.x,p.pos.y,goalX*fieldScale,goalY*fieldScale)<15){ //reachedTheEnd=true; endBolt=true; //set the move particle just off screen //check which gate this foe is using if (goalX>goalY) moveParticle.pos.x+=10; else moveParticle.pos.y+=10; } //reduce freezeTimer. if it is above 0 the foe is frozen freezeTimer--; } //moving the foe off screen if it has reached the end if (endBolt){ //reset the particle p.resetForce(); //atract the controler to the next node float atraction=moveAtraction*5; p.addAttractionForce(moveParticle, p.pos.distance(moveParticle.pos)*1.5, atraction); moveAtraction+=moveAtractionIncrease; //dampen and update the particle p.addDampingForce(); p.update(); //if we've reach the move particle, the foe is done if ( (goalX>goalY && p.pos.x>moveParticle.pos.x) || (goalY>goalX && p.pos.y>moveParticle.pos.y) ) { reachedTheEnd=true; } } //test if the foes is dead if (hp<=0) dead=true; }
void CloudsIntroSequence::updateQuestions(){ for(int i = 0; i < startQuestions.size(); i++){ CloudsPortal& curQuestion = startQuestions[i]; curQuestion.scale = questionScale; curQuestion.update(); if(curQuestion.hoverPosition.z < warpCamera.getPosition().z){ curQuestion.hoverPosition.z += questionWrapDistance; } float slowDownFactor = 0.0; //hold the questions if(questionChannels[ curQuestion.tunnelQuadrantIndex ]){ //let it go with time slowDownFactor = powf(ofMap(ofGetElapsedTimef(), channelPauseTime[curQuestion.tunnelQuadrantIndex] + questionPauseDuration, channelPauseTime[curQuestion.tunnelQuadrantIndex] + questionPauseDuration+2, 1.0, 0.0, true), 2.0); if(slowDownFactor == 0.0){ questionChannels[ curQuestion.tunnelQuadrantIndex ] = false; } } else{ float distanceFromCamera = (curQuestion.hoverPosition.z - warpCamera.getPosition().z); //if it's in front of the stop range if(distanceFromCamera > questionZStopRange.min){ slowDownFactor = powf(ofMap(distanceFromCamera, questionZStopRange.min, questionZStopRange.max, 1.0, 0.0, true), 2.0); // curQuestion.hoverPosition.z += slowDownFactor * cameraForwardSpeed; if(slowDownFactor > .9){ //pause this node and all the ones behind it if(!firstQuestionStopped){ firstQuestionStoppedTime = ofGetElapsedTimef(); firstQuestionStopped = true; } questionChannels[curQuestion.tunnelQuadrantIndex] = true; channelPauseTime[curQuestion.tunnelQuadrantIndex] = ofGetElapsedTimef(); } } } if(&curQuestion == caughtQuestion){ slowDownFactor = 1.0; } curQuestion.hoverPosition.z += cameraForwardSpeed * slowDownFactor; if(curQuestion.hoverPosition.z - warpCamera.getPosition().z < questionZStopRange.max || &curQuestion == caughtQuestion){ #ifdef OCULUS_RIFT ofVec3f screenPos = getOculusRift().worldToScreen(curQuestion.hoverPosition, true); ofRectangle viewport = getOculusRift().getOculusViewport(); float distanceToQuestion = ofDist(screenPos.x, screenPos.y,viewport.getCenter().x, viewport.getCenter().y); #else ofVec2f mouseNode = cursor; float distanceToQuestion = startQuestions[i].screenPosition.distance(mouseNode); #endif if(selectedQuestion == NULL && caughtQuestion == NULL){ if( distanceToQuestion < questionTugDistance.max ){ if(distanceToQuestion < questionTugDistance.min){ caughtQuestion = &curQuestion; if (caughtQuestion->startHovering()) { getClick()->setPosition(0); getClick()->play(); } } } } //we have a caught question make sure it's still close else if(caughtQuestion == &curQuestion){ if( caughtQuestion->isSelected() && !bQuestionDebug && selectedQuestion == NULL){ getSelectLow()->setPosition(0); getSelectLow()->play(); selectedQuestion = caughtQuestion; selectedQuestionTime = ofGetElapsedTimef(); selectQuestionStartPos = warpCamera.getPosition(); selectQuestionStartRot = warpCamera.getOrientationQuat(); CloudsPortalEventArgs args( GetTranslationForString( ofToUpper(selectedQuestion->question) ) ); ofNotifyEvent(events.portalHoverBegan, args); } else if(distanceToQuestion > questionTugDistance.max && selectedQuestion == NULL){ caughtQuestion->stopHovering(); caughtQuestion = NULL; if(firstQuestionStopped){ firstQuestionStoppedTime = ofGetElapsedTimef(); } } } } } if (caughtQuestion != NULL) { // move the sticky cursor towards the caught question stickyCursor.interpolate(caughtQuestion->screenPosition - ofVec2f(bleed,bleed)*.5, 0.2f); } else { stickyCursor.interpolate(cursor, 0.5f); } }
void Agent::update( ) { float dist = ofDist ( position.x , position.y , target.x , target.y ) ; if ( dist < targetBufferDist ) { if ( bFirstTarget == false ) bFirstTarget = true ; //bTarget = true ; // if ( agent.bTarget == true && points.size() > 1 ) // { targetIndex+= 1 ; //cout << "target index is now : " << targetIndex << endl ; //cout << " x : " << target.x << " , " << target.y << " , " << target.z << endl ; if ( targetIndex >= ( followRibbon.points.size() - 1 ) ) { targetIndex = 0 ; } if ( followRibbon.points.size() > 0 ) { target = followRibbon.points [ targetIndex ] ; } // agent.bTarget = false ; //} } if ( bFirstTarget == true ) trailRibbon.addPoint( ofVec3f( position ) ) ; // float dist = mousePoint.distance( agents[a]->target ) ; // ofDist( mousePoint.x , mousePoint.y , agents[a]->target.x , followRibbon.update() ; // = (*ribbons[a] ) ; trailRibbon.update() ; /* if ( ofGetFrameNum() % pathSampling == 0 ) { curIndex++ ; ColorPoint cp ; if ( curIndex == colorInterpolateNum ) { curIndex = 0 ; color = nextColor ; nextColor = colorPool.getRandomColor() ; } float ratio = (float)curIndex / (float)colorInterpolateNum ; ofColor lerp = color.lerp( nextColor , ratio ) ; cp.color = lerp ; cp.color.a = ofRandom( 255.0f * .7 , 255.0f * 1.0f ) ; cp.position = position ; cp.radius = ofRandom ( 0.25 , 4 ) ; //4 + sin( ofGetElapsedTimef() ) * 1 ; curPath.addPoint( cp ) ; //.push_back( cp ) ; } */ force.limit(maxForce); velocity += force; velocity.limit(maxVelocity); position += velocity; seek( target ) ; }
//-------------------------------------------------------------- void ofApp::draw(){ // Sets the background to a circular gradient ofColor colorOne; ofColor colorTwo; colorOne.set (182, 73, 38); colorTwo.set (142, 40, 0); ofBackgroundGradient(colorOne, colorTwo, OF_GRADIENT_CIRCULAR); // ofBackground(0x2A2C2B); //Set up the background // //Draw background rect for spectrum // ofSetColor( 230, 230, 230 ); // ofFill(); // ofRect( 10, 700, N * 6, -100 ); // // //Draw spectrum // ofSetColor( 0, 0, 0 ); // for (int i=0; i<N; i++) { // //Draw bandRad and bandVel by black color, // //and other by gray color // if ( i == bandRad || i == bandVel ) { // ofSetColor( 0, 0, 0 ); //Black color // } // else { // ofSetColor( 128, 128, 128 ); //Gray color // } // ofRect( 10 + i * 5, 700, 3, -spectrum[i] * 100 ); // } //Draw cloud //Move center of coordinate system to the screen center ofPushMatrix(); ofTranslate( ofGetWidth() / 2, ofGetHeight() / 2 ); //Draw points ofSetColor(70, 137, 102); ofFill(); for (int i=0; i<n; i++) { ofCircle( p[i], 10 ); } //Draw lines between near points ofSetColor(255, 240, 165); float dist = 30; //Threshold parameter of distance for (int j=3; j<n; j++) { for (int k=j+1; k<n; k++) { if ( ofDist( p[j].x, p[j].y, p[k].x, p[k].y ) < dist ) { ofLine( p[j], p[k] ); } } } //Restore coordinate system ofPopMatrix(); }
//-------------------------------------------------------------- void testApp::mousePressed(int x, int y, int button){ float d = ofDist(loc.x, loc.y, x, y); if(d < radius) { dragging = true; } }
//-------------------------------------------------------------- void ofApp::update(){ contourFinder.setMinAreaRadius(minRadius); contourFinder.setMaxAreaRadius(maxRadius); contourFinder.setMinArea(minArea); contourFinder.setMaxArea(maxArea); contourFinder.setThreshold(mThreshold); //ビデオのサイズ調整 setVideoSize(); if(MOVIE_DEBUG_MODE){ movie.update(); if(movie.isFrameNew()){ ofxCv::blur(movie,10); contourFinder.findContours(movie); } }else { cam.update(); if(cam.isFrameNew()){ ofxCv::blur(cam,10); contourFinder.findContours(cam); } } //当たり判定 if(showLabels){ //接しているか判定 float objRads[contourFinder.size()]; float objPosX[contourFinder.size()]; float objPosY[contourFinder.size()]; for(int i = 0;i<contourFinder.size();i++){ cv::Rect targetRect = contourFinder.getBoundingRect(i); float targetW = targetRect.width; float targetH = targetRect.height; float targetF = max(targetW,targetH); objRads[i] = targetF; objPosX[i] = contourFinder.getCenter(i).x; objPosY[i] = contourFinder.getCenter(i).y; } for(int i = 0;i < contourFinder.size();i++){ for (int n = i+1; n<contourFinder.size(); n++) { if(objRads[n]){ float distance = ofDist(objPosX[i], objPosY[i], objPosX[n], objPosY[n]); if(objRads[i] + objRads[n] + collisionDist > distance){ std::cout << "Collision!!" << endl; std::cout << distance << endl; //OSCメッセージの準備 ofxOscMessage m; //OSCアドレスの指定 m.setAddress( "/collision/flag" ); m.addIntArg(0); //メッセージを送信 sender.sendMessage( m ); } } } } } }
//-------------------------------------------------------------- void testApp::update(){ if (!titleScreen && !displayMsg1 && !displayMsg2 && !displayMsg3) { // If the player goes offscreen, reset to the default position: /*if (player.xPos < -player.wide || player.xPos > ofGetWidth()+player.wide) { player.xPos = xPosPlayerDefault; player.yPos = player.onGround; }*/ if (booYaCounter > 0) booYaCounter -= 1/framerate; if (dontPlayMeMsgCounter > 0) dontPlayMeMsgCounter -= 1/framerate; else dontPlayMeMsg = false; if (demo) { secondCounter ++; if (secondCounter >= framerate) { demoCounter--; secondCounter = 0; } if (demoCounter <= 0) demo = false; } if (slow) framerate = frameRateSlow; else framerate = framerateNormal; ofSetFrameRate(framerate); if (moveL) originX += moveSpeed; // Translate to the right on LEFT. if (moveR) originX -= moveSpeed; // Translate to the left on RIGHT. // Restore the player to default position where appropriate: if (player.yPos == player.onGround && !player.vanish && !player.kickAss){ if (player.xPos > xPosPlayerDefault) player.xPos--; if (player.xPos < xPosPlayerDefault) player.xPos++; } moveR = true; // Advance the screen automatically when the player's in the default pos: if ((player.xPos != xPosPlayerDefault && player.yPos != player.onGround && !collided) || player.vanish || player.kickAss) moveR = false; else if (collided && player.xPos < xPosPlayerDefault/2) moveR = false; // ...unless the player attacks: //else moveR = false; // Advance the enemy generation counter once per second: if (enemyRateCounter < enemyRate) enemyRateCounter += 1/framerateNormal; // Generate enemies automatically at the pace we set in setup(): if (enemyRateCounter >= enemyRate && enemies.size() < maxEnemies) { enemy_grunt enemy; // Position them just offscreen to the right, taking into account the changing position of the origin: enemy.setup(ofGetWidth()+fabs(originX)+100, groundY); enemies.push_back(enemy); enemyRateCounter = 0; } // Update everyone: for (int i = 0; i<enemies.size(); i++) enemies[i].update(originX); player.update(framerate); // Detect a collision between the player and an enemy: collided = false; // Set this to false by default, overwritten by collision: for (int i=0; i<enemies.size(); i++) { float enemyDistance = ofDist(player.xPos, player.yPos, enemies[i].xPos+originX, enemies[i].yPos); float attackDistance = (player.wide/2+enemies[i].rad)*4; float defeatDistance = player.wide/2+enemies[i].rad; if (enemyDistance < attackDistance && player.xPos < ofGetWidth()) { if (!player.vanish && !player.kickAss) storeI = i; // Record the value of the enemy in question. collided = true; // This cues jumping, vanishing, then kicking ass. if (enemyDistance < defeatDistance) { enemies[i].pwned = true; // The enemy is defeated. enemiesDefeated++; player.kickAss = false; // Occasionally play a message of condolence: if (rollForBooYa && ofRandom(1) <= 0.6) { booYaMsg = true; booYaCounter = booYaCounterLimit; rollForBooYa = false; } else rollForBooYa = false; } } else player.jump = false; } rollForBooYa = true; if (booYaCounter <= 0) booYaMsg = false; // Trigger effects on collision: if (collided && !player.kickAss) { player.jump = true; player.tall = 25; // Randomly activate slow motion: if (rollForSlow && ofRandom(1) < 0.2) { slow = true; rollForSlow = false; } else rollForSlow = false; } else { // Restore default values: rollForSlow = true; slow = false; player.tall = 50; } // Randomly comment on the vanishing act: if (player.vanish) { if (rollForNinja && ofRandom(1) < 0.5) { ninjaMsg = true; rollForNinja = false; } else rollForNinja = false; } else { // Restore default values: rollForNinja = true; ninjaMsg = false; } // The player reappears at a randomized point: if (player.changeX) { player.xPos += ofRandom(-xPosPlayerDefault, xPosPlayerDefault); player.yPos += ofRandom(-player.yPos, player.onGround-player.yPos-10); player.changeX = false; } // We use Xeno's Paradox to "animate" the player's movement toward the enemy's position to make an attack: if (player.kickAss) { if (player.xPos >= enemies[storeI].xPos+originX) { player.xPos -= xeno * ofDist(player.xPos, player.yPos, enemies[storeI].xPos+originX, player.yPos); } else { player.xPos += xeno * ofDist(player.xPos, player.yPos, enemies[storeI].xPos+originX, player.yPos); } player.yPos += xeno * ofDist(player.xPos, player.yPos, player.xPos, enemies[storeI].yPos); } // Update coordinates for writing messages: mouthX = player.xPos-player.wide/2-10; mouthY = player.yPos-player.tall/2-10; msgX = player.xPos-110; msgY = ofGetHeight()/2+10; textX = player.xPos-140; textY = ofGetHeight()/2; // Following up the boolean function we created above, this oF function sorts the vector according to the values of the booleans and then removes any with a 'true' value: ofRemove(enemies,bShouldIErase); // If the player defeats all the enemies, cue the win screen, then restart the game: if (enemiesDefeated >= totalToWin) youWonCounter += 1/framerate; if (youWonCounter >= youWonCounterLimit) { // Clear out the vector: for (int i=0; i<enemies.size(); i++) enemies.erase(enemies.begin(), enemies.end()); setup(); } } }
//-------------------------------------------------------------- void testApp::draw(){ ofSetColor(ofColor::lightGreen); ofPushMatrix(); ofScale(ofGetWidth()/640, ofGetHeight()/480); // draw debug (ie., image, depth, skeleton) // openNIDevice.drawDebug(); // use a blend mode so we can see 'through' the mask(s) ofEnableBlendMode(OF_BLENDMODE_ALPHA); // get number of current users int numUsers = openNIDevice.getNumTrackedUsers(); // iterate through users for (int i = 0; i < numUsers; i++){ // get a reference to this user ofxOpenNIUser & user = openNIDevice.getTrackedUser(i); rightHand = user.getJoint(JOINT_RIGHT_HAND).getProjectivePosition(); leftHand = user.getJoint(JOINT_LEFT_HAND).getProjectivePosition(); // for body head = user.getJoint(JOINT_HEAD).getProjectivePosition(); rightShoulder = user.getJoint(JOINT_RIGHT_SHOULDER).getProjectivePosition(); leftShoulder = user.getJoint(JOINT_LEFT_SHOULDER).getProjectivePosition(); rightElbow = user.getJoint(JOINT_RIGHT_ELBOW).getProjectivePosition(); leftElbow = user.getJoint(JOINT_LEFT_ELBOW).getProjectivePosition(); torsoJoint = user.getJoint(JOINT_TORSO).getProjectivePosition(); rightHip = user.getJoint(JOINT_RIGHT_HIP).getProjectivePosition(); leftHip = user.getJoint(JOINT_LEFT_HIP).getProjectivePosition(); rightKnee = user.getJoint(JOINT_RIGHT_KNEE).getProjectivePosition(); leftKnee = user.getJoint(JOINT_LEFT_KNEE).getProjectivePosition(); rightFoot = user.getJoint(JOINT_RIGHT_FOOT).getProjectivePosition(); leftFoot = user.getJoint(JOINT_LEFT_FOOT).getProjectivePosition(); vel_right = rightHand - prev_rightHand; vel_left = leftHand - prev_leftHand; // if (vel.length() > 50 && rightHand.z < prev_rightHand.z) { // isThrowing = true; // // }else if (vel.length() < 10) { // isThrowing = false; // } // draw bg bg.draw(-200, 0); // draw the silhouette if(gameStatus == 0, 1, 2) //draw head ofCircle(head.x, head.y, 60); //draw shoulders //ofBeginShape(); int shoulderLength = ofDist(rightShoulder.x, rightShoulder.y, leftShoulder.x, leftShoulder.y); int shoulder_width = shoulderLength/10; //ofVertex(rightShoulder.x, (rightShoulder.y - shoulder_width)); // ofVertex(rightShoulder.x, (rightShoulder.y + shoulder_width)); // ofVertex(leftShoulder.x, (leftShoulder.y + shoulder_width)); // ofVertex(leftShoulder.x, (leftShoulder.y - shoulder_width)); // ofEndShape(); // int shoulderLength = ofDist(rightShoulder.x, rightShoulder.y, leftShoulder.x, leftShoulder.y); // ofRect(rightShoulder.x, rightShoulder.y, -(shoulderLength), (shoulderLength/3)); //draw upper right arm ofBeginShape(); int upperArmLength = ofDist(rightShoulder.x, rightShoulder.y, rightElbow.x, rightElbow.y); int upperArm_width = upperArmLength/8; ofVertex((rightShoulder.x + upperArm_width), rightShoulder.y); ofVertex((rightShoulder.x + upperArm_width)-10, rightShoulder.y-10); ofVertex((rightShoulder.x + upperArm_width)-20, rightShoulder.y-20); ofVertex((rightShoulder.x - upperArm_width), rightShoulder.y); ofVertex((rightElbow.x - upperArm_width), rightElbow.y); ofVertex((rightElbow.x + upperArm_width), rightElbow.y); ofEndShape(); //draw upper left arm ofBeginShape(); ofVertex((leftShoulder.x - upperArm_width), leftShoulder.y); ofVertex((leftShoulder.x - upperArm_width)+20, leftShoulder.y-20); ofVertex((leftShoulder.x - upperArm_width)+10, leftShoulder.y-10); ofVertex((leftShoulder.x + upperArm_width), leftShoulder.y); ofVertex((leftElbow.x + upperArm_width), leftElbow.y); ofVertex((leftElbow.x - upperArm_width), leftElbow.y); ofEndShape(); //draw lower right arm ofBeginShape(); int lowerArmLength = ofDist(rightElbow.x, rightElbow.y, rightHand.x, rightHand.y); int lowerArm_width = lowerArmLength/9; ofVertex((rightElbow.x + lowerArm_width), rightElbow.y); ofVertex((rightElbow.x - lowerArm_width), rightElbow.y); ofVertex((rightHand.x - lowerArm_width), rightHand.y); ofVertex((rightHand.x + lowerArm_width), rightHand.y); ofEndShape(); //draw lower left arm ofBeginShape(); ofVertex((leftElbow.x + lowerArm_width), leftElbow.y); ofVertex((leftElbow.x - lowerArm_width), leftElbow.y); ofVertex((leftHand.x - lowerArm_width), leftHand.y); ofVertex((leftHand.x + lowerArm_width), leftHand.y); ofEndShape(); //draw hands ofCircle(rightHand.x, rightHand.y, 15); ofCircle(leftHand.x, leftHand.y, 15); //draw torso ofBeginShape(); //shoulders ofVertex(rightShoulder.x, rightShoulder.y); ofVertex(rightShoulder.x, rightShoulder.y-10); ofVertex(rightShoulder.x-10, rightShoulder.y-20); ofVertex(leftShoulder.x+10, leftShoulder.y-20); ofVertex(leftShoulder.x, leftShoulder.y-10); ofVertex(leftShoulder.x, leftShoulder.y); ofVertex(leftShoulder.x, leftHip.y); ofVertex(leftShoulder.x+20, leftHip.y+40); //ofVertex(torsoJoint.x, rightHip.y+35); ofVertex(rightShoulder.x-20, rightHip.y+40); ofVertex(rightShoulder.x, rightHip.y); ofEndShape(); //draw upper right leg ofBeginShape(); int upperLegLength = ofDist(rightHip.x, rightHip.y, rightKnee.x, rightKnee.y); int upperLeg_width = upperLegLength/10; ofVertex((rightHip.x + upperLeg_width), rightHip.y); ofVertex((rightHip.x - upperLeg_width), rightHip.y); ofVertex((rightKnee.x - upperLeg_width), rightKnee.y); ofVertex((rightKnee.x + upperLeg_width), rightKnee.y); ofEndShape(); //draw upper left leg ofBeginShape(); ofVertex((leftHip.x + upperLeg_width), leftHip.y); ofVertex((leftHip.x - upperLeg_width), leftHip.y); ofVertex((leftKnee.x - upperLeg_width), leftKnee.y); ofVertex((leftKnee.x + upperLeg_width), leftKnee.y); ofEndShape(); //draw lower right leg ofBeginShape(); int lowerLegLength = ofDist(rightKnee.x, rightKnee.y, rightFoot.x, rightFoot.y); int lowerLeg_width = lowerLegLength/8; ofVertex((rightKnee.x + lowerLeg_width), rightKnee.y); ofVertex((rightKnee.x - lowerLeg_width), rightKnee.y); ofVertex((rightFoot.x - lowerLeg_width), rightFoot.y); ofVertex((rightFoot.x + lowerLeg_width), rightFoot.y); ofEndShape(); //draw lower left leg ofBeginShape(); ofVertex((leftKnee.x + lowerLeg_width), leftKnee.y); ofVertex((leftKnee.x - lowerLeg_width), leftKnee.y); ofVertex((leftFoot.x - lowerLeg_width), leftFoot.y); ofVertex((leftFoot.x + lowerLeg_width), leftFoot.y); ofEndShape(); //user.drawSkeleton(); //only if we're NOT playing, draw the silhouette... maybe you want it like this? if (vel_left.length() > vel_right.length()) { vel = vel_left; hand = leftHand; prevHand = prev_leftHand; } else { vel = vel_right; hand = rightHand; prevHand = prev_rightHand; } if (gameStatus == 1){ //only check the ball, and then draw ball stuff if we're playing! myBall.update(hand, prevHand, vel); if ((target.x - 40) < myBall.pos.x && myBall.pos.x < (target.x + 40) && (target.y - 40) < myBall.pos.y && myBall.pos.y < target.y + 40) { hasHit = true; now = ofGetElapsedTimef(); lastTarget.x = target.x; lastTarget.y = target.y; //cout << "wtf" << endl; } ofNoFill(); ofSetColor(ofColor::white); ofSetLineWidth(5); ofCircle(target.x, target.y, 50); ofFill(); drawSplat(); for (int i = 0; i < splatList.size(); i++ ) { splatList[i].draw(); } prev_rightHand = rightHand; prev_leftHand = leftHand; } } if (gameStatus == 0){ // this is your start screen ! score = 0; //reset the score? bg.draw(-200, 0); ofSetColor(255); //start button ofSetColor(ofColor::red); ofStyle(smooth); ofCircle(WIDTH/1.5, HEIGHT/2, 75); // (ballX >= ofGetWidth() || ballX <= 0 ) ofSetColor(ofColor::black); verdana.loadFont(ofToDataPath("verdana.ttf"), 30); string msgB = "Start"; verdana.drawString(msgB, (WIDTH/1.5)-50, (HEIGHT/2)+10); // use code for start button int distFromStartCircle = ofDist(WIDTH/1.5, HEIGHT/2, hand.x, hand.y); if (distFromStartCircle < 75) { gameStatus = 1; // set play screen score = 0; //reset score //reset timer } ofSetColor(ofColor::white); verdana.loadFont(ofToDataPath("verdana.ttf"), 96); string msg = "Food Fight!"; verdana.drawString(msg, WIDTH/16, 100); } else if (gameStatus == 1){ myBall.draw(hand); ofDisableBlendMode(); ofPopMatrix(); // draw some info regarding frame counts etc // ofSetColor(0, 255, 0); //string msg = " MILLIS: " + ofToString(ofGetElapsedTimeMillis()) + " FPS: " + ofToString(ofGetFrameRate()) + " Device FPS: " + ofToString(openNIDevice.getFrameRate()); // // verdana.drawString(msg, 20, openNIDevice.getNumDevices() * 480 - 20); //cout << vel.length() << endl; //draw svg file //svg.draw(); ofSetColor(255); long currTime = ofGetElapsedTimeMillis(); //int min = 60000; //if (currTime <= 15000) { // verdana.loadFont(ofToDataPath("verdana.ttf"), 75); // string msg = "Food Fight!"; // verdana.drawString(msg, WIDTH/3, 100); // } verdana.loadFont(ofToDataPath("verdana.ttf"), 50); string msgC = "Score: "+ofToString(score); verdana.drawString(msgC, WIDTH/.9, 150); string msgT = "Time(sec): "+ofToString((ofGetElapsedTimeMillis()/1000)); verdana.drawString(msgT, WIDTH/8, 150); } else if (gameStatus == 2) { // ofRect( //draw rect over background // draw bg bg.draw(-200, 0); //restart button ofSetColor(ofColor::green); ofCircle(WIDTH/3, HEIGHT/2, 75); // (ballX >= ofGetWidth() || ballX <= 0 ) ofSetColor(ofColor::black); verdana.loadFont(ofToDataPath("verdana.ttf"), 20); string msgR = "Restart"; verdana.drawString(msgR, ((WIDTH/3)-55), (HEIGHT/2)+10); // use code for restart button int distFromRestartCircle = ofDist(WIDTH/3, HEIGHT/2, hand.x, hand.y); if (distFromRestartCircle < 75) { gameStatus = 0; // set start screen score = 0; //reset score //reset timer } //quit button ofSetColor(ofColor::red); ofCircle(WIDTH/.99, HEIGHT/2, 75); ofSetColor(ofColor::black); verdana.loadFont(ofToDataPath("verdana.ttf"), 20); string msgQ = "Quit"; verdana.drawString(msgQ, ((WIDTH/.99)-35), (HEIGHT/2)+10); //quit button int distFromQuitCircle = ofDist(WIDTH/.99, HEIGHT/2, hand.x, hand.y); if (distFromQuitCircle < 75) { //gameStatus = 1; //set play screen score = 0; //reset the score? bg.draw(-200, 0); ofSetColor(ofColor::red); verdana.loadFont(ofToDataPath("verdana.ttf"), 80); string msgG = "Game Over!"; verdana.drawString(msgG, (WIDTH/8), HEIGHT/2); } ofSetColor(ofColor::aquamarine); verdana.loadFont(ofToDataPath("verdana.ttf"), 50); string msgF = "Final Score:"+ofToString(score); verdana.drawString(msgF, (WIDTH/3)-25, 100); //final score //draw game over screen with final score } }
//-------------------------------------------------------------- void testApp::mousePressed(int x, int y, int button){ float d = ofDist(x, y, topX, topY); if(d < topRadius) { dragging = true; } }
//-------------------------------------------------------------- void testApp::update(){ updateDataPoints(); #ifdef TARGET_OSX // only working on Mac at the moment hardware.update(); #endif if (isLive) { // update all nodes recordContext.update(); recordDepth.update(); recordImage.update(); // demo getting depth pixels directly from depth gen depthRangeMask.setFromPixels(recordDepth.getDepthPixels(nearThreshold, farThreshold), recordDepth.getWidth(), recordDepth.getHeight(), OF_IMAGE_GRAYSCALE); // update tracking/recording nodes if (isTracking) recordUser.update(); if (isRecording) oniRecorder.update(); // demo getting pixels from user gen if (isTracking && isMasking) { allUserMasks.setFromPixels(recordUser.getUserPixels(), recordUser.getWidth(), recordUser.getHeight(), OF_IMAGE_GRAYSCALE); user1Mask.setFromPixels(recordUser.getUserPixels(1), recordUser.getWidth(), recordUser.getHeight(), OF_IMAGE_GRAYSCALE); user2Mask.setFromPixels(recordUser.getUserPixels(2), recordUser.getWidth(), recordUser.getHeight(), OF_IMAGE_GRAYSCALE); } } else { // update all nodes playContext.update(); playDepth.update(); playImage.update(); // demo getting depth pixels directly from depth gen depthRangeMask.setFromPixels(playDepth.getDepthPixels(nearThreshold, farThreshold), playDepth.getWidth(), playDepth.getHeight(), OF_IMAGE_GRAYSCALE); // update tracking/recording nodes if (isTracking) playUser.update(); // demo getting pixels from user gen if (isTracking && isMasking) { allUserMasks.setFromPixels(playUser.getUserPixels(), playUser.getWidth(), playUser.getHeight(), OF_IMAGE_GRAYSCALE); user1Mask.setFromPixels(playUser.getUserPixels(1), playUser.getWidth(), playUser.getHeight(), OF_IMAGE_GRAYSCALE); user2Mask.setFromPixels(playUser.getUserPixels(2), playUser.getWidth(), playUser.getHeight(), OF_IMAGE_GRAYSCALE); } } if (recordUser.getNumberOfTrackedUsers() > 0) { // we have a tracked user! yay! ofxTrackedUser * tracked = recordUser.getTrackedUser(1); // all i'm doing here is setting the points in this array to parts of the skeleton that the kinect finds. if you start to type in tracked-> then it should autofill with the other body parts you can use. i've included z in here in case we do want to try to do depth parts[0].pos.set(tracked->left_lower_arm.position[1].X, tracked->left_lower_arm.position[1].Y, tracked->left_lower_arm.position[1].Z); parts[0].pos *= 1.6; parts[1].pos.set(tracked->right_lower_arm.position[1].X, tracked->right_lower_arm.position[1].Y, tracked->right_lower_arm.position[1].Z); parts[1].pos *= 1.6; parts[2].pos.set(tracked->left_lower_leg.position[1].X, tracked->left_lower_leg.position[1].Y, tracked->left_lower_leg.position[1].Z); parts[2].pos *= 1.6; parts[3].pos.set(tracked->right_lower_leg.position[1].X, tracked->right_lower_leg.position[1].Y, tracked->right_lower_leg.position[1].Z); parts[3].pos *= 1.6; } // // draw lines // ofSetColor(0); // ofFill(); // // ofLine(centerPoint, rootLeg.pos); // ofLine(centerPoint, otherLeg.pos); // // ofLine(centerPoint, leftShoulder); // ofLine(centerPoint, rightShoulder); // // // draw root circle // ofCircle(rootLeg.pos, 30); // // // draw other leg circle // ofCircle(otherLeg.pos, 30); // // // draw smaller shoulder circles // ofCircle(leftShoulder, 10); // ofCircle(rightShoulder, 10); // // // draw hands // ofCircle(leftHand.pos, 30); // ofCircle(rightHand.pos, 30); partIsOverRootLeg = false; for (int i = 0; i < 4; i++) { if (ofDist(rootPoint.x, rootPoint.y, parts[i].pos.x, parts[i].pos.y) < 70) { partIsOverRootLeg = true; } } partIsOverOtherLeg = false; for (int i = 0; i < 4; i++) { if (ofDist(otherLegPoint.x, otherLegPoint.y, parts[i].pos.x, parts[i].pos.y) < 70) { partIsOverOtherLeg = true; } } partIsOverLeftHand = false; for (int i = 0; i < 4; i++) { if (ofDist(leftHandPoint.x, leftHandPoint.y, parts[i].pos.x, parts[i].pos.y) < 70) { partIsOverLeftHand = true; } } partIsOverRightHand = false; for (int i = 0; i < 4; i++) { if (ofDist(rightHandPoint.x, rightHandPoint.y, parts[i].pos.x, parts[i].pos.y) < 70) { partIsOverRightHand = true; } } }
//-------------------------------------------------------------- void ballPond::update(){ kinect.update(); grayImage.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height); grayThreshFar = grayImage; grayThresh = grayImage; grayThresh.threshold(nearThreshold, true); grayThreshFar.threshold(farThreshold); cvAnd(grayThresh.getCvImage(), grayThreshFar.getCvImage(), grayImage.getCvImage(), NULL); //update the cv image grayImage.flagImageChanged(); contourFinder.findContours(grayImage, minBlobSize, (kinect.width*kinect.height)/2, 3, true); vector <ofPoint> temp; if (contourFinder.blobs.size() > 0) { //Contour Analysis for (int i = 0; i < contourFinder.blobs.size(); i++) { v_arr.push_back(temp); ofPoint p; //ofxBox2dLine lineStrip; //lineStripBlob.push_back(lineStrip); lineStripBlob[i].setWorld(box2d.getWorld()); lineStripBlob[i].clear(); //lineStripBlob.clear(); if(bReversePoints) { contourAnalysis.simplify(contourFinder.blobs[i].pts, simpleContour, simpleAmount); //BIG MEMORY ALLOCATION LEAK *SOLVED* blobPts.push_back(simpleContour.size()-1); for (int j = 0; j < blobPts[i]; j++) { v_arr[i].push_back(0); } for(int j = blobPts[i]; j >= 0; j--) { //for (int j=0; j<blobPts[i]; j++) { v_arr[i].push_back(0); v_arr[i][j].x = simpleContour[j].x; v_arr[i][j].y = simpleContour[j].y; p.x = v_arr[i][j].x; p.y = v_arr[i][j].y; lineStripBlob[i].addPoint(ofMap(p.x, 0, 640, 0, resX, false), ofMap(p.y, 0, 480, 0, resY, false)); } } // good to go :) lineStripBlob[i].createShape(); } //Blobs Center/Width/Distance blob1.x = contourFinder.blobs[0].centroid.x; blob1.y = contourFinder.blobs[0].centroid.y; blob1Size.x = contourFinder.blobs[0].boundingRect.width; blob1Size.y = contourFinder.blobs[0].boundingRect.height; if (contourFinder.blobs.size() == 2){ blob2.x = contourFinder.blobs[1].centroid.x; blob2.y = contourFinder.blobs[1].centroid.y; blob2Size.x = contourFinder.blobs[1].boundingRect.width; blob2Size.y = contourFinder.blobs[1].boundingRect.height; if (blob1.x < blob2.x) { distBlob = ofDist((blob1.x + blob1Size.x/2),0,(blob2.x - blob2Size.x/2),0); }else { distBlob = ofDist((blob1.x - blob1Size.x/2),0,(blob2.x + blob2Size.x/2),0); } }else { bDistBlob = true; } } if (contourFinder.nBlobs < clearLineStrip) { //cout << "nblobs: " << contourFinder.nBlobs << " clearLineStrip: " << clearLineStrip << endl; for (int i = contourFinder.nBlobs; i < clearLineStrip; i++) { lineStripBlob[i].clear(); //cout << "lineStripBlob[" << i << "].clear()" << endl; } } clearLineStrip = contourFinder.nBlobs; //cout << " clearLineStrip: " << clearLineStrip << " = nblobs: " << contourFinder.nBlobs << " = blobs.size(): " << contourFinder.blobs.size() << endl; //Box2d box2d.update(); //if particles are outside the window set new position for( int i = 0; i < particles.size(); i++ ) { particles[i].update(); } //Sound ofSoundUpdate(); //ContactHandler }
void ofApp::ofRectGradient(int px, int py, int w, int h,const ofColor& start, const ofColor& end, ofGradientMode mode){ ofVboMesh gradientMesh; gradientMesh.clear(); gradientMesh.setMode(OF_PRIMITIVE_TRIANGLE_FAN); #ifndef TARGET_EMSCRIPTEN #ifdef TARGET_OPENGLES if(ofIsGLProgrammableRenderer()) gradientMesh.setUsage(GL_STREAM_DRAW); #else gradientMesh.setUsage(GL_STREAM_DRAW); #endif #endif if(mode == OF_GRADIENT_CIRCULAR) { // this could be optimized by building a single mesh once, then copying // it and just adding the colors whenever the function is called. ofVec2f center(w / 2 + px, h / 2 + py); gradientMesh.addVertex(center); gradientMesh.addColor(start); int n = 32; // circular gradient resolution float angleBisector = TWO_PI / (n * 2); float smallRadius = ofDist(0, 0, w / 2, h / 2); float bigRadius = smallRadius / cos(angleBisector); for(int i = 0; i <= n; i++) { float theta = i * TWO_PI / n; gradientMesh.addVertex(center + ofVec2f(sin(theta), cos(theta)) * bigRadius); gradientMesh.addColor(end); } } else if(mode == OF_GRADIENT_LINEAR) { gradientMesh.addVertex(ofVec2f(px, py)); gradientMesh.addVertex(ofVec2f(px+w, py)); gradientMesh.addVertex(ofVec2f(px+w, py+h)); gradientMesh.addVertex(ofVec2f(px, py+h)); gradientMesh.addColor(start); gradientMesh.addColor(start); gradientMesh.addColor(end); gradientMesh.addColor(end); } else if(mode == OF_GRADIENT_BAR) { gradientMesh.addVertex(ofVec2f(px+w / 2, py+h / 2)); gradientMesh.addVertex(ofVec2f(px, py+h / 2)); gradientMesh.addVertex(ofVec2f(px, py)); gradientMesh.addVertex(ofVec2f(px+w, py)); gradientMesh.addVertex(ofVec2f(px+w, py+h / 2)); gradientMesh.addVertex(ofVec2f(px+w, py+h)); gradientMesh.addVertex(ofVec2f(px, py+h)); gradientMesh.addVertex(ofVec2f(px, py+h / 2)); gradientMesh.addColor(start); gradientMesh.addColor(start); gradientMesh.addColor(end); gradientMesh.addColor(end); gradientMesh.addColor(start); gradientMesh.addColor(end); gradientMesh.addColor(end); gradientMesh.addColor(start); } GLboolean depthMaskEnabled; glGetBooleanv(GL_DEPTH_WRITEMASK,&depthMaskEnabled); glDepthMask(GL_FALSE); gradientMesh.draw(); if(depthMaskEnabled){ glDepthMask(GL_TRUE); } }
//-------------------------------------------------------------- void testApp::draw(){ //----------------------------------- start draw for LEDS // ofBackground( (int)( ofGetElapsedTimef() * 100 ) % 255); // float sinOfTime = sin( ofGetElapsedTimef() * 10 ); // float sinOfTimeMapped = ofMap( sinOfTime, -1, 1, 0 ,30); // ofSetColor( 127 + 127 * sin(ofGetElapsedTimef())); // ofCircle(mouseX, ofGetHeight() * .5, sinOfTimeMapped * 10.0); // -------------------------- draw the line ofSetColor(fade); ofSetLineWidth(5); TPR.draw(); // -------------------------- draw the point at the current time if (TPR.bHaveADrawing()){ // if we have a drawing to work with // figure out what time we are at, and make sure we playback cyclically (!) // use the duration here and make sure our timeToCheck is in the range of 0 - duration float timeToCheck = ofGetElapsedTimef() - playbackStartTime; while (timeToCheck > TPR.getDuration() && TPR.getDuration() > 0){ timeToCheck -= TPR.getDuration(); } // get the position and velocity at timeToCheck ofPoint pos = TPR.getPositionForTime(timeToCheck); ofPoint vel = TPR.getVelocityForTime(timeToCheck); // since velocity is a line, we want to know how long it is. float lengthOfVel = ofDist(0,0,vel.x, vel.y); ofFill(); float sinOfTime = sin( ofGetElapsedTimef() * 5 ); float sinOfTimeMapped = ofMap( sinOfTime, -1, 1, 10 ,40); ofSetColor( 127 + 127 * sin(ofGetElapsedTimef())); // ofCircle(mouseX, ofGetHeight() * .5, sinOfTimeMapped * 10.0); ofCircle(pos.x, pos.y, 2 + lengthOfVel/5.0); } //----------------------------------- end draw for LEDS ofImage imgTemp; imgTemp.grabScreen(0, ofGetHeight()/2, ofGetWidth(), 6); imgTemp.setImageType(OF_IMAGE_GRAYSCALE ); imgTemp.resize(N_LIGHTS, 6); unsigned char * pixels = imgTemp.getPixels(); if (ofGetFrameNum() % 3 == 0){ serial.writeByte(255); for (int j = 0; j < N_LIGHTS; j++){ float pct = ofMap(pixels[j], 0, 255, 0 , 1, true); float value = ofMap( powf(pct, 2), 0, 1, 0,253, true); serial.writeByte(value); //if (j % (int)ofClamp(mouseX, 1, 10) == 0) serial.writeByte(254); //else serial.writeByte(0); } } ofSetColor(127); ofFill(); ofRect(0, ofGetHeight()/2, ofGetWidth(), 6); }
bool ofxCircOSC::isOn(int xMouse, int yMouse){//verify the if the mouse is on a particule //This func need be init in update function, //(i.e. obj.isOn(mouseX,mouseY)) calling to mouse positions; if(ofDist(X,Y,xMouse,yMouse)<tamano)isOnn = true; }