-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
83 lines (64 loc) · 2.13 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
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
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
import numpy as np
import math
from components.car import Car
from components.grid import Grid, rgb
# settings
SCREEN_HEIGHT = 720
SCREEN_WIDTH = 920
def main():
pygame.init()
display = (SCREEN_WIDTH, SCREEN_HEIGHT)
# set pygame up for 3d graphics
pygame.display.set_mode(display, DOUBLEBUF | OPENGL)
# pygame.mouse.set_visible(False)
gluPerspective(45, (display[0] / display[1]), 0.1, 50)
# Settup camera
t_x, t_y, t_z = -5, -5, -15
glTranslatef(t_x, t_y, t_z)
# now apply rottation so that it looks at the center
glRotatef(0, 0, 0, 0)
# draw pyramid as a solid object
glEnable(GL_DEPTH_TEST)
c1 = Car(rgb(100, 100, 1), rgb(200, 200, 1), (0, 0, 0), (0, 0, 0))
# c1.rotate(math.radians(45), 'y')
c2 = Car(rgb(100, 100, 100), rgb(255, 255, 255), (10, 0, 10), (0, 45, 0))
c3 = Car(rgb(150, 134, 200), rgb(178, 164, 255), (0, 0, 10), (0, 45, 0))
c4 = Car(rgb(150, 90, 90), rgb(255, 180, 180), (20, 0, 0), (0, 90, 0))
g1 = Grid()
velocity = 0.1
clock = pygame.time.Clock()
# camera settings
while True:
clock.tick(60)
# continually rotate pyramid
glRotatef(velocity * 1.1, 0, 1, 0)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
keys = pygame.key.get_pressed()
# if keys[pygame.K_w] and keys[pygame.K_d]:
# c1.turnCar((0,0.1,0), True)
# # c1.rotate(0.01, 'y')
# elif keys[pygame.K_w]:
# c1.moveForward(.005, True)
# elif keys[pygame.K_s]:
# c1.moveForward(.005, False)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
c1.draw()
c2.draw()
c2.rotate(0.01, "y")
c3.draw()
c3.rotate(0.03, "y")
c4.draw()
c4.rotate(0.02, "y")
g1.draw()
# p.draw()
# p2.draw()
pygame.display.flip()
if __name__ == "__main__":
main()