void setup() { useSharedData(); data.setup(ofGetWidth(), ofGetHeight(), 8); historyMesh.setMode(OF_PRIMITIVE_POINTS); dataMesh.setMode(OF_PRIMITIVE_POINTS); neighborsMesh.setMode(OF_PRIMITIVE_POINTS); }
void ofxNDCircularGradient(float radius, const ofColor & start, const ofColor & end) { int n = 32; // circular gradient resolution static ofMesh _nd_cg_mesh; _nd_cg_mesh.clear(); _nd_cg_mesh.setMode(OF_PRIMITIVE_TRIANGLE_FAN); ofVec2f center(0,0); _nd_cg_mesh.addVertex(center); float angleBisector = TWO_PI / (n * 2); float smallRadius = radius; float bigRadius = smallRadius / cos(angleBisector); for(int i = 0; i <= n; i++) { float theta = i * TWO_PI / n; _nd_cg_mesh.addVertex(center + ofVec2f(sin(theta), cos(theta)) * bigRadius); } _nd_cg_mesh.clearColors(); _nd_cg_mesh.addColor(start); for(int i = 0; i <= n; i++) { _nd_cg_mesh.addColor(end); } _nd_cg_mesh.draw(); }
//--------------------------------------------------------- void ofxPolyline::createMeshBevelJoint(ofMesh &mesh, int begin, int end) { mesh.setMode(OF_PRIMITIVE_TRIANGLES); // Starting point pair<ofVec2f, ofVec2f> jb1 = jointBegin((*this)[begin], (*this)[begin+1], width); pair<vector<ofVec2f>, vector<ofVec2f> > jb2 = bevelJoint((*this)[begin], (*this)[begin+1], (*this)[begin+2], width); mesh.addVertex(jb1.first); mesh.addVertex(jb1.second); mesh.addVertex(jb2.first.front()); mesh.addVertex(jb1.second); mesh.addVertex(jb2.first.front()); mesh.addVertex(jb2.second.front()); // Between both ends for (int i=begin+1; i<end-1; i++) { pair<vector<ofVec2f>, vector<ofVec2f> > j1 = bevelJoint((*this)[i-1], (*this)[i], (*this)[i+1], width); pair<vector<ofVec2f>, vector<ofVec2f> > j2 = bevelJoint((*this)[i], (*this)[i+1], (*this)[i+2], width); // triangle of bevel joint for (int i=0; i<j1.first.size(); i++) { mesh.addVertex(j1.first[i]); } for (int i=0; i<j1.second.size(); i++) { mesh.addVertex(j1.second[i]); } // the two points of the bevel triangle + next left point mesh.addVertex(j1.first.back()); mesh.addVertex(j1.second.back()); mesh.addVertex(j2.first.front()); // right point of the bevel triangle + next left point mesh.addVertex(j1.second.back()); mesh.addVertex(j2.first.front()); mesh.addVertex(j2.second.front()); } // End point pair<vector<ofVec2f>, vector<ofVec2f> > je1 = bevelJoint((*this)[end-2], (*this)[end-1], (*this)[end], width); pair<ofVec2f, ofVec2f> je2 = jointEnd((*this)[end-1], (*this)[end], width); for (int i=0; i<je1.first.size(); i++) { mesh.addVertex(je1.first[i]); } for (int i=0; i<je1.second.size(); i++) { mesh.addVertex(je1.second[i]); } mesh.addVertex(je1.first.back()); mesh.addVertex(je1.second.back()); mesh.addVertex(je2.first); mesh.addVertex(je1.second.back()); mesh.addVertex(je2.first); mesh.addVertex(je2.second); }
void ofxPolyline::createMesh(ofMesh &mesh, int begin, int end) { if (end - begin == 1) { // If only two points, just make a line. mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP); pair<ofVec2f, ofVec2f> joint = jointBegin((*this)[begin], (*this)[end], width); mesh.addVertex(joint.first); mesh.addVertex(joint.second); joint = jointEnd((*this)[begin], (*this)[end], width); mesh.addVertex(joint.first); mesh.addVertex(joint.second); return; } else if (end - begin == 0) { // Return no mesh return; } // More than two points if (strokeLinejoin == OFXSVG_STROKE_LINEJOIN_MITER) { createMeshMiterJoint(mesh, begin, end); } else if (strokeLinejoin == OFXSVG_STROKE_LINEJOIN_BEVEL) { createMeshBevelJoint(mesh, begin, end); } else if (strokeLinejoin == OFXSVG_STROKE_LINEJOIN_ROUND) { createMeshRoundJoint(mesh, begin, end); } }
void setup() { vid.initGrabber(w, h); mesh.setMode(OF_PRIMITIVE_POINTS); mesh.addVertices(vector<ofVec3f>(n)); mesh.addColors(vector<ofFloatColor>(n)); }
void BGGraphics::pushCirclePart(ofMesh& mesh, ofVec2f position, float nodeRadius, float minAngle, float deltaAngle) { mesh.setMode(OF_PRIMITIVE_TRIANGLES); pushVertex(mesh, position.x, position.y, 1, 0, 0, 1, 0, 0); float innerRadius = nodeRadius - NETWORK_OFFSET; float internalOffsetY = .5;// innerRadius / nodeRadius; int samples = (int)(15 * deltaAngle / M_PI); samples = max(1, samples); for(int i=0; i<samples; ++i) { float angle = minAngle + deltaAngle * i / (float)(samples - 1); ofVec2f to(cosf(angle), sinf(angle)); ofVec2f p1 = position + to * innerRadius; ofVec2f p2 = position + to * nodeRadius; //pushVertex(ofMesh & mesh, float x, float y, float z, float nx, float ny, float nz, float offsetX, float offsetY) pushVertex(mesh, p1.x, p1.y, 1, 0, 0, 1, 0, internalOffsetY); pushVertex(mesh, p2.x, p2.y, 0, to.x, to.y, 0, 0, 1); if(i > 0) { int offset = 1 + 2 * i; mesh.addTriangle(0, offset - 2, offset); mesh.addTriangle(offset - 2, offset - 1, offset); mesh.addTriangle(offset - 1, offset, offset + 1); } } }
void update() { int n = mesh.getNumVertices(); int start = ofMap(mouseX, 0, ofGetWidth(), 0, n, true); controlPoints.clear(); controlPoints.setMode(OF_PRIMITIVE_POINTS); for(int i = start; i < n; i++) { unsigned int index = rankedCorners[i]; controlPoints.addVertex(mesh.getVertex(index)); } }
//-------------------------------------------------------------- ofMesh testApp::pixelManipulate(ofImage imageA, ofMesh meshA, float intensityThreshold, float sketchDepth){ imageA.resize(200, 200); //create mesh with points as the primitive //meshA.setMode(OF_PRIMITIVE_POINTS); //create a mesh with lines meshA.setMode(OF_PRIMITIVE_LINE_LOOP); //meshA.setMode(OF_PRIMITIVE_LINE_STRIP); int w = imageA.getWidth(); int h = imageA.getHeight(); //loop through each pixel in the image using image width & height for (int x=0; x<w; x++){ for(int y=0; y<h; y++){ //create the color object at that pixel //ofColor c = imageA.getColor(x, y); ofColor c = imageA.getColor(x, y); //check the intensity of the pixel's color float intensity = c.getLightness(); //if the intensity exceeds the threshold, create a vertex at the location of the pixel //& color it with the pixel's color if (intensity >= intensityThreshold){ //pushes brighter colors in the positive z direction //pushes whiter colors in the negative z direction float saturation = c.getSaturation(); float z = ofMap(saturation, 0, 255, -sketchDepth, sketchDepth); //the image is now 1/4 the size of the OF window, so multiply //the pixel location by 4 so that the mesh covers the OF window ofVec3f pos(5*x, 4*y, z); meshA.addVertex(pos); meshA.addColor(c); } } } return meshA; }
//-------------------------------------------------------------- static void aiMeshToOfMesh(const aiMesh* aim, ofMesh& ofm, ofxAssimpMeshHelper * helper = NULL){ // default to triangle mode ofm.setMode(OF_PRIMITIVE_TRIANGLES); // copy vertices for (int i=0; i < (int)aim->mNumVertices;i++){ ofm.addVertex(ofVec3f(aim->mVertices[i].x,aim->mVertices[i].y,aim->mVertices[i].z)); } if(aim->HasNormals()){ for (int i=0; i < (int)aim->mNumVertices;i++){ ofm.addNormal(ofVec3f(aim->mNormals[i].x,aim->mNormals[i].y,aim->mNormals[i].z)); } } // aiVector3D * mTextureCoords [AI_MAX_NUMBER_OF_TEXTURECOORDS] // just one for now if(aim->GetNumUVChannels()>0){ for (int i=0; i < (int)aim->mNumVertices;i++){ if( helper != NULL && helper->texture.getWidth() > 0.0 ){ ofVec2f texCoord = helper->texture.getCoordFromPercent(aim->mTextureCoords[0][i].x ,aim->mTextureCoords[0][i].y); ofm.addTexCoord(texCoord); }else{ ofm.addTexCoord(ofVec2f(aim->mTextureCoords[0][i].x ,aim->mTextureCoords[0][i].y)); } } } //aiColor4D * mColors [AI_MAX_NUMBER_OF_COLOR_SETS] // just one for now if(aim->GetNumColorChannels()>0){ for (int i=0; i < (int)aim->mNumVertices;i++){ ofm.addColor(aiColorToOfColor(aim->mColors[0][i])); } } for (int i=0; i <(int) aim->mNumFaces;i++){ if(aim->mFaces[i].mNumIndices>3){ ofLog(OF_LOG_WARNING,"non-triangular face found: model face # " + ofToString(i)); } for (int j=0; j<(int)aim->mFaces[i].mNumIndices; j++){ ofm.addIndex(aim->mFaces[i].mIndices[j]); } } ofm.setName(string(aim->mName.data)); // ofm.materialId = aim->mMaterialIndex; }
void CloudsVisualSystemNbody::meshFromFbo(ofFbo& fbo, ofMesh& mesh){ mesh.addTexCoord(ofVec2f(0,0)); mesh.addVertex(ofVec3f(0,0,0)); mesh.addTexCoord(ofVec2f(fbo.getWidth(),0)); mesh.addVertex(ofVec3f(fbo.getWidth(),0,0)); mesh.addTexCoord(ofVec2f(0,fbo.getHeight())); mesh.addVertex(ofVec3f(0,fbo.getHeight(),0)); mesh.addTexCoord(ofVec2f(fbo.getWidth(),fbo.getHeight())); mesh.addVertex(ofVec3f(fbo.getWidth(),fbo.getHeight(),0)); mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP); }
void texturedRect(float width, float height) { if(texturedRectMesh.getNumVertices() == 0) { texturedRectMesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP); texturedRectMesh.addTexCoord(ofVec2f(0, 0)); texturedRectMesh.addVertex(ofVec2f(0, 0)); texturedRectMesh.addTexCoord(ofVec2f(0, 1)); texturedRectMesh.addVertex(ofVec2f(0, 1)); texturedRectMesh.addTexCoord(ofVec2f(1, 0)); texturedRectMesh.addVertex(ofVec2f(1, 0)); texturedRectMesh.addTexCoord(ofVec2f(1, 1)); texturedRectMesh.addVertex(ofVec2f(1, 1)); } ofPushMatrix(); ofScale(width, height); texturedRectMesh.drawFaces(); ofPopMatrix(); }
//--------------------------------------------------------- void ofxPolyline::createMeshMiterJoint(ofMesh &mesh, int begin, int end) { mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP); // Starting point pair<ofVec2f, ofVec2f> joint = jointBegin((*this)[begin], (*this)[begin+1], width); mesh.addVertex(joint.first); mesh.addVertex(joint.second); // Between both ends for (int i=begin+1; i<end-1; i++) { joint = miterJoint((*this)[i-1], (*this)[i], (*this)[i+1], width); mesh.addVertex(joint.first); mesh.addVertex(joint.second); } // End point joint = jointEnd((*this)[end-1], (*this)[end], width); mesh.addVertex(joint.first); mesh.addVertex(joint.second); }
//--------------------------------------------------------------------- static void prepareBitmapTexture(){ if (!bBitmapTexturePrepared){ myLetterPixels.allocate(16*16, 16*16, 4); // letter size:8x14pixels, texture size:16x8letters, gl_rgba: 4bytes/1pixel myLetterPixels.set(0); bitmappedFontTexture.allocate(16*16, 16*16, GL_RGBA, false); bBitmapTexturePrepared = true; for (int i = 0; i < 256; i++) { const unsigned char * face = bmpChar_8x13_Map[i]; for (int j = 1; j < 15; j++){ for (int k = 0; k < 8; k++){ if ( ((face[15-j] << k) & (128)) > 0 ){ myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4] = 255; myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4+1] = 255; myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4+2] = 255; myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4+3] = 255; }else{ myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4] = 0; myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4+1] = 0; myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4+2] = 0; myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4+3] = 0; } } } } bitmappedFontTexture.loadData(myLetterPixels); bitmappedFontTexture.setTextureMinMagFilter(GL_LINEAR,GL_NEAREST); charMesh.setMode(OF_PRIMITIVE_TRIANGLES); } }
//---------------------------------------------------------- void ofTessellator::performTessellation(ofPolyWindingMode polyWindingMode, ofMesh& dstmesh, bool bIs2D ) { if (!tessTesselate(cacheTess, polyWindingMode, TESS_POLYGONS, 3, 3, 0)){ ofLogError("ofTessellator") << "performTessellation(): mesh polygon tessellation failed, winding mode " << polyWindingMode; return; } int numVertices = tessGetVertexCount( cacheTess ); int numIndices = tessGetElementCount( cacheTess )*3; dstmesh.clear(); dstmesh.addVertices((ofDefaultVertexType*)tessGetVertices(cacheTess),numVertices); dstmesh.addIndices((ofIndexType*)tessGetElements(cacheTess),numIndices); /*ofIndexType * tessElements = (ofIndexType *)tessGetElements(cacheTess); for(int i=0;i<numIndices;i++){ if(tessElements[i]!=TESS_UNDEF) dstmesh.addIndex(tessElements[i]); }*/ dstmesh.setMode(OF_PRIMITIVE_TRIANGLES); }
void ofApp::createSegmentedMeshTriangles(const ofVec3f& center, ofMesh &mesh, double radius, double limitH, int textWidth, int textHeight) //using triangles only { int h, drawH, drawW, w; int divNumber = 32; double theta, phi, phi_1, limitW; ofVec3f p; mesh.clear(); //Handle special cases if (radius < 0) radius = -radius; if (precision < 0) precision = -precision; if (precision < 4 || radius <= 0) { mesh.addVertex(center); return; } mesh.setMode(OF_PRIMITIVE_TRIANGLES); //limitH = 3.14 / (double) hDivNumber; limitW = limitH * (textWidth/(double)textHeight); drawH = textHeight / divNumber; drawW = textWidth / divNumber; for(h = 0; h < drawH; h++) //create the mesh { phi = (((h * divNumber) * limitH)/(double) textHeight) + (1.57079632679 - (limitH/ (double )2)); //phi_1 = (((h+1) * limitH)/(double) textHeight) + (1.57079632679 - (limitH/ (double )2)); for(w = 1; w <= drawW; w++) //count forward { theta = (limitW * (w * divNumber)) / (double) textWidth + (1.57079632679 - (limitW/ (double )2)); p.x = radius*cos(theta)*sin(phi); p.y = radius* sin(theta)*sin(phi); p.z = radius*cos(phi); /*p.x = w; p.y = 2; p.z = h;*/ mesh.addTexCoord(ofVec2f((w*divNumber), (h*divNumber))); mesh.addVertex(p); } } /*for (int y = 0; y<drawH; y = y+1){ for (int x=0; x<drawW; x = x + 1){ const ofIndexType texIndex = static_cast<ofIndexType>(x + y*drawW); mesh.setTexCoord(texIndex, ofVec2f((w*divNumber), (h*divNumber))); } }*/ //mesh.clearIndices(); for (int y = 0; y<drawH-1; y = y+1){ for (int x=0; x<drawW-1; x++){ mesh.addIndex(x+y*drawW); // 0 mesh.addIndex(x+(y+1)*drawW); // 10 mesh.addIndex((x+1)+(y+1)*drawW); // 11 // mesh.addIndex(x); // 0 //mesh.addIndex(x+drawW); // 10 //mesh.addIndex((x+1)+drawW); // 11 mesh.addIndex((x+1)+y*drawW); // 1 mesh.addIndex(x+y*drawW); // 0 mesh.addIndex((x+1)+(y+1)*drawW); // 11 } } }
//--------------------------------------------------------- void ofxPolyline::createMeshRoundJoint(ofMesh &mesh, int begin, int end) { // Starting point pair<ofVec2f, ofVec2f> jb1 = jointBegin((*this)[begin], (*this)[begin+1], width); pair<vector<ofVec2f>, vector<ofVec2f> > jb2 = roundJoint((*this)[begin], (*this)[begin+1], (*this)[begin+2], width); mesh.addVertex(jb1.first); mesh.addVertex(jb1.second); mesh.addVertex(jb2.first.front()); mesh.addVertex(jb1.second); mesh.addVertex(jb2.first.front()); mesh.addVertex(jb2.second.front()); // Between both ends for (int i=begin+1; i<end-1; i++) { mesh.setMode(OF_PRIMITIVE_TRIANGLES); pair<vector<ofVec2f>, vector<ofVec2f> > j1, j2; j1 = roundJoint((*this)[i-1], (*this)[i], (*this)[i+1], width); j2 = roundJoint((*this)[i], (*this)[i+1], (*this)[i+2], width); // Triangles representing a circular sector of the round joint if (j1.first.size() == 1) { for (int i=0; i<j1.second.size()-1; i++) { mesh.addVertex(j1.first.front()); mesh.addVertex(j1.second[i]); mesh.addVertex(j1.second[i+1]); } } else { for (int i=0; i<j1.first.size()-1; i++) { mesh.addVertex(j1.second.front()); mesh.addVertex(j1.first[i]); mesh.addVertex(j1.first[i+1]); } } // the last two points of the round joint // + the next left point of the next round joint mesh.addVertex(j1.first.back()); mesh.addVertex(j1.second.back()); mesh.addVertex(j2.first.front()); // the last right point + two point of the next round joint mesh.addVertex(j1.second.back()); mesh.addVertex(j2.first.front()); mesh.addVertex(j2.second.front()); } // End point pair<vector<ofVec2f>, vector<ofVec2f> > je1 = roundJoint((*this)[end-2], (*this)[end-1], (*this)[end], width); pair<ofVec2f, ofVec2f> je2 = jointEnd((*this)[end-1], (*this)[end], width); if (je1.first.size() == 1) { for (int i=0; i<je1.second.size()-1; i++) { mesh.addVertex(je1.first.front()); mesh.addVertex(je1.second[i]); mesh.addVertex(je1.second[i+1]); } } else { for (int i=0; i<je1.first.size()-1; i++) { mesh.addVertex(je1.second.front()); mesh.addVertex(je1.first[i]); mesh.addVertex(je1.first[i+1]); } } mesh.addVertex(je1.first.back()); mesh.addVertex(je1.second.back()); mesh.addVertex(je2.first); mesh.addVertex(je1.second.back()); mesh.addVertex(je2.first); mesh.addVertex(je2.second); }
void getCellMesh(voro::voronoicell &_c, ofPoint _pos, ofMesh& mesh ){ if( _c.p ) { ofPoint centroid = getCellCentroid(_c,_pos); int i,j,k,l,m,n; // Vertex // double *ptsp=_c.pts; vector<ofPoint> vertices; vector<ofPoint> normals; for(i = 0; i < _c.p; i++, ptsp+=3){ ofPoint newPoint; newPoint.x = _pos.x + ptsp[0]*0.5; newPoint.y = _pos.y + ptsp[1]*0.5; newPoint.z = _pos.z + ptsp[2]*0.5; vertices.push_back(newPoint); ofPoint newNormal; newNormal = _pos - newPoint;//centroid ; newNormal = newNormal.normalize(); normals.push_back(newNormal); } // ofMesh mesh; mesh.setMode(OF_PRIMITIVE_TRIANGLES ); mesh.addVertices(vertices); mesh.addNormals(normals); // Index // for(i = 1; i < _c.p; i++){ for(j = 0; j < _c.nu[i]; j++) { k = _c.ed[i][j]; if( k >= 0 ) { _c.ed[i][j]=-1-k; l = _c.cycle_up( _c.ed[i][ _c.nu[i]+j], k); m = _c.ed[k][l]; _c.ed[k][l]=-1-m; while(m!=i) { n = _c.cycle_up( _c.ed[k][ _c.nu[k]+l],m); mesh.addTriangle(i, k, m); k=m; l=n; m=_c.ed[k][l]; _c.ed[k][l]=-1-m; } } } } // return mesh; } // return ofMesh(); };
void ofApp::createSegmentedMesh(const ofVec3f& center, ofMesh &mesh, double radius, int precision, int textWidth, int textHeight, double theta1, double theta2, double phi1, double phi2) { /* original funtion used as inspiration Create a sphere centered at c, with radius r, and precision n Draw a point for zero radius spheres Use CCW facet ordering Partial spheres can be created using theta1->theta2, phi1->phi2 in radians 0 < theta < 2pi, -pi/2 < phi < pi/2 */ int i,j; double t1,t2,t3; ofVec3f e,p; mesh.clear(); /* Handle special cases */ if (radius < 0) radius = -radius; if (precision < 0) precision = -precision; if (precision < 4 || radius <= 0) { mesh.addVertex(center); return; } for (j=0;j<precision/2;j++) { t1 = phi1 + j * (phi2 - phi1) / (precision/2); t2 = phi1 + (j + 1) * (phi2 - phi1) / (precision/2); mesh.setMode(OF_PRIMITIVE_POINTS ); //mesh.setMode( OF_PRIMITIVE_LINE_STRIP); for (i=0;i<=precision;i++) { t3 = theta1 + i * (theta2 - theta1) / precision; e.x = cos(t1) * cos(t3); e.y = sin(t1); e.z = cos(t1) * sin(t3); p.x = center.x + radius * e.x; p.y = center.y + radius * e.y; p.z = center.z + radius * e.z; mesh.addNormal(e); mesh.addTexCoord(ofVec2f( (i/(double)precision) * textWidth, textHeight - (2*j/(double)precision) * textHeight)); mesh.addVertex(p); e.x = cos(t2) * cos(t3); e.y = sin(t2); e.z = cos(t2) * sin(t3); p.x = center.x + radius * e.x; p.y = center.y + radius * e.y; p.z = center.z + radius * e.z; mesh.addNormal(e); mesh.addTexCoord(ofVec2f( (i/(double)precision) * textWidth, textHeight - (2*(j+1)/(double)precision) * textHeight)); mesh.addVertex(p); } } }
/* Old, beta function, use the triangle funtion now */ void ofApp::createSegmentedMeshMine(const ofVec3f& center, ofMesh &mesh, double radius, int textWidth, int textHeight) { //uses triangle strips int h, hTemp, w; double theta, phi, phi_1, limitH, limitW; ofVec3f p; mesh.clear(); //Handle special cases if (radius < 0) radius = -radius; if (precision < 0) precision = -precision; if (precision < 4 || radius <= 0) { mesh.addVertex(center); return; } //mesh.setupIndicesAuto(); textWidth = textWidth / 4; textHeight = textHeight / 4; mesh.setMode( OF_PRIMITIVE_TRIANGLE_STRIP); limitH = 3.14 / (double) 3; limitW = limitH * (textWidth/(double)textHeight); for(hTemp = 0; hTemp < textHeight-1; hTemp = hTemp+2) { h = hTemp; //phi = (h * 3.141)/(double) textHeight; //phi_1 = ((h+1) * 3.141)/(double) textHeight; phi = ((h * limitH)/(double) textHeight) + (1.57079632679 - (limitH/ (double )2)); phi_1 = (((h+1) * limitH)/(double) textHeight) + (1.57079632679 - (limitH/ (double )2)); for(w = 0; w <= textWidth; w++) //count forward { theta = (limitW * w) / (double) textWidth + (1.57079632679 - (limitW/ (double )2)); // p.x = radius * cos(theta); //p.y = h; //p.z = radius * sin(theta); p.x = radius*cos(theta)*sin(phi); p.y = radius* sin(theta)*sin(phi); p.z = radius*cos(phi); mesh.addTexCoord(ofVec2f(4*w, 4*h)); mesh.addVertex(p); //p.x = radius *cos(theta); //p.y = h+1; //p.z = radius * sin(theta); p.x = radius*cos(theta)*sin(phi_1); p.y = radius* sin(theta)*sin(phi_1); p.z = radius*cos(phi_1); mesh.addTexCoord(ofVec2f(4*w, (4*h)+1)); mesh.addVertex(p); } h = hTemp+1; phi = ((h * limitH)/(double) textHeight) + (1.57079632679 - (limitH/ (double )2)); phi_1 = (((h+1) * limitH)/(double) textHeight) + (1.57079632679 - (limitH/ (double )2)); for(w = textWidth; w>=0; w--) //count backwards { theta = (limitW * w) / (double) textWidth + (1.57079632679 - (limitW/ (double )2)); p.x = radius*cos(theta)*sin(phi); p.y = radius* sin(theta)*sin(phi); p.z = radius*cos(phi); mesh.addTexCoord(ofVec2f(w, h)); mesh.addVertex(p); p.x = radius*cos(theta)*sin(phi_1); p.y = radius* sin(theta)*sin(phi_1); p.z = radius*cos(phi_1); mesh.addTexCoord(ofVec2f(w, h+1)); mesh.addVertex(p); } } }
void ofxPuppet::setup(ofMesh & mesh){ mesh.setMode(OF_PRIMITIVE_TRIANGLES); originalMesh = mesh, deformedMesh = mesh; deformer.InitializeFromMesh( &originalMesh ); needsUpdating = true; }
//-------------------------------------------------------------- void ofApp::setup(){ beat.load("sound/heartbeat.mp3"); mizukusa.load("mizukusa.png"); // for that purpose: fftSmoothed = new float[8192]; for (int i = 0; i < 8192; i++){ fftSmoothed[i] = 0; } nBandsToGet = 128; ofSetFrameRate(60); model.loadModel("untitled.obj"); ofEnableLighting(); ofEnableAlphaBlending(); material.setShininess(255); material.setDiffuseColor(ofColor(255,255,255)); material.setSpecularColor(ofColor(255,255,0)); material.setAmbientColor(ofColor(255,0,0)); mesh = model.getMesh(0); for (int i=0; i < model.getMeshCount();i++){ heart.push_back(model.getMesh(i)); } pointLight2.setDiffuseColor( ofFloatColor(.85, .0, .0) ); pointLight2.setSpecularColor( ofFloatColor(1.f, 1.f, 0.6f)); pointLight.setDiffuseColor( ofFloatColor(.85, .0, .0) ); pointLight.setSpecularColor( ofFloatColor(1.f, 1.f, 0.6f)); // mesh.setMode(OF_PRIMITIVE_TRIANGLES); vector<ofMeshFace> triangles = mesh.getUniqueFaces(); mesh.setFromTriangles(triangles,true); for(int i=0; i < model.getMeshCount();i++){ //heart[i].setMode(OF_PRIMITIVE_TRIANGLES); vector<ofMeshFace> triangles = heart[i].getUniqueFaces(); heart[i].setFromTriangles(triangles,true); } //clone object heart_ = heart; ofSetBackgroundColor(0); cam.setDistance(500.0f); heart_vertices= heart[0].getVertices(); for(int i=0; i < 3;i++){ for(int j=0; j < heart[i].getNumVertices(); j+=10){ //heart[i].setVertex(j,heart_[i].getVertex(j)*(ofNoise(ofGetFrameNum()/100.0f,j)*0.1+1)); ofVec3f v = heart[i].getVertex(j); vector <int> list; for(int k=0; k < heart[i].getNumVertices(); k++){ if(v.distance(heart[i].getVertex(k))<0.1){ list.push_back(k); } } nearest.push_back(list); } } myFbo.allocate(ofGetWidth(),ofGetHeight()); myGlitch.setup(&myFbo); beat.play(); for(int i=0; i <6;i++){ noises.push_back(0.0); } for(int i=0; i<IMG_SIZE; i++){ ofImage img; img.load("img"+ofToString(i)+".png"); images.push_back(img); } }