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

How to make different orthogonal projections Pyglet?

我制作了两个立方体视口,但它们都是正面正交投影,我需要其中一个是侧面投影。 这是绘图代码 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).