예제 #1
0
//--------------------------------------------------------------
ofMesh pen::createCircle(float x, float y, float radius, ofColor color){
    
    float sides = 30;
    ofMesh mesh;
	mesh.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
    
    color.setBrightness(ofRandom(100,250));
    
    for(int i=0; i<=sides; i++){
        
        float pointRatio = i/sides; 
        float xSteps = cos(pointRatio*2*PI);
        float ySteps = sin(pointRatio*2*PI);
        float pointX = x + xSteps * radius;
        float pointY = y + ySteps * radius;
        
        mesh.addVertex(ofPoint(pointX, pointY));
        mesh.addColor(color);
    }
    
    
    return mesh;
}
예제 #2
0
//--------------------------------------------------------------
ofMesh pen::lineToMesh(ofPolyline line,ofColor color, float thicknessOffset, ofVec2f positionOffset){ 
    ofMesh mesh;
    mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP); 
    vector<ofPoint> points = line.getVertices();
    
    int brightness = 255;
    
    for(int i = 1; i < points.size(); i++){
		ofVec2f thisPoint = ofVec2f(points[i-1].x,points[i-1].y);
		ofVec2f nextPoint = ofVec2f(points[i].x,points[i].y);
		ofVec2f direction = (nextPoint - thisPoint);
		float distance = direction.length();
        
		ofVec2f unitDirection = direction.normalized();
		ofVec2f toTheLeft = unitDirection.getRotated(-90);
		ofVec2f toTheRight = unitDirection.getRotated(90);
        
		float thickness = ofMap(thisPoint.y, 0, ofGetScreenHeight(), 5, 40);
        thickness += thicknessOffset;
        
        if (thicknessOffset == 0)
            color.setBrightness(ofMap(i, 0, points.size(), 250, 200));
        
		ofVec2f leftPoint = thisPoint+toTheLeft*thickness;
		ofVec2f rightPoint = thisPoint+toTheRight*thickness;
        
        if (thicknessOffset > 0 && i == 1){
            ofVec2f tempLeftPoint = leftPoint;
            ofVec2f tempRightPoint = rightPoint;
            
            tempLeftPoint -= unitDirection * (thickness/2);
            tempRightPoint -= unitDirection * (thickness/2);
            
            mesh.addVertex(ofVec2f(tempLeftPoint.x + positionOffset.x, tempLeftPoint.y + positionOffset.y));
            mesh.addColor(color);
            mesh.addVertex(ofVec2f(tempRightPoint.x + positionOffset.x, tempRightPoint.y + positionOffset.y));
            mesh.addColor(color);
        }
        
		mesh.addVertex(ofVec2f(leftPoint.x, leftPoint.y + positionOffset.y));
        mesh.addColor(color);
		mesh.addVertex(ofVec2f(rightPoint.x, rightPoint.y + positionOffset.y));
        mesh.addColor(color);
        
        if (thicknessOffset > 0 && i == points.size()-1){
            
            leftPoint += unitDirection * (thickness/3) + positionOffset;
            rightPoint += unitDirection * (thickness/3) + positionOffset;
            
            mesh.addVertex(leftPoint);
            mesh.addColor(color);
            mesh.addVertex(rightPoint);
            mesh.addColor(color);
        }
        
        
        //Add arrow
        if (i == points.size()-1 ){
          
            leftPoint = thisPoint+toTheLeft*thickness*1.5;
            rightPoint = thisPoint+toTheRight*thickness*1.5;

            mesh.addVertex(leftPoint);
            mesh.addColor(color);
            
            mesh.addVertex(rightPoint);
            mesh.addColor(color);
     
            
            mesh.addVertex(nextPoint + unitDirection * thickness*2.5);
            mesh.addColor(color);
        }
        
        
    }
    
    return mesh;
}
예제 #3
0
//--------------------------------------------------------------
ofMesh pen::extrudeMesh(ofMesh mesh, ofColor color){ 
    
    ofMesh side; 
    float depth = 50; 
    color.setBrightness(250);
    
    vector<ofPoint> points = mesh.getVertices();
    int k;
    
    if (points.size() > 4){
        ofPoint p1 = points[0];
        ofPoint p2 = points[1];
        
        side.addVertex(p1);
        side.addColor(color);
        side.addVertex(p2);
        side.addColor(color);
        side.addVertex(ofPoint(p1.x, p1.y, p1.z-depth));
        side.addColor(color);
        side.addVertex(ofPoint(p1.x, p1.y, p1.z-depth));
        side.addColor(color);
        side.addVertex(ofPoint(p2.x, p2.y, p2.z-depth));
        side.addColor(color);
        side.addVertex(p2);
        side.addColor(color);
        
        for(k=0; k<points.size()-2; k++)
        {
            
            ofPoint p1 = points[k+0];
            ofPoint p2 = points[k+2];
            
            side.addVertex(p1);
            side.addColor(color);
            side.addVertex(p2);
            side.addColor(color);
            side.addVertex(ofPoint(p1.x+5, p1.y, p1.z-depth));
            side.addColor(color);
            if (ofRandom(0,25) < 1)
                color.setBrightness(ofMap(k, 0, points.size(), 100, 50));
            else 
                color.setBrightness(ofMap(k, 0, points.size(), 150, 100));
            side.addVertex(ofPoint(p1.x+5, p1.y, p1.z-depth));
            side.addColor(color);
            side.addVertex(ofPoint(p2.x+5, p2.y, p2.z-depth));
            side.addColor(color);
            side.addVertex(p2);
            side.addColor(color);
        }
        
        p1 = points[points.size()-2];
        p2 = points[points.size()-1];
        side.addVertex(p1);
        side.addColor(color);
        side.addVertex(p2);
        side.addColor(color);
        side.addVertex(ofPoint(p1.x, p1.y, p1.z-depth));
        side.addColor(color);
        side.addVertex(ofPoint(p1.x, p1.y, p1.z-depth));
        side.addColor(color);
        side.addVertex(ofPoint(p2.x, p2.y, p2.z-depth));
        side.addColor(color);
        side.addVertex(p2);
        side.addColor(color);
    }
    return side;
    
}