-4
카메라를 움직이기 위해 노력하고 있지만 q를 클릭해도 효과가 없습니다. 나는 원래 프로그래머에게 물어 보려했지만, 그게 무식하게되었고, 그래서 나는 무엇을 해야할지 모른다.PyGame - 키를 눌렀을 때 카메라가 움직이지 않습니다.
코드 :
import pygame, sys, math
class Cam:
def __init__(self,pos=(0,0,0),rot=(0,0)):
self.pos = list(pos)
self.rot = list(rot)
def update(self,dt,key):
s = dt*10
if key[pygame.K_q]: self.pos[1]-=s
if key[pygame.K_e]: self.pos[1]+=s
if key[pygame.K_w]: self.pos[2]+=s
if key[pygame.K_s]: self.pos[2]-=s
if key[pygame.K_a]: self.pos[0]-=s
if key[pygame.K_d]: self.pos[0]+=s
pygame.init()
w,h = 400,400; cx,cy = w//2,h//2
screen = pygame.display.set_mode((w,h))
clock = pygame.time.Clock()
verts = (-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),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),(0,4),(1,5),(2,6),(3,7)
cam = Cam((0,0,-5))
while True:
dt = clock.tick()/1000
for event in pygame.event.get():
if event.type == pygame.QUIT: pygame.quit(); sys.exit()
screen.fill((255,255,255))
for edge in edges:
points = []
for x,y,z in (verts[edge[0]],verts[edge[1]]):
x-=cam.pos[0]
y-=cam.pos[1]
z-=cam.pos[2]
f = 200/z
x,y = x*f,y*f
points+=[(cx+int(x),cy+int(y))]
pygame.draw.line(screen,(0,0,0),points[0],points[1],1)
pygame.display.flip()
key = pygame.key.get_pressed()
cam.update(dt,key)
여전히 작동하지 않음 – pol002
"작동하지 않는다"는 의미는 @ pol002입니까? 당신은 무엇을 기대 했습니까? 당신은 무엇을 얻었습니까? 어떤 디버깅을 했습니까? 코드가하는 일을 이해하기 위해 중간 값을 출력 했습니까? – halfer