-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
126 lines (105 loc) · 4.33 KB
/
Copy pathmain.py
File metadata and controls
126 lines (105 loc) · 4.33 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import pygame as pg
import numpy as np
import random as rd
import config as cfg
from camera import camera
from objects import Cuboid, Tetrahedron, Prism, Pyramid
from console import start_console
from numpy import rad2deg
pg.init()
pg.display.set_caption("Flight Simulator 3D")
font = pg.font.SysFont("Arial", 16)
def gen_word(string: str, start_pos: tuple):
main_offset = 0
cuboids = []
for char in string:
if char not in cfg.LETTERS:
main_offset += 2
continue
matrix = cfg.LETTERS[char]
for y in range(5):
for x in range(3):
if matrix[y][x] == 1:
cuboids.append(Cuboid(1, 1, 1, (start_pos[0] + main_offset + x, start_pos[1] - y, start_pos[2])))
main_offset += 6
return cuboids
cuboids = [
Cuboid(5, 5, 5, (0, 0, 0)),
]
tetrahedrons = [
Tetrahedron((6, 0, 0), (11, 0, 0), (6, 5, 0), (6, 0, 5)),
]
prisms = [
Prism(((12, 0, 0), (13, 0, 5), (16, 0, 5), (17, 0, 0)), 5)
]
pyramids = [
Pyramid((18, 0, 2.5), (19, 0, 1), (20.5, 0, 0), (22, 0, 1), (23, 0, 2.5), (22, 0, 4), (20.5, 0, 5), (19, 0, 4), (20.5, 5, 2.5))
]
def main():
states = ["Cuboid", "Tetrahedron", "Prism", "Pyramid"]
state = 0
def r():
return rd.randint(1, 10)
while cfg.running:
cfg.screen.fill((0, 0, 0))
cfg.screen.blit(font.render(f"XYZ: {camera.x:.3f} | {camera.y:.3f} | {camera.z:.3f}", True, (255, 255, 255)), (15, 15))
cfg.screen.blit(font.render(f"Rotation: {rad2deg(camera.dx):.3f} | {rad2deg(camera.dy):.3f}", True, (255, 255, 255)), (15, 30))
cfg.screen.blit(font.render(f"FoV: {camera.fov:.3f}", True, (255, 255, 255)), (15, 45))
cfg.screen.blit(font.render(f"Current object: {states[state]}", True, (255, 255, 255)), (15, 60))
for event in pg.event.get():
if event.type == pg.QUIT:
cfg.running = False
if event.type == pg.KEYDOWN:
if event.key == pg.K_LALT:
cfg.camera_motion = not cfg.camera_motion
if cfg.camera_motion:
pg.event.set_grab(True)
pg.mouse.set_visible(False)
else:
pg.event.set_grab(False)
pg.mouse.set_visible(True)
pg.mouse.set_pos(cfg.CXTH, cfg.CYTH)
if event.key == pg.K_q and state > 0:
state -= 1
if event.key == pg.K_e and state < 3:
state += 1
if event.type == pg.MOUSEWHEEL:
if event.y > 0.5 and 30 < camera.fov:
camera.fov -= 1
camera.f = camera.get_focus(cfg.screen, camera.fov)/2
elif event.y < 0.5 and camera.fov < 120:
camera.fov += 1
camera.f = camera.get_focus(cfg.screen, camera.fov)/2
if event.type == pg.MOUSEBUTTONDOWN:
if event.button == pg.BUTTON_RIGHT:
if state == 0:
cuboids.append(Cuboid(r(), r(), r(), (camera.x, camera.y, camera.z)))
elif state == 1:
tetrahedrons.append(Tetrahedron((camera.x, camera.y, camera.z), (r(), r(), r()), (r(), r(), r()), (r(), r(), r())))
if cfg.camera_motion:
if event.type == pg.MOUSEMOTION:
camera.dx += event.rel[0] * 0.001
camera.dy = max(min(camera.dy - event.rel[1] * 0.001, 1.5), -1.5)
if camera.dx > np.pi:
camera.dx -= 2*np.pi
elif camera.dx <= -np.pi:
camera.dx += 2*np.pi
camera.vector = camera.get_direction_vector()
camera.move()
for cuboid in cuboids:
cuboid.render(cfg.screen)
cuboid.update()
for tetrahedron in tetrahedrons:
tetrahedron.render(cfg.screen)
tetrahedron.update()
for prism in prisms:
prism.render(cfg.screen)
prism.update()
for pyramid in pyramids:
pyramid.render(cfg.screen)
pyramid.update()
cfg.CLOCK.tick(240)
pg.display.update()
if __name__ == "__main__":
start_console()
main()