I'm struggling to make the camera movements feel more natural. Currently, the camera movements are rigid and don't smoothly follow user input or animations.
Here's a simplified version of my code:
import pygamefrom pygame.locals import *running = Truemouse_down = Falsewhile running: for event in pygame.event.get((QUIT,MOUSEBUTTONUP,MOUSEBUTTONDOWN)): if event.type == QUIT: running = False elif event.type == MOUSEBUTTONUP: mouse_down = False elif event.type == MOUSEBUTTONDOWN: mouse_down = True xcoor = pygame.mouse.get_pos() if mouse_down and (pygame.mouse.get_pos()[0] - xcoor[0] != 0 or pygame.mouse.get_pos()[1] - xcoor[1]): condition = True camera[1].z += (pygame.mouse.get_pos()[0] - xcoor[0]) * 0.1 camera[1].y -= (pygame.mouse.get_pos()[1] - xcoor[1]) * 0.1 xcoor = pygame.mouse.get_pos() else: condition = False keys = pygame.key.get_pressed() if keys[K_LEFT]: camera[0].x -= 0.1 condition = True if keys[K_RIGHT]: camera[0].x += 0.1 condition = True if keys[K_UP]: camera[0].z -= 0.1 condition = True if keys[K_DOWN]: camera[0].z += 0.1 condition = True if keys[K_w]: camera[0].y += 0.1 condition = True if keys[K_s]: camera[0].y -= 0.1 condition = True
I initialize the camera position and orientation using a set of vectors and angles. However, when I try to move or rotate the camera, the movements are abrupt and not smooth at all.
What techniques or approaches can I use to improve the fluidity and naturalness of camera movements in my Pygame raytracer? Are there specific algorithms or libraries that would help with this?