在OpenGL中用三角形绘制圆柱体
它画了一个有堆叠和边缘的圆柱体,但问题是堆叠连接到一个点而不是一个新点。 也许一张照片能更好地展示它: 下面是我渲染侧面的方式,因为磁盘是单独渲染的:在OpenGL中用三角形绘制圆柱体,opengl,procedural-generation,Opengl,Procedural Generation,它画了一个有堆叠和边缘的圆柱体,但问题是堆叠连接到一个点而不是一个新点。 也许一张照片能更好地展示它: 下面是我渲染侧面的方式,因为磁盘是单独渲染的: for (int i = 1; i <= height; ++i) { for (int j = 0; j < edges; ++j) { glBegin(GL_TRIANGLES); { // 0 bottom glVerte
for (int i = 1; i <= height; ++i) {
for (int j = 0; j < edges; ++j) {
glBegin(GL_TRIANGLES); {
// 0 bottom
glVertex3f(x + radius * cos(theta + interval), y , z + radius * sin(theta + interval));
// 1 bottom
glVertex3f(x + radius * cos(theta), y + y_value * i, z + radius * sin(theta));
// 2 top
glVertex3f(x + radius * cos(theta), y + y_value * i, z + radius * sin(theta));
// 2 top
glVertex3f(x + radius * cos(theta), y + y_value * i, z + radius * sin(theta));
// 3 top
glVertex3f(x + radius * cos(theta + interval), y + y_value * i, z + radius * sin(theta + interval));
// 0 bottom
glVertex3f(x + radius * cos(theta + interval), y , z + radius * sin(theta + interval));
} glEnd();
theta += interval;
}
theta = 0.0;
}
用于(int i=1;实际上我不得不将//1 bottom中的y0改为y1,但我想我理解你在那里做了什么。这很奇怪,因为你应该在顶部有三个顶点,底部有你。是的,你是对的,它没有很好地映射。我已经将它改为quads,并按照你所说的方式映射,现在它正在工作。现在我正在努力进行UV映射。我如果您想查看,请完成更新。如果您以前的问题已解决,请避免更改问题。相反,请接受当前问题的答案,并用新问题询问新问题。
u = 0.0,
v = 0.0,
u_inter = 1.0 / edges,
v_inter = 1.0 / y_value; // (y_value = height / edges)
for (int i = 1; i <= height; ++i) {
for (int j = 0; j < edges; ++j) {
glBegin(GL_QUAD_STRIP); {
// 0 bottom
glTexCoord2f(u, v);
// 1 bottom
glTexCoord2f(u + u_inter, v);
// 2 top
glTexCoord2f(u + u_inter, v + v_inter);
// 3 top
glTexCoord2f(u, v + v_inter);
} glEnd();
theta += interval;
u += u_inter;
}
v += v_inter;
theta = 0.0;
}
float y0 = y + y_value * (i-1);
float y1 = y + y_value * i;
// 0 bottom
glVertex3f(x + radius * cos(theta + interval), y0, z + radius * sin(theta + interval));
// 1 bottom
glVertex3f(x + radius * cos(theta), y0, z + radius * sin(theta));
// 2 top
glVertex3f(x + radius * cos(theta), y1, z + radius * sin(theta));
// 2 top
glVertex3f(x + radius * cos(theta), y1, z + radius * sin(theta));
// 3 top
glVertex3f(x + radius * cos(theta + interval), y1, z + radius * sin(theta + interval));
// 0 bottom
glVertex3f(x + radius * cos(theta + interval), y0, z + radius * sin(theta + interval));