natenine
YaBB Newbies
Offline
Posts: 3
Re: 3d diamond
Reply #2 - Jun 22nd , 2009, 11:20am
Thanks, but... I cannot see how I can cut the second pyramid, ill show what i have. for now is just based in another code: void setup() { size(800, 600, P3D); smooth(); } void draw() { background(0); lights(); translate(width / 2, height / 2); rotateY(map(mouseX, 0, width, 0, PI)); rotateZ(map(mouseY, 0, height, 0, -PI)); rotateX(map(mouseX-mouseY, 0, width, 0, PI*2)); noStroke(); noFill(); stroke(255); strokeWeight(1); translate(0, -40, 0); drawCylinder(0, 150, 150, 8); // Draw a pyramid } void drawCylinder(float topRadius, float bottomRadius, float tall, int sides) { float angle = 0; float angleIncrement = TWO_PI / sides; beginShape(QUAD_STRIP); for (int i = 0; i < sides + 1; ++i) { vertex(topRadius*cos(angle), 0, topRadius*sin(angle)); vertex(bottomRadius*cos(angle), tall, bottomRadius*sin(angle)); angle += angleIncrement; } endShape(); // If it is not a cone, draw the circular top cap // if (topRadius != 0) { angle = 0; beginShape(TRIANGLE_FAN); // Center point vertex(0, 0, 0); for (int i = 0; i < sides + 1; i++) { vertex(topRadius * cos(angle), 0, topRadius * sin(angle)); angle += angleIncrement; } endShape(); // } // If it is not a cone, draw the circular bottom cap if (bottomRadius != 0) { angle = 0; beginShape(TRIANGLE_FAN); // Center point vertex(0, tall+150, 0); for (int i = 0; i < sides + 1; i++) { vertex(bottomRadius * cos(angle), tall, bottomRadius * sin(angle)); angle += angleIncrement; } endShape(); } }