【发布时间】:2014-12-08 22:26:53
【问题描述】:
我最近一直在尝试使用三角形在 OpenGL 中渲染 3D 球体。我一直在测试和修改来自各个网站的代码,终于找到了一个成功的组合。唯一的问题是球体中有明显的间隙。有什么想法会导致这种情况吗?
渲染球体的代码
float Slices = 30;
float Stacks = 60;
float Radius = 20.0;
for (int i = 0; i <= Stacks; ++i){
float V = i / (float) Stacks;
float phi = V * glm::pi <float> ();
for (int j = 0; j <= Slices; ++j){
float U = j / (float) Slices;
float theta = U * (glm::pi <float> () * 4);
float x = cosf (theta) * sinf (phi);
float y = cosf (phi);
float z = sinf (theta) * sinf (phi);
x *= Radius;
y *= Radius;
z *= Radius;
Vertex *v = new Vertex {{x,y,z}, //Position
{255,0,0}}; //Color
screenToBuffer(v, 1);
delete []v;
}
}
问题
【问题讨论】:
-
screenToBuffer(v, 1);是做什么的? -
将顶点发送到 VBO。
-
渲染代码在哪里?
-
点计算看起来不错。但除此之外,您还需要一个索引数组来定义正确的连接性,以便从这些点创建三角形。要么这样,要么你必须重复点。
标签: c++ opengl 3d geometry glm-math