-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain Scene.py
More file actions
211 lines (157 loc) · 8.24 KB
/
Main Scene.py
File metadata and controls
211 lines (157 loc) · 8.24 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import pygame
from texture import Texture
# import the scene class
from scene import Scene
from numpy import random
from lightSource import LightSource
from BaseModel2 import DrawModelFromMesh
# from AniModel import DrawAniModelFromMesh
from shaders import *
class ParisScene(Scene):
def __init__(self):
Scene.__init__(self)
self.lights.append(LightSource(self, position=[5., 3., 5.], Ia=[1,1,1]))
self.camera.psi = 0.1
self.noise = np.random.rand(3000)
self.stretch_value = 0
self.stretch = True
self.animated = False
self.add_model(DrawModelFromMesh(scene=self,
scene_pos=(scaleMatrix([0.04,0.04,0.04])),
file_name='models/man.obj',
shader=FlatShader()))
self.add_model(DrawModelFromMesh(scene=self,
scene_pos=(scaleMatrix([0.13,0.07,0.095])),
file_name='models/stand.obj',
shader=FlatShader()))
self.add_model(DrawModelFromMesh(scene=self,
scene_pos=np.matmul(translationMatrix([0,-1.55,-2.6]),scaleMatrix([0.25,0.2,0.2])),
file_name='models/eiffel_platform.obj',
shader=TextureShader()))
self.add_model(DrawModelFromMesh(scene=self,
scene_pos=np.matmul(translationMatrix([0,-1.5,-30]), scaleMatrix([0.13,0.13,0.13])),
file_name='models/eiffel_tower.obj',
shader=FlatShader()))
self.add_model(DrawModelFromMesh(scene=self, scene_pos=np.matmul(translationMatrix([0,-1.6,-20]), scaleMatrix([2,5,5])), file_name='models/floor.obj', shader=FlatShader()))
self.add_model(DrawModelFromMesh(scene=self, scene_pos=scaleMatrix([0.5,0.09,0.3]), file_name='models/hedge.obj', shader=TextureShader()))
self.add_model(DrawModelFromMesh(scene=self, scene_pos=scaleMatrix([0.5,0.5,0.5]), file_name='models/spotlight.obj', shader=FlatShader()))
def draw(self):
'''
Draw all models in the scene
:return: None
'''
# first we need to clear the scene, we also clear the depth buffer to handle occlusions
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
self.camera.update()
noise_marker = 0
if self.animated:
if self.stretch_value > 0.02:
self.stretch = False
elif self.stretch_value <= 0.:
self.stretch = True
if self.stretch:
self.stretch_value += 0.01
else:
self.stretch_value -= 0.01
man_queue_length_z = 85
man_offset_z = -3.
man_offset_x = -1.11
self.men = []
for i in range(man_queue_length_z):
if i % 2 == 0:
man_matrix = (translationMatrix([man_offset_x, -1.6, man_offset_z]) @ rotationMatrixY(np.deg2rad(90)) @ scaleMatrix([1,1+self.stretch_value,1]))
self.models[0].draw(man_matrix)
for _ in range(2):
noisy_friend = man_offset_x - self.noise[noise_marker]
noise_marker += 1
if noisy_friend > -1.15:
man_matrix = (translationMatrix([noisy_friend, -1.6, (man_offset_z - self.noise[noise_marker+1]/2)]) @ rotationMatrixY(np.deg2rad(90)) @scaleMatrix([1,1+self.stretch_value,1]))
self.models[0].draw(man_matrix)
noise_marker += 1
else:
man_matrix = (translationMatrix([-man_offset_x, -1.6, man_offset_z]) @ rotationMatrixY(np.deg2rad(270)) @ scaleMatrix([1,1+self.stretch_value,1]))
self.models[0].draw(man_matrix)
for _ in range(2):
noisy_friend = -man_offset_x + self.noise[noise_marker]
noise_marker += 1
if noisy_friend < 1.15:
man_matrix = (translationMatrix([noisy_friend, -1.6, (man_offset_z - self.noise[noise_marker+1]/2)]) @ rotationMatrixY(np.deg2rad(270)) @scaleMatrix([1,1+self.stretch_value,1]))
self.models[0].draw(man_matrix)
noise_marker += 1
man_offset_z -= 0.15
if man_offset_x < -0.36:
man_offset_x += 0.9/(i+9)
elif man_offset_x >= -0.36:
man_offset_x += 0.005
x_setpoint = 1.3
y_setpoint = -1.6
z_setpoint = -3.2
for _ in range(3):
x_position = x_setpoint
y_position = y_setpoint
for _ in range(16):
z_position = z_setpoint
for _ in range(20):
if self.noise[noise_marker] < 0.3:
man_matrix = translationMatrix([x_position, y_position, z_position]) @ rotationMatrixY(np.deg2rad(270)) @scaleMatrix([1,1+self.stretch_value,1])
self.models[0].draw(man_matrix)
noise_marker+=1
if self.noise[noise_marker] < 0.3:
man_matrix = translationMatrix([-x_position, y_position, z_position]) @ rotationMatrixY(np.deg2rad(90)) @scaleMatrix([1,1+self.stretch_value,1])
self.models[0].draw(man_matrix)
noise_marker+=1
z_position -= 0.13
y_position += 0.02
x_position += 0.1
z_setpoint -= 3
stand_count = 6
stand_offset = -4.5
for j in range(stand_count):
if j % 2 == 0:
self.models[1].draw(translationMatrix([-2.1,-1.6,stand_offset]) @ rotationMatrixY(np.deg2rad(90)))
else:
self.models[1].draw(translationMatrix([2.1,-1.6,stand_offset]) @ rotationMatrixY(np.deg2rad(270)))
stand_offset -= 3
light_count = 4
light_offset = -5
for j in range(light_count):
if j % 2 == 0:
self.models[6].draw(translationMatrix([-5,2,light_offset]) @ rotationMatrixY(np.deg2rad(90)) @ rotationMatrixX(np.deg2rad(-45)))
self.lights.append(LightSource(self, position=[-5,2,light_offset], Id=[0.5,0.5,0.5], Is=[0.8,0.8,0.8]))
else:
self.models[6].draw(translationMatrix([5,2,light_offset]) @ rotationMatrixY(np.deg2rad(270)) @ rotationMatrixX(np.deg2rad(-45)))
self.lights.append(LightSource(self, position=[5,2,light_offset], Id=[0.5,0.5,0.5], Is=[0.8,0.8,0.8]))
light_offset -= 7
hedge_count = 8
hedge_offset = -4.5
for j in range(hedge_count):
if j % 2 == 0:
self.models[5].draw(translationMatrix([-4,-1.6,hedge_offset]) @ rotationMatrixY(np.deg2rad(90)))
else:
self.models[5].draw(translationMatrix([4,-1.6,hedge_offset]) @ rotationMatrixY(np.deg2rad(270)))
hedge_offset -= 3
hedge_count = 8
hedge_offset = -7
for j in range(hedge_count):
if j % 2 == 0:
self.models[5].draw(translationMatrix([-3,-1.55,hedge_offset]) @ rotationMatrixY(np.deg2rad(90)))
else:
self.models[5].draw(translationMatrix([3,-1.55,hedge_offset]) @ rotationMatrixY(np.deg2rad(270)))
hedge_offset -= 10
self.models[2].draw()
self.models[3].draw()
self.models[4].draw()
# # then we loop over all models in the list and draw them
# for model in self.models:
# model.draw()
# once we are done drawing, we display the scene
# Note that here we use double buffering to avoid artefacts:
# we draw on a different buffer than the one we display,
# and flip the two buffers once we are done drawing.
pygame.display.flip()
if __name__ == '__main__':
# initialises the scene object
# scene = Scene(shaders='gouraud')
scene = ParisScene()
# starts drawing the scene
scene.run()