如何在 pyglet 中制作一个立方体,上面有图像
How to make a cube in pyglet with images on faces
我正在制作一个 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 tex\n
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 渲染程序。
我假设坐标(x1
,y1
,z1
)是立方体的最小值,坐标是最大值(x1
,y1
, z1
).例如:
self.cuboid(0, 0, 0, 1, 1, 1, self.tex)
如果在视图 space 中绘制立方体,则:
x-axis指向左边。 left
纹理必须放置在所有顶点的 x 坐标为 x1
的位置,而 right
纹理必须放置在 x 坐标为 x2
:
的位置
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-axis点向上。所以 bottom
是 y 坐标 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)
在Right-handed system the z axis points out of the view. The z-axis is the Cross product的x-axis和y-axis.
这导致 front
必须放在 z-coordinates 是 z2
和 back
的地方 z-coordinates 是 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 tex\n
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)
我正在制作一个 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 tex\n
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 渲染程序。
我假设坐标(x1
,y1
,z1
)是立方体的最小值,坐标是最大值(x1
,y1
, z1
).例如:
self.cuboid(0, 0, 0, 1, 1, 1, self.tex)
如果在视图 space 中绘制立方体,则:
x-axis指向左边。 left
纹理必须放置在所有顶点的 x 坐标为 x1
的位置,而 right
纹理必须放置在 x 坐标为 x2
:
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-axis点向上。所以 bottom
是 y 坐标 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)
在Right-handed system the z axis points out of the view. The z-axis is the Cross product的x-axis和y-axis.
这导致 front
必须放在 z-coordinates 是 z2
和 back
的地方 z-coordinates 是 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 tex\n
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)