在这里使用测地圆顶。它运行正常,但它看起来像垃圾,并没有渲染任何反锯齿。
我认为在处理中默认打开平滑功能。谁能告诉我哪里出错?是因为我正在使用beginShape()吗?我似乎也无法改变笔画宽度,并且alpha填充不会做任何事情。
https://jsfiddle.net/ophello/cr1ez8ok/
int state = 0;
float scale = 100;
float phi = (1 + sqrt(5)) / 2.0;
float radius = sqrt(sq(1) + sq(phi));
ArrayList<Triangle> triangles;
void setup(){
size(1000, 500, P3D);
PVector[] vertices = {new PVector(0, 1, phi),
new PVector(0, -1, phi),
new PVector(0, -1, -phi),
new PVector(0, 1, -phi),
new PVector(phi, 0, 1),
new PVector(-phi, 0, 1),
new PVector(-phi, 0, -1),
new PVector(phi, 0, -1),
new PVector(1, phi, 0),
new PVector(-1, phi, 0),
new PVector(-1, -phi, 0),
new PVector(1, -phi, 0)};
triangles = new ArrayList<Triangle>();
triangles.add(new Triangle(vertices[0], vertices[8], vertices[9]));
triangles.add(new Triangle(vertices[0], vertices[9], vertices[5]));
triangles.add(new Triangle(vertices[0], vertices[5], vertices[1]));
triangles.add(new Triangle(vertices[0], vertices[1], vertices[4]));
triangles.add(new Triangle(vertices[0], vertices[4], vertices[8]));
triangles.add(new Triangle(vertices[1], vertices[5], vertices[10]));
triangles.add(new Triangle(vertices[1], vertices[10], vertices[11]));
triangles.add(new Triangle(vertices[1], vertices[11], vertices[4]));
triangles.add(new Triangle(vertices[2], vertices[3], vertices[7]));
triangles.add(new Triangle(vertices[2], vertices[7], vertices[11]));
triangles.add(new Triangle(vertices[2], vertices[11], vertices[10]));
triangles.add(new Triangle(vertices[2], vertices[10], vertices[6]));
triangles.add(new Triangle(vertices[2], vertices[6], vertices[3]));
triangles.add(new Triangle(vertices[3], vertices[6], vertices[9]));
triangles.add(new Triangle(vertices[3], vertices[9], vertices[8]));
triangles.add(new Triangle(vertices[3], vertices[8], vertices[7]));
triangles.add(new Triangle(vertices[4], vertices[11], vertices[7]));
triangles.add(new Triangle(vertices[4], vertices[7], vertices[8]));
triangles.add(new Triangle(vertices[5], vertices[9], vertices[6]));
triangles.add(new Triangle(vertices[5], vertices[6], vertices[10]));
for(int i = 0; i < 1; i++){
ArrayList<Triangle> nextTriangles = new ArrayList<Triangle>();
for(Triangle t: triangles){
nextTriangles.addAll(t.divide());
}
triangles = nextTriangles;
}
}
void draw(){
//camera(width/2.0, height/2.0, (height/2.0) / tan(PI*30.0 / 180.0), width/2.0, height/2.0, 0, 0, 1, 0)
background(255);
translate(width / 2, height / 2);
rotateX(frameCount * 0.0002);
rotateY(frameCount * 0.0004);
rotateZ(frameCount * 0.0006);
for(Triangle t: triangles){
t.display();
}
}
class Triangle{
PVector[] vertices;
Triangle(PVector v0, PVector v1, PVector v2){
vertices = new PVector[3];
vertices[0] = v0;
vertices[1] = v1;
vertices[2] = v2;
}
void display(){
stroke(255, 210,0);
noFill();
beginShape();
for(int i = 0; i < 3; i++){
vertex(vertices[i].x * scale, vertices[i].y * scale, vertices[i].z * scale);
}
endShape(CLOSE);
}
ArrayList<Triangle> divide(){
PVector[] midpoints = new PVector[3];
for(int i = 0; i < 3; i++){
int j = i != 2 ? i + 1: 0;
PVector m = PVector.lerp(vertices[i], vertices[j], 0.5);
m.normalize();
m.mult(radius);
midpoints[i] = m;
}
ArrayList<Triangle> triangles = new ArrayList<Triangle>();
triangles.add(new Triangle(vertices[0], midpoints[0], midpoints[2]));
triangles.add(new Triangle(vertices[1], midpoints[1], midpoints[0]));
triangles.add(new Triangle(vertices[2], midpoints[2], midpoints[1]));
triangles.add(new Triangle(midpoints[0], midpoints[1], midpoints[2]));
return triangles;
}
}
答案 0 :(得分:0)
请养成发布MCVE而不是整个项目的习惯。
Here是一个更简单的示例,用于演示此问题:
void setup(){
size(500, 500, P3D);
}
void draw(){
background(255);
line(0, 0, mouseX, mouseY);
}
听起来你正在寻找hint()
功能。可以在the reference中找到更多信息,但here只是一个简单示例:
void setup(){
hint(ENABLE_OPENGL_4X_SMOOTH);
size(500, 500, P3D);
}
void draw(){
background(255);
line(0, 0, mouseX, mouseY);
}
如果您仍然遇到问题,请在新的问题帖子中发布更新的MCVE。祝你好运。