额,其实任何多面体都是三边形或者四边形拼接成的,然后只要在beginshape和endshape中间画四边形或者三角形就行了。。
void setup(){
size(640, 360, P3D);
}
void draw(){
background(0);
translate(width/2, height/2, 0);
stroke(255);
rotateX(PI/2);
rotateZ(-PI/6);
noFill();
beginShape(QUAD_STRIP);
six_prism(0,0,100,50);
endShape();
}
void six_prism(float x, float y, float z, float radius) {
float angle = TWO_PI / 6;
for (float a = 0; a < TWO_PI; a += angle) {
float sx = x + cos(a) * radius;
float sy = y + sin(a) * radius;
vertex(sx, sy, z/2);
vertex(sx, sy, -z/2);
}
}
网友评论