-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
54 lines (46 loc) · 1.73 KB
/
main.py
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
import pygame as pg
from View import *
from Projection_matrix import *
from Object_3d import *
class RenderGameSoftware:
def __init__(self):
self.axes = None
self.world_axes = None
self.object = None
self.projection = None
self.view = None
pg.init()
self.RES = self.WIDTH, self.HEIGHT = 1600, 900
self.H_WIDTH, self.H_HEIGHT = self.WIDTH // 2, self.HEIGHT // 2
self.FPS = 60
self.screen = pg.display.set_mode(self.RES)
self.clock = pg.time.Clock()
self.create_objects()
def create_objects(self):
self.view = View_scene(self, [0, 0, -70])
self.projection = Projection_struct(self)
self.object = self.get_object_from_file('Resource/Dragon.obj')
def get_object_from_file(self, filename):
vertex, faces = [], []
with open(filename) as f:
for line in f:
if line.startswith('v '):
vertex.append([float(i) for i in line.split()[1:]] + [1])
elif line.startswith('f'):
faces_ = line.split()[1:]
faces.append([int(face_.split('/')[0]) - 1 for face_ in faces_])
return Object_3d(self, vertex, faces)
def draw(self):
self.screen.fill(pg.Color('darkslategray'))
self.object.draw()
def run(self):
while True:
self.draw()
self.view.control()
[exit() for i in pg.event.get() if i.type == pg.QUIT]
pg.display.set_caption(str(self.clock.get_fps()))
pg.display.flip()
self.clock.tick(self.FPS)
if __name__ == '__main__':
app = RenderGameSoftware()
app.run()