gpt4 book ai didi

python - 如何制作不同的正交投影 Pyglet?

转载 作者:太空宇宙 更新时间:2023-11-03 21:10:03 26 4
gpt4 key购买 nike

我制作了两个立方体视口(viewport),但它们都是正面正交投影,我需要其中一个来自侧面。这是绘图代码draw_small 正在绘制小型静态立方体dwar_big是大立方体的绘制,可以移动、缩放和旋转

    def on_draw(self) :

self.clear()

pgl.glClear(pgl.GL_COLOR_BUFFER_BIT | pgl.GL_DEPTH_BUFFER_BIT)

pgl.glViewport(0, 0, 650, 500)
pgl.glMatrixMode(pgl.GL_PROJECTION)
pgl.glLoadIdentity()
pgl.glOrtho(-1300 / 8, 1300 / 8, -1000 / 8, 1000 / 8, 100, 500)
pgl.glMatrixMode(pgl.GL_MODELVIEW)
pgl.glLoadIdentity
pgl.glTranslatef(0, 0, -100)
pgl.glPolygonMode(pgl.GL_FRONT_AND_BACK, pgl.GL_FILL)
draw_small()

pgl.glPushMatrix()
pgl.glTranslatef(self.x, self.y, self.z)
pgl.glRotatef(self.xRotation, 1, 0, 0)
pgl.glRotatef(self.yRotation, 0, 1, 0)
pgl.glRotatef(self.zRotation, 0, 0, 1)
pgl.glScalef(self.zoom, self.zoom, self.zoom)

if not transparant:
pgl.glPolygonMode(pgl.GL_FRONT_AND_BACK, pgl.GL_FILL)
else:
ogl.glPolygonMode(pgl.GL_FRONT_AND_BACK, pgl.GL_LINE)

draw_big()

pgl.glPopMatrix()


pgl.glViewport(650, 0, 650, 500)
pgl.glMatrixMode(pgl.GL_PROJECTION)
pgl.glLoadIdentity()
pgl.glOrtho(-1300 / 8, 1300 / 8, -1000 / 8, 1000 / 8, 0, 500)
pgl.glMatrixMode(pgl.GL_MODELVIEW)
pgl.glLoadIdentity()
pgl.glTranslatef(0, 0, -100)
pgl.glPolygonMode(pgl.GL_FRONT_AND_BACK, pgl.GL_FILL)

draw_small()

pgl.glPushMatrix()
pgl.glTranslatef(self.x, self.y, self.z)
pgl.glRotatef(self.xRotation, 1, 0, 0)
pgl.glRotatef(self.yRotation, 0, 1, 0)
pgl.glRotatef(self.zRotation, 0, 0, 1)
pgl.glScalef(self.zoom, self.zoom, self.zoom)

if not transparant:
pgl.glPolygonMode(pgl.GL_FRONT_AND_BACK, pgl.GL_FILL)
else:
pgl.glPolygonMode(pgl.GL_FRONT_AND_BACK, pgl.GL_LINE)

draw_big()

pgl.glPopMatrix()

最佳答案

只需将 View 绕 View 空间中的 y 轴旋转 90 度即可:

pgl.glMatrixMode(pgl.GL_MODELVIEW)
pgl.glLoadIdentity
pgl.glTranslatef(0, 0, -100)
pgl.glRotatef(-90, 0, 1, 0) # roatet 90 degrees around view space y axis

注意,左 View 和右 View 是由 pgl.glRotatef(-90, 0, 1, 0) 生成的和pgl.glRotatef(90, 0, 1, 0) .
顶部和底部 View 是通过绕 View 空间 x 轴旋转来实现的,通过 pgl.glRotatef(90, 1, 0, 0)分别pgl.glRotatef(-90, 0, 1, 0) .

关于python - 如何制作不同的正交投影 Pyglet?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55131639/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com