我需要 pygame 中 PyOpenGL 的帮助。我希望能够旋转视图以使其全局化,我相信这个术语是。我希望能够围绕y(向上)轴左右旋转,并向y轴向上和向下旋转。
我将如何做到这一点?
用于旋转视图的功能是:
glRotatef(angle, rotX, rotY, rotZ)
但是,它只围绕轴旋转。
编辑:这是代码:
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
verticies = (
(1, -1, -1),
(1, 1, -1),
(-1, 1, -1),
(-1, -1, -1),
(1, -1, 1),
(1, 1, 1),
(-1, -1, 1),
(-1, 1, 1)
)
edges = (
(0,1),
(0,3),
(0,4),
(2,1),
(2,3),
(2,7),
(6,3),
(6,4),
(6,7),
(5,1),
(5,4),
(5,7)
)
def Cube():
glBegin(GL_LINES)
for edge in edges:
for vertex in edge:
glVertex3fv(verticies[vertex])
glEnd()
def main():
pygame.init()
display = (800,600)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
gluPerspective(45, (display[0]/display[1]), 0.1, 50.0)
glTranslatef(0.0,0.0, -5)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
elif(event.type == pygame.K_LEFT):
left() #?
elif(event.type == pygame.K_RIGHT):
right() #?
# up.. down.. etc
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
Cube()
pygame.display.flip()
pygame.time.wait(10)
main()