【发布时间】:2016-11-22 02:52:09
【问题描述】:
它正在绘制一个带有堆栈和边缘的圆柱体,但问题是堆栈连接到一个点而不是一个新点。 也许一张图片会更好地显示它:
这是我渲染侧面的方式,因为磁盘是单独渲染的:
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;
}
我已经尝试解决它好几天了,但我的想法已经用完了。你知道我做错了什么吗?
更新: 我已经使用 ybungalobill 建议将其更改为使用四边形渲染。现在我正在为 UV 贴图而苦苦挣扎。希望一旦这部分得到解决,它就可以很容易地转换成三角形。 这就是我现在所拥有的:
这就是我用于 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;
}
【问题讨论】:
标签: opengl procedural-generation