-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cube_file.py
More file actions
123 lines (101 loc) · 2.44 KB
/
test_cube_file.py
File metadata and controls
123 lines (101 loc) · 2.44 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
import pygame
import random
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
vertices = (
(1, -1, -1),
(1, 1, -1),
(-1, 1, -1),
(-1, -1, -1),
(1, -1, 1),
(1, 1, 1),
(-1, 1, 1),
(-1, -1, 1)
)
tri = (
(0,1,2),
(0,3,2),
(0,4,5),
(0,1,5),
(0,4,7),
(0,3,7),
(6,2,1),
(6,5,1),
(6,2,3),
(6,7,3),
(6,7,4),
(6,5,4)
)
edges = (
(0,1),
(0,3),
(0,4),
(2,1),
(2,3),
(2,6),
(7,3),
(7,4),
(6,7),
(5,1),
(5,4),
(5,6)
)
clrs = [(0,1,0),(1,0,0),(0,0,1),(1,1,0),(1,0,1),(0,1,1),(1,1,1),(0,0,0)]
def Cube(r):
glBegin(GL_TRIANGLES) #we could do quads, i just already have triangle info
#because of mass calculations
for edge in tri:
glVertex3fv(vertices[edge[0]])
glVertex3fv(vertices[edge[1]])
glVertex3fv(vertices[edge[2]])
glEnd()
def main():
pygame.init()
display = (800,600)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
gluPerspective(45, (display[0]/display[1]), 0.1, 50.0)
glMaterial(GL_FRONT, GL_AMBIENT, (0.1, 0.1, 0.1, 1.0))
glMaterial(GL_FRONT, GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0))
glTranslate(0,0,-40)
glEnable(GL_DEPTH_TEST)
glShadeModel(GL_FLAT)
glClearColor(1.0, 1.0, 1.0, 0.0)
glEnable(GL_COLOR_MATERIAL)
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glLightfv(GL_LIGHT0, GL_POSITION, (10, 10, 10))
crash = False
while not crash:
r = (0,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_LEFT]:
glTranslatef(0.1,0,0)
if keys[pygame.K_RIGHT]:
glTranslatef(-0.1,0,0)
if keys[pygame.K_UP]:
glTranslatef(0,0,0.1)
if keys[pygame.K_DOWN]:
glTranslatef(0,0,-0.1)
if keys[pygame.K_r]:
r = (10,0,1,0)
x = glGetDoublev(GL_MODELVIEW_MATRIX)
#print(x)
camera_x=x[3][0]
camera_y=x[3][1]
camera_z=x[3][2]
if camera_z < -1:
crash = True
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glTranslatef(0,0,0.2)
Cube(r)
pygame.display.flip()
pygame.time.wait(10)
for i in range(10):
main()
pygame.quit()
quit()