我有一个生成球体顶点的函数,但我不知道如何生成球体的边/连接。有人知道我怎样才能做到这一点吗
以下是生成球体顶点的方法:
def uv_sphere_vertices(position, radius, stackcount : int, sectorcount : int):
verts = []
sectorstep = 2 * math.pi / sectorcount
stackstep = math.pi / stackcount
for num in range(stackcount):
stackangle = math.pi / 2 - num * stackstep
for num2 in range(sectorcount):
sectorangle = num2 * sectorstep
x = radius * math.cos(stackangle) * math.cos(sectorangle)
y = radius * math.cos(stackangle) * math.sin(sectorangle)
z = radius * math.sin(stackangle)
verts.append([x,y,z])
return verts
我需要连接作为顶点列表中顶点的索引。这是连接所需的示例:
我试过他们在http://www.songho.ca/opengl/gl_sphere.html做这件事的方式,但没有真正起作用。我将那里的内容转换为:
for num in range(stackcount):
k1 = num * (sectorcount + 1)
k2 = k1 + sectorcount + 1
for num2 in range(sectorcount):
if num != 0:
edges.append([k1,k2,k1+1])
if num != stackcount-1:
edges.append([k1+1,k2,k2+1])
k1 += 1
k2 += 1
我想出了一个解决办法。结果是,我需要在范围值中添加一个。这是我的最终代码:
相关问题 更多 >
编程相关推荐