-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (52 loc) · 1.79 KB
/
Copy pathmain.py
File metadata and controls
67 lines (52 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# https://github.com/Josephbakulikira/3D-perspective-projection-with-python-
import os
import numpy as np
import pygame
from pygame import surfarray
from engine import screen
from engine.camera import camera_input, camera
from scenes import scene_quake as SCENE
from settings import settings
os.environ["SDL_VIDEO_CENTERED"] = '1'
run = True
pygame.init()
pyscreen = pygame.display.set_mode((settings.width, settings.height), pygame.SCALED)
clock = pygame.time.Clock()
fps = 600
delta_time = 0
scene = SCENE
light_pos = np.array([-15.5, 10., -9., 0.])
d_campos = np.array([0., 0., 0., 0.])
d_camrot = np.array([0., 0., 0., 0.])
cam_moving_speed = 900
cam_rot_speed = 4
camera.transform.pos = scene.campos
camera.transform.rot = scene.camrot
def draw(light_pos, d_campos, d_camrot):
camera.clear()
camera.transform.update_transform(d_campos * cam_moving_speed, d_camrot * cam_rot_speed)
for idx, obj in enumerate(scene.object_list): camera.draw_object(obj, light_pos)
if not settings.only_z_buffer:
color_buffer, tris_len = camera.get_data(scene)
surfarray.blit_array(pyscreen, color_buffer)
else:
zbuffer_scr, tris_len = camera.get_z_buffer()
surfarray.blit_array(pyscreen, zbuffer_scr)
pygame.display.update()
screen.print_caption(clock, tris_len)
while run:
clock.tick(fps)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
dx, dy, dz = camera_input.scan_control_move(delta_time)
d_campos[0] = dx
d_campos[1] = dy
d_campos[2] = dz
drx, dry = camera_input.scan_control_rotate(delta_time)
d_camrot[0] = drx
d_camrot[1] = dry
scene.update(delta_time)
draw(light_pos, d_campos, d_camrot)
delta_time = clock.get_time() / 1000
pygame.quit()