cone with a base
in
Programming Questions
•
9 months ago
I'm trying to draw a cone with a base, but I don't know why the base does not appear.
- void setup(){
- size(500, 500, P3D);
- background(255);
- frameRate(60);
- }
- void draw(){
- background(255);
- translate(width/2, height/2);
- rotateShape( mouseY * 0.01, mouseX * 0.01, mouseX * 0.01 );
- cone(10, 200, 50.0);
- }
- void cone(int det, int h, float r){
- float[] unitConeX = new float[det+1];
- float[] unitConeY = new float[det+1];
- for (int i = 0; i <= det; i++) {
- float a1 = TWO_PI * i / det;
- unitConeX[i] = (float)Math.cos(a1);
- unitConeY[i] = (float)Math.sin(a1);
- }
- pushMatrix();
- scale(r, r);
- beginShape(TRIANGLES);
- for(int i = 0; i < det; i++){
- vertex(unitConeX[i], unitConeY[i], 0.0);
- vertex(unitConeX[i + 1], unitConeY[i+1], 0.0);
- vertex(0,0,h);
- }
- endShape();
- beginShape(TRIANGLE_FAN);
- vertex(0, h/2, 0);
- for(int i = 0; i < det; i++){
- vertex(unitConeY[i] * r, h/2, unitConeX[i] * r);
- }
- endShape();
- popMatrix();
- }
- void rotateShape(float x, float y, float z){
- rotateX(x);
- rotateY(y);
- rotateZ(z);
- }
1