コード例 #1
0
VoroNode::VoroNode(ofVboMesh _mesh, VoroNode& vnParent) {
    counter++;
    isSplit = false;
    bDraw = true;
    
    level = vnParent.level+1;
    
    // make the mesh vertices local for the node
    // move th relative position to the nodes position
    // transformations on the unit are around the centroid of the mesh not the centroid of the parent
    mesh = _mesh;
    setPosition(mesh.getCentroid());
    
    for(int i=0; i<_mesh.getNumVertices(); i++) {
        mesh.setVertex(i,  _mesh.getVertex(i)-_mesh.getCentroid());
    }
    
    mesh.setupIndicesAuto();
    mesh.getVbo();
    
    calculateBoundingBox();
    
    setParent(vnParent);
    
};
コード例 #2
0
ファイル: form.cpp プロジェクト: jftesser/blobs
void form::addMesh(ofVboMesh &_mesh) {
    vector<ofVec3f> ns = _mesh.getNormals();
    vector<unsigned int> inds = _mesh.getIndices();
    vector<ofVec3f> vs = _mesh.getVertices();
    for (int i=0; i<inds.size();i+=3) {
        mExporter.addTriangle(vs[inds[i]], vs[inds[i+1]], vs[inds[i+2]], ofPoint(0,0,0));
    }
}
コード例 #3
0
ファイル: ofApp.cpp プロジェクト: autofasurer/ofxEquiMap
 void drawEquiScene()
 {
     ofPushStyle();
     ofSetLineWidth(3);
     ofSetColor(192);
     m.drawWireframe();
     ofPopStyle();
 }
コード例 #4
0
//--------------------------------------------------------------
void ofApp::setup(){
    ofEnableSmoothing();
    ofBackground(0);
    
    pVec.clear();
    delauMesh.clear();
    for (int i = 0; i < N; i++) {
        pVec.push_back(ofVec2f(ofRandom(ofGetWidth()), ofRandom(ofGetHeight())));
    }
    
    
    for(int i = 0; i < N-2; i++) {
        ofVec2f v1 = pVec[i];
        for(int j = i+1; j < N-1; j++) {
            ofVec2f v2 = pVec[j];
            for(int k = j+1; k < N; k++) {
                ofVec2f v3 = pVec[k];
                
                float tmp = 2.0*((v2.x-v1.x)*(v3.y-v1.y)-(v2.y-v1.y)*(v3.x-v1.x));
                ofVec2f center = ofVec2f(
                                         ((v3.y-v1.y)*(v2.x*v2.x-v1.x*v1.x+v2.y*v2.y-v1.y*v1.y)+
                                          (v1.y-v2.y)*(v3.x*v3.x-v1.x*v1.x+v3.y*v3.y-v1.y*v1.y))/tmp,
                                         ((v1.x-v3.x)*(v2.x*v2.x-v1.x*v1.x+v2.y*v2.y-v1.y*v1.y)+
                                          (v2.x-v1.x)*(v3.x*v3.x-v1.x*v1.x+v3.y*v3.y-v1.y*v1.y))/tmp
                                         );
                float r = ofDist(center.x,center.y, v1.x,v1.y) - 0.01;
                
                Boolean flg = false;
                for (int l = 0; l < N; l++) {
                    if (ofDist(center.x,center.y, pVec[l].x,pVec[l].y) < r) {
                        flg = true;
                        break;
                    }
                }
                ofFloatColor c = ofFloatColor( ofRandom(0.0,1.0), ofRandom(0.0,1.0), ofRandom(0.0,1.0) );
                if (!flg) {
                    //ofDrawLine(v1.x, v1.y, v2.x, v2.y);
                    //ofDrawLine(v2.x, v2.y, v3.x, v3.y);
                    //ofDrawLine(v3.x, v3.y, v1.x, v1.y);
                    delauMesh.addVertex(v1);
                    delauMesh.addColor(c);
                    delauMesh.addVertex(v2);
                    delauMesh.addColor(c);
                    delauMesh.addVertex(v3);
                    delauMesh.addColor(c);
                }
            }
        }
    }
    
}
コード例 #5
0
ファイル: ofxVoro.cpp プロジェクト: arthurhunt7/ofxVoro
void getCellMesh(voro::voronoicell &_c, ofPoint _pos, ofVboMesh& _mesh, bool bWireframe){
    if( _c.p ) {
        
		if( !bWireframe ) {
			//  Extract Verteces
			//
			ofVboMesh mesh;
			mesh.setMode(OF_PRIMITIVE_TRIANGLES );
			mesh.addVertices(getCellVerteces(_c, _pos));
			
			//  Add triangles using Indeces
			//
			int k,l,m,n;
			for(int i = 1; i < _c.p; i++){
				for(int 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;
						}
					}
				}
			}
			
			//  Calculate Normals
			//
			_mesh.setMode(OF_PRIMITIVE_TRIANGLES);
			vector<ofMeshFace> faces = mesh.getUniqueFaces();
			for (int i = 0; i < faces.size(); i++) {
				ofMeshFace face = faces[i];
				ofPoint a = face.getVertex(0);
				ofPoint b = face.getVertex(1);
				ofPoint c = face.getVertex(2);
				
				ofPoint normal = ((b - a).cross(c - a)).normalize() * -1.;
				
                
				_mesh.addVertex(a);
				_mesh.addNormal(normal);
				
				_mesh.addVertex(b);
				_mesh.addNormal(normal);
				_mesh.addVertex(c);
				_mesh.addNormal(normal);
                
                // add texture coordinates
                if( i % 2 == 0) {
                    _mesh.addTexCoord(ofVec2f(0.0, 0.0));
                    _mesh.addTexCoord(ofVec2f(0.0, 1.0));
                    _mesh.addTexCoord(ofVec2f(1.0, 0.0));
                } else {
                    _mesh.addTexCoord(ofVec2f(1.0, 0.0));
                    _mesh.addTexCoord(ofVec2f(0.0, 1.0));
                    _mesh.addTexCoord(ofVec2f(1.0, 1.0));
                }
                
                
			}
		} else { // wireframe
			_mesh.setMode(OF_PRIMITIVE_LINES);
			_mesh.addVertices(getCellVerteces(_c, _pos));
			for(int i = 1; i < _c.p; i++){
				for(int j = 0; j < _c.nu[i]; j++) {
					
					int k = _c.ed[i][j];
					
					if( k >= 0 ) {
						_mesh.addIndex(i);
						_mesh.addIndex(k);
					}
				}
			}
		}
    }
}
コード例 #6
0
//--------------------------------------------------------------
void ofApp::draw(){
    delauMesh.setMode(OF_PRIMITIVE_TRIANGLES);
    delauMesh.draw();
}
コード例 #7
0
ファイル: testApp.cpp プロジェクト: MrMDeluxe/generative
//--------------------------------------------------------------
void testApp::setup(){
    
    ofBackground(0);
    ofSetFrameRate(30);
    ofEnableAlphaBlending();
    //    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //    glEnable(GL_DEPTH_TEST);
    glPointSize(1.0);
    drawFBO = false;
    autoRotate = true;
    drawEQ = false;
    
    //not really needed
    //    glEnable(GL_ALPHA_TEST);
    //    glAlphaFunc(GL_GREATER, 0.10f);
    
    //generate the mesh points
    buildSphereMesh(rad, res, vm);
    cout << "nverts: " << vm.getNumVertices() << endl;
    cout << "arb: " << ofGetUsingArbTex() << ", norm: " << ofGetUsingNormalizedTexCoords() << endl;
    
    //load the texture shader
    shader.load("tex.vert", "tex.frag");
    
    //fft init
    fftSmoothed = new float[8192];
    memset(fftSmoothed, 0x00, sizeof(float) * 8192);
    
    //map the frequencies to bark bands
    float freq_spc = FREQ_MAX / (float)SPECTRAL_BANDS;
    
	for (int i = 0; i < SPECTRAL_BANDS; i++) {
        int bidx = bark(i * freq_spc);
        barkmap[i] = bidx;
    }
    
    //load the position updating frag shader
    pos_shader.load("", "position.frag");
    
    //for the sphere we set this to the resolution which = #of verts along each axis
    fbo_res = res;
    
    //init the fbo's with blank data
    vector<ofVec3f> fbo_init_data;
    fbo_init_data.assign(fbo_res * fbo_res, ofVec3f(0.0, 0.0, 0.0));
    
    posbuf.allocate(fbo_res, fbo_res, GL_RGB32F);
    posbuf.src->getTextureReference().loadData((float *)&fbo_init_data[0], fbo_res, fbo_res, GL_RGB);
    posbuf.dst->getTextureReference().loadData((float *)&fbo_init_data[0], fbo_res, fbo_res, GL_RGB);
    
    //reuse fbo_init_data for no real reason, it just needs to be blank
    eq_tex.allocate(fbo_res, 1, GL_RGB32F_ARB);
    eq_tex.loadData((float *)&fbo_init_data[0], fbo_res, 1, GL_RGB);
    
    axis_loc = fbo_res;
    angincr = 180.0/(float)fbo_res;

    player.loadSound("jhfd.mp3");
    
    player.play(); //go
}
コード例 #8
0
ファイル: testApp.cpp プロジェクト: MrMDeluxe/generative
//--------------------------------------------------------------
void testApp::draw(){
    
    //curve eq
    if (drawEQ) {
        ofPushMatrix();
        ofTranslate(600, ofGetHeight() - 50);
        ofMesh eq_mesh = eq_path.getTessellation();
        eq_mesh.drawVertices();
        ofPopMatrix();
    }
    
    /* see what the fbo has in it */
    if (drawFBO) {
        ofPushMatrix();
        ofTranslate(50, 50);
        ofDrawBitmapString("FBO", 0, 0);
        ofPopMatrix();
        
        ofPushMatrix();
        ofTranslate(50, 70);
        posbuf.src->getTextureReference().bind();
        
        glBegin(GL_QUADS);
        glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
        glTexCoord2f(fbo_res, 0); glVertex3f(fbo_res, 0, 0);
        glTexCoord2f(fbo_res, fbo_res); glVertex3f(fbo_res, fbo_res, 0);
        glTexCoord2f(0, fbo_res); glVertex3f(0, fbo_res, 0);
        glEnd();
        
        posbuf.src->getTextureReference().unbind();
        ofPopMatrix();
    }
    
    //actual sphere
    
    ofPushMatrix();
    ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
    
    cam.begin();
    
    if (autoRotate) {
        ofRotateY(-30);
        ofRotateX(ang += angincr);
        ofRotateZ(ofGetFrameNum() * 0.005);
    } else {
        ofRotateX(0.0);
        ofRotateY(0.0);
        ofRotateZ(0.0);
    }
    
    glEnable(GL_POINT_SMOOTH);
    glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
    
    shader.begin();
    shader.setUniformTexture("u_OffMap", posbuf.src->getTextureReference(), 0);
    shader.setUniform1f("u_fboRes", (float)fbo_res);
    
    vm.drawVertices();
    
    shader.end();
    
    glDisable(GL_POINT_SMOOTH);
    
    cam.end();
    ofPopMatrix();
}
コード例 #9
0
// Mesh reference must be passed in
void testApp::addTexture(ofVboMesh& vboMesh, ofVec2f top, ofVec2f left, ofVec2f right) {
    vboMesh.addTexCoord(top);
    vboMesh.addTexCoord(left);
    vboMesh.addTexCoord(right);
}
コード例 #10
0
// Mesh reference must be passed in
void testApp::addFace(ofVboMesh& vboMesh, ofVec3f top, ofVec3f left, ofVec3f right) {
    vboMesh.addVertex(top);
    vboMesh.addVertex(left);
    vboMesh.addVertex(right);
}