如何在pyglet中制作一个带有面部图像的立方体



我正在制作一个 3D 游戏,我需要将图像粘贴到立方体上,但我找不到front/back/top/bottom/left/right纹理应该去哪里。

我刚开始使用pyglet,所以我对它不是很熟悉。我已经翻转立方体的纹理部分几天了,它仍然一团糟。这是我在下面为立方体函数编写的代码:

def cuboid(self, x1,y1,z1, x2,y2,z2, tex):
'''
Draws a cuboid from x1,y1,z1 to x2,y2,z2 and covers each side with texn
tex format:n
(front, back, left, right, top, bottom)
Facing in the -z direction
'''
front = tex[0]
back = tex[1]
left = tex[2]
right = tex[3]
top = tex[4]
bottom = tex[5]
tex_coords = ("t2f", (0,0, 1,0, 1,1, 0,1))
self.batch.add(4,GL_QUADS,back,('v3f',(x1,y1,z1, x1,y1,z2, x1,y2,z2, x1,y2,z1, )),tex_coords)
self.batch.add(4,GL_QUADS,right,('v3f',(x2,y1,z2, x2,y1,z1, x2,y2,z1, x2,y2,z2, )),tex_coords)
self.batch.add(4,GL_QUADS,top,('v3f',(x1,y1,z1, x2,y1,z1, x2,y1,z2, x1,y1,z2, )),tex_coords)
self.batch.add(4,GL_QUADS,front,('v3f',(x1,y2,z2, x2,y2,z2, x2,y2,z1, x1,y2,z1, )),tex_coords)
self.batch.add(4,GL_QUADS,bottom,('v3f',(x2,y1,z1, x1,y1,z1, x1,y2,z1, x2,y2,z1, )),tex_coords)
self.batch.add(4,GL_QUADS,left,('v3f',(x1,y1,z2, x2,y1,z2, x2,y2,z2, x1,y2,z2, )),tex_coords)

我无法显示我的期望,因为我没有有效的 3d 渲染程序。

我假设坐标(x1y1z1)是立方体的最小值,坐标是最大值(x1y1z1)。 例如:

self.cuboid(0, 0, 0, 1, 1, 1, self.tex)

如果在视图空间中绘制立方体,则:

x 轴指向左侧。left纹理必须放置在所有顶点的 x 坐标x1的位置,而 x 坐标x2right纹理

self.batch.add(4, GL_QUADS, right,  ('v3f',(x1,y1,z1, x1,y1,z2, x1,y2,z2, x1,y2,z1)), tex_coords)
self.batch.add(4, GL_QUADS, left,   ('v3f',(x2,y1,z2, x2,y1,z1, x2,y2,z1, x2,y2,z2)), tex_coords)

y 轴指向上方。因此,bottomy 坐标y1和顶部 y 坐标y2

self.batch.add(4, GL_QUADS, bottom, ('v3f',(x1,y1,z1, x2,y1,z1, x2,y1,z2, x1,y1,z2)), tex_coords)
self.batch.add(4, GL_QUADS, top,    ('v3f',(x1,y2,z2, x2,y2,z2, x2,y2,z1, x1,y2,z1)), tex_coords)

在右手系统中,z 轴指向视图之外。z 轴是 x 轴和 y 轴的叉积。
这会导致front必须放置在 z 坐标z2的位置,backz 坐标z1的位置

self.batch.add(4, GL_QUADS, back,   ('v3f',(x2,y1,z1, x1,y1,z1, x1,y2,z1, x2,y2,z1)), tex_coords)
self.batch.add(4, GL_QUADS, front,  ('v3f',(x1,y1,z2, x2,y1,z2, x2,y2,z2, x1,y2,z2)), tex_coords)

该方法cuboid

def cuboid(self, x1,y1,z1, x2,y2,z2, tex):
'''
Draws a cuboid from x1,y1,z1 to x2,y2,z2 and covers each side with texn
tex format:n
(front, back, left, right, top, bottom)
Facing in the -z direction
'''
front  = tex[0]
back   = tex[1]
left   = tex[2]
right  = tex[3]
top    = tex[4]
bottom = tex[5]
tex_coords = ("t2f", (0,0, 1,0, 1,1, 0,1))
self.batch.add(4, GL_QUADS, right,  ('v3f',(x1,y1,z1, x1,y1,z2, x1,y2,z2, x1,y2,z1)), tex_coords)
self.batch.add(4, GL_QUADS, left,   ('v3f',(x2,y1,z2, x2,y1,z1, x2,y2,z1, x2,y2,z2)), tex_coords)
self.batch.add(4, GL_QUADS, bottom, ('v3f',(x1,y1,z1, x2,y1,z1, x2,y1,z2, x1,y1,z2)), tex_coords)
self.batch.add(4, GL_QUADS, top,    ('v3f',(x1,y2,z2, x2,y2,z2, x2,y2,z1, x1,y2,z1)), tex_coords)
self.batch.add(4, GL_QUADS, back,   ('v3f',(x2,y1,z1, x1,y1,z1, x1,y2,z1, x2,y2,z1)), tex_coords)
self.batch.add(4, GL_QUADS, front,  ('v3f',(x1,y1,z2, x2,y1,z2, x2,y2,z2, x1,y2,z2)), tex_coords)

相关内容

最新更新