-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab2.py
More file actions
193 lines (173 loc) · 3.91 KB
/
lab2.py
File metadata and controls
193 lines (173 loc) · 3.91 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
from OpenGL.GL import *
import glfw
import math
delta = 0.0
angle = 0.0
angle1 = 0.0
posx = 0.0
posy = 0.0
posz = 0.0
size = 0.0
r=0.173205080757
run=0
seen=0
edges = (
(0,1),
(0,3),
(0,4),
(2,1),
(2,3),
(2,7),
(6,3),
(6,4),
(6,7),
(5,1),
(5,4),
(5,7)
)
grani =(
[0,1,2,3],
[4,5,7,6],
[0,1,5,4],
[2,3,6,7],
[1,2,7,5],
[0,3,6,4]
)
vertices= (
(0.1, -0.1, -0.1),
(0.1, 0.1, -0.1),
(-0.1, 0.1, -0.1),
(-0.1, -0.1, -0.1),
(0.1, -0.1, 0.1),
(0.1, 0.1, 0.1),
(-0.1, -0.1, 0.1),
(-0.1, 0.1, 0.1)
)
vertices1= (
(0.6, 0.6-r, 0.6-r),
(0.6+r, 0.6, 0.6),
(0.6, 0.6+r, 0.6+r),
(0.6-r, 0.6, 0.6),
(0.6, 0.6-r, 0.6+r),
(0.6+r, 0.6, 0.6+2*r),
(0.6-r, 0.6, 0.6+2*r),
(0.6, 0.6+r, 0.6+3*r)
)
def main():
if not glfw.init():
return
window = glfw.create_window(640, 640, "Lab2", None, None)
if not window:
glfw.terminate()
return
glfw.make_context_current(window)
glfw.set_key_callback(window, key_callback)
glfw.set_scroll_callback(window, scroll_callback)
while not glfw.window_should_close(window):
display(window)
glfw.destroy_window(window)
glfw.terminate()
def CubeSeen(vertices, grani):
glBegin(GL_QUADS)
for gr in grani:
for vertex in gr:
glColor3f(1.0,0.5,1.0)
glVertex3fv(vertices[vertex])
glEnd()
def CubeSeen1(vertices, grani):
glBegin(GL_QUADS)
for gr in grani:
for vertex in gr:
glColor3f(0.0,1.0,1.0)
glVertex3fv(vertices[vertex])
glEnd()
def Cube(vertices, edges):
glBegin(GL_LINES)
for edge in edges:
for vertex in edge:
glColor3f(1.0,0.5,1.0)
glVertex3fv(vertices[vertex])
glEnd()
def Cube1(vertices, edges):
glBegin(GL_LINES)
for edge in edges:
for vertex in edge:
glColor3f(0.0,1.0,1.0)
glVertex3fv(vertices[vertex])
glEnd()
def display(window):
global run
global seen
global angle
global angle1
glClear(GL_COLOR_BUFFER_BIT)
glLoadIdentity()
glClearColor(1.0, 1.0, 1.0, 1.0)
glPushMatrix()
#glRotatef(angle, 1, 1, 1)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glEnable(GL_DEPTH_TEST)
if seen==0:
Cube1(vertices1, edges)
else:
CubeSeen1(vertices1, grani)
glMatrixMode(GL_MODELVIEW)
c=math.cos(angle)
s=math.sin(angle)
oz=[c, s, 0, 0, -s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
glMultMatrixd(oz)
c=math.cos(angle1)
s=math.sin(angle1)
ox=[1, 0,0,0,0,c,s,0,0,-s,c,0,0,0,0,1]
glMultMatrixd(ox)
#oy=[c,0,-s,0,0,1,0,0,s,0,c,0,0,0,0,1]
#glMultMatrixd(oy)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glPushMatrix()
ct=0.81654081188
st=0.57728771208
cf=0.70710678118
sf=0.70710678118
m=[cf, sf*st, sf*ct, 0, 0, ct, -st, 0, sf, -cf*st, -cf*ct, 0, 0, 0, 0, 1]
glMultMatrixd(m)
if seen==0:
Cube(vertices, edges)
else:
CubeSeen(vertices, grani)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
run=1
#Cube(vertices, edges)
glPopMatrix()
angle += delta
glfw.swap_buffers(window)
glfw.poll_events()
def key_callback(window, key, scancode, action, mods):
global delta
global seen
global deltax
global angle
global angle1
global posy
if action == glfw.PRESS:
if key == glfw.KEY_RIGHT:
angle += 0.1
if key == 263: # glfw.KEY_LEFT
angle -= 0.1
if key == glfw.KEY_SPACE:
if seen==0:
seen=1
else:
seen=0
if key == glfw.KEY_UP:
angle1 += 0.1
if key == glfw.KEY_DOWN:
angle1 -= 0.1
def scroll_callback(window, xoffset, yoffset):
global size
if (xoffset > 0):
size -= yoffset/10
else:
size += yoffset/10
main()