Chrisir
Full Member
Offline
Posts: 207
Germany
Re: 3d Sphere / Delaunay
Reply #8 - Jan 7th , 2010, 2:57pm
@Quark: I just used umbrella for an arrow with shaft and head - maybe something for your shapes import peasy.*; PeasyCam pCamera; void setup() { size(800, 600, P3D); background(0); stroke(112); fill(102); pCamera = new PeasyCam(this, 300); pCamera.lookAt(0,0,0,10); pCamera.setDistance(830); } void draw(){ background(0); Test_On_Arrow(); } // void void Test_On_Arrow () { Liner ( 310,200,10, 310,200,110 ); } // function void Liner(int z1, int x1, int y1, int z2, int x2, int y2 ){ // prepare Arrow final int diff=24; PVector MyPVector1 = new PVector(0, 0, 0); // from PVector MyPVector2 = new PVector(0, 0, 0); // to PVector ArrowVectorPosition= new PVector(0, 0, 0); PVector ArrowVectorRotate= new PVector(0, 0, 0); MyPVector1.set ( x1,y1,z1 ); MyPVector2.set ( x2,y2,z2 ); MyPVector1.y-=4; MyPVector2.y-=4; MyPVector2.y=MyPVector2.y-diff; ArrowVectorPosition.set(MyPVector2.x,MyPVector2.y+2,MyPVector2.z); ArrowVectorRotate.set (90,90,90); // paint arrow Arrow ( MyPVector1, MyPVector2, ArrowVectorPosition, ArrowVectorRotate, 2.0, 7.0, 110 ); } // void // ------------------------------------------------------------ // Arrow void Arrow ( PVector MyPVector1,PVector MyPVector2, PVector ArrowVectorPosition, PVector ArrowVectorRotate, float WeightShaft, float RadiusArrowHead, color Color ){ // here a lot could be simplified and optimized... // in Arrow, MyBox and Arrowhead // draws an arrow // Parameters: // MyPVector1 = from / Arrow shaft // MyPVector2 = To / Arrow shaft // ArrowVectorPosition = Arrow head Position // ArrowVectorRotate = Arrow head Rotation // WeightShaft = Weight for the Arrow shaft // RadiusArrow = radius for the Arrow head stroke( Color ); fill( Color ); // Shaft ArrowShaft( MyPVector1.x, MyPVector1.y, MyPVector1.z, MyPVector2.x, MyPVector2.y, MyPVector2.z, WeightShaft, Color ); // Arrow head pushMatrix(); translate(ArrowVectorPosition.x, ArrowVectorPosition.y, ArrowVectorPosition.z); rotateX (radians(ArrowVectorRotate.x)); rotateY (radians(ArrowVectorRotate.y)); rotateZ (radians(ArrowVectorRotate.z)); Arrowhead (RadiusArrowHead ); popMatrix(); } // void Arrow void ArrowShaft(float x1, float y1, float z1, float x2, float y2, float z2, float weight, color strokeColour){ // arrow shaft // was called drawLine; programmed by James Carruthers from the processing-forum // see http://processing.org/discourse/yabb2/num_1262458611.html#9 PVector p1 = new PVector(x1, y1, z1); PVector p2 = new PVector(x2, y2, z2); PVector v1 = new PVector(x2-x1, y2-y1, z2-z1); float rho = sqrt(pow(v1.x,2)+pow(v1.y,2)+pow(v1.z,2)); float phi = acos(v1.z/rho); float the = atan2(v1.y,v1.x); v1.mult(0.5); pushMatrix(); translate(x1,y1,z1); translate(v1.x, v1.y, v1.z); rotateZ(the); rotateY(phi); noStroke(); fill(strokeColour); box(weight,weight,p1.dist(p2)*1.2); popMatrix(); } // ArrowShaft void Arrowhead(float radius){ // Arrowhead // was umbrella from the processing-forum // float radius = 7.0; // 50.0; float rho = radius; float x, y, z, u, v; float phi; int phiSteps = 1; // 20; float phiFactor = HALF_PI / phiSteps; float theta; int thetaSteps = 4 ; // 20; float thetaFactor = TWO_PI / thetaSteps; // PVector[] sphereVertexPoints; // for closing the bottom of the arrow head // (towards the shaft) PVector[] BottomOfTheHead = new PVector [8]; // PImage skin; // noFill(); stroke(255); // fill(200, 130, 0); // stage lighting // directionalLight(255, 255, 255, -100, 100, -100); // ambientLight(120, 120, 120); phi = 0.0; for(int p = 0; p < phiSteps; p++) { beginShape(QUAD_STRIP); // texture(skin); theta = 0.0; for(int t = 0; t < thetaSteps + 1; t++) { x = rho * sin(phi) * cos(theta); z = rho * sin(phi) * sin(theta); y = -rho * cos(phi); // u = (float)t / thetaSteps; // v = (float)p / phiSteps; normal(x, y, z); vertex(x, y, z ); // , u, v); x = rho * sin(phi + phiFactor) * cos(theta); z = rho * sin(phi + phiFactor) * sin(theta); y = -rho * cos(phi + phiFactor); // println (x); // u = (float)t / thetaSteps; // v = (float)(p + 1) / phiSteps; normal(x, y, z); vertex(x, y, z); // , u, v); BottomOfTheHead [t] = new PVector (x, y, z); theta += thetaFactor; } phi += phiFactor; endShape(CLOSE); } // close the bottom of the arrow head // (towards the shaft) beginShape(); for(int b = 0; b < 4; b++) { vertex (BottomOfTheHead[b].x,BottomOfTheHead[b].y,BottomOfTheHead[b].z); } // for b endShape(CLOSE); } // Arrowhead