-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
50 lines (36 loc) · 1.4 KB
/
main.py
File metadata and controls
50 lines (36 loc) · 1.4 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
#!/usr/bin/python
from display import Display
from star3d import Star3D
from rendercontext import RenderContext
from vertex import Vertex
from enginemaths import Matrix4f
import math
def main():
display = Display(600, 400, "Software Renderer")
stars = Star3D(1000, 64.0, 20.0)
shape = RenderContext(display.get_target(),600,400)
minYVert = Vertex(-1,-1,0)
midYVert = Vertex(0,1,0)
maxYVert = Vertex(1,-1,0)
# projection matrix
projection = Matrix4f().init_perspective(math.radians(70.0),
display.get_aspect_ratio(),
0.1, 1000.0)
rotCounter = 0.0
while display.is_running():
display.poll_events()
# stars.update_and_render(display.get_target(), display.get_delta())
rotCounter += display.get_delta()
translation = Matrix4f().init_translation(0.0, 0.0, 3.0)
rotation = Matrix4f().init_rotation(0.0, rotCounter, 0.0)
finalTransform = projection * translation * rotation
# Clear screen to black
display.get_target().fill((0,0,0))
# Draw shape
shape.fill_triangle(midYVert.transform(finalTransform),
maxYVert.transform(finalTransform),
minYVert.transform(finalTransform))
display.render()
display.clean_up()
if __name__=="__main__":
main()