我制作了两个多维数据集视口,但它们都是正面正交投影,因此我需要从侧面看。
这是绘图代码
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()
最佳答案
只需将视图空间中的视图围绕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
注意,左视图和右视图由
pgl.glRotatef(-90, 0, 1, 0)
和pgl.glRotatef(90, 0, 1, 0)
生成。顶视图和底视图是通过围绕视图空间x轴旋转分别通过
pgl.glRotatef(90, 1, 0, 0)
和pgl.glRotatef(-90, 0, 1, 0)
来实现的。关于python - 如何制作不同的正交投影Pyglet?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55131639/