在PyOpenGL中切换Y和Z轴

问题描述 投票:0回答:1

我想在PyOpenGL中切换Y和Z轴方向。我曾尝试使用矩阵变换,但未能做到这一点。

代码:

glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(self.zoom, -self.zoom, -self.zoom, self.zoom, -5000, 5000)
glMatrixMode(GL_MODELVIEW)
glClearColor(1, 1, 1, 0)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadMatrixf(self.m)

位置:

self.zoom = 150
self.m = [[1, 0, 0, 0],
          [0, 0, 1, 0],
          [0, 1, 0, 0],
          [0, 0, 0, 1]]

错误的结果:enter image description here

使用身份矩阵:enter image description here

预期:enter image description here

python opengl matrix pyopengl
1个回答
0
投票

通过交换分量并将分量之一反转,二维矢量可以旋转90°:

  • 向左旋转(x,y)为(-y,x)
  • 向右旋转(x,y)是(y,-x)

您实际要做的是将右手矩阵转换为左手矩阵。它是旋转90°和镜像的串联。

更改矩阵:

两个

self.m = [[1, 0,  0, 0],
          [0, 0, -1, 0],
          [0, 1,  0, 0],
          [0, 0,  0, 1]]

self.m = [[1,  0, 0, 0],
          [0,  0, 1, 0],
          [0, -1, 0, 0],
          [0,  0, 0, 1]]

注意,同样可以通过绕x轴旋转来实现。例如:

glLoadIdentity()
glRotatef(90, 1, 0, 0)
© www.soinside.com 2019 - 2024. All rights reserved.