Поворот камеры OpenGL+Pygame

from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *

pygame.init()
width, height = 800, 600
pygame.display.set_mode((width, height), DOUBLEBUF | OPENGL)

glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45, width / height, 0.1, 50.0)
glMatrixMode(GL_MODELVIEW)

glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glLightfv(GL_LIGHT0, GL_POSITION, (0.5, 0.5, 1, 0))
glLightfv(GL_LIGHT0, GL_AMBIENT, (0.5, 0.5, 0.5, 1))
glLightfv(GL_LIGHT0, GL_DIFFUSE, (1, 1, 1, 1))
glLightfv(GL_LIGHT0, GL_SPECULAR, (1, 1, 1, 1))

glClearColor(0.5, 0.7, 1.0, 1.0)

camera_pos = [0, 0, -5]
camera_speed = 0.005
rotation_speed = 1.0

def draw_sphere():
    glColor3f(1, 1, 1)
    gluSphere(gluNewQuadric(), 0.5, 32, 32)

def draw_floor():
    vertices = (
        (-10, -0.6, -10),
        (-10, -0.6, 10),
        (10, -0.6, 10),
        (10, -0.6, -10)
    )

    glBegin(GL_QUADS)
    glColor3f(0.5, 0.5, 0.5)
    for vertex in vertices:
        glVertex3fv(vertex)
    glEnd()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()

    keys = pygame.key.get_pressed()
    if keys[pygame.K_w]:
        camera_pos[2] -= camera_speed
    if keys[pygame.K_s]:
        camera_pos[2] += camera_speed
    if keys[pygame.K_a]:
        camera_pos[0] -= camera_speed
    if keys[pygame.K_d]:
        camera_pos[0] += camera_speed
    if keys[pygame.K_LEFT]:
        glRotatef(rotation_speed, 0, 1, 0)
    if keys[pygame.K_RIGHT]:
        glRotatef(-rotation_speed, 0, 1, 0)
    if keys[pygame.K_UP]:
        glRotatef(rotation_speed, 1, 0, 0)
    if keys[pygame.K_DOWN]:
        glRotatef(-rotation_speed, 1, 0, 0)

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()

    gluLookAt(camera_pos[0], camera_pos[1], camera_pos[2], camera_pos[0], camera_pos[1], camera_pos[2]-1, 0, 1, 0)

    draw_floor()

    glPushMatrix()
    glTranslatef(0, 0, 0)
    draw_sphere()
    glPopMatrix()

    pygame.display.flip()```


Мучаюсь не могу исправить как заставить поворачиваться камеру на стрелки

Ответы (0 шт):