-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.py
112 lines (95 loc) · 3.61 KB
/
controller.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
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
from modelo import *
import glfw
class Controller(object):
def __init__(self):
self.showAxis = False
self.distance = 3
self.camera_theta = np.pi/4
self.camX = -np.cos(self.camera_theta)
self.camY = -np.sin(self.camera_theta)
self.viewPos = np.array([self.distance*self.camX,self.distance*self.camY, self.distance])
self.camAt = np.array([0,0,0])
self.camUp = np.array([0, 0, 1])
self.edificio = 0
self.projection = tr.perspective(45, float(1000) / float(1000), 0.1, 100)
self.trayectoria = True
self.model = None
self.stop = False
self.agua = True
def set_model(self, m):
self.model = m
def setView(self):
view = tr.lookAt(
self.viewPos,
self.camAt,
self.camUp
)
return view
def on_key(self, window, key, scancode, action, mods):
if action != glfw.PRESS:
return
if key == glfw.KEY_ESCAPE:
glfw.set_window_should_close(window, True)
# Controlador modifica al modelo
elif key == glfw.KEY_1:
# Camara Frontal
self.camX = 0
self.camY = -1
self.distance = 3
self.viewPos = np.array([self.distance*self.camX, self.distance*self.camY, 0.5]) # Vista frontal
self.camAt = np.array([0, 0, 0.5])
self.camUp = np.array([0, 0, 1])
print('Camara Frontal')
elif key == glfw.KEY_2:
# Camara elevada-lateral Derecha
self.camera_theta = 5*np.pi/4
self.camX = np.cos(self.camera_theta)
self.camY = np.sin(self.camera_theta)
self.distance = 3
self.viewPos = np.array([self.distance*self.camX, -self.distance*self.camY, self.distance]) # Vista diagonal 1
self.camAt = np.array([0,0,0])
self.camUp = np.array([0, 0, 1])
print('Camara Descendiente-Lateral Derecha')
elif key == glfw.KEY_3:
# Camara descendiente-diagonal Izquierda
self.camera_theta = np.pi/4
self.camX = np.cos(self.camera_theta)
self.camY = np.sin(self.camera_theta)
self.distance = 3
self.viewPos = np.array([self.distance*self.camX, self.distance*self.camY, self.distance]) # Vista diagonal 1
self.camAt = np.array([0,0,0])
self.camUp = np.array([0, 0, 1])
print('Camara Lateral-Diagonal Izquierda')
elif key == glfw.KEY_4:
# Camara Superior
self.camera_theta = 2*np.pi
self.camX = -2 * np.cos(self.camera_theta)
self.camY = -2 * np.sin(self.camera_theta)
self.distance = 3
self.viewPos = np.array([0, 0, self.distance]) # Vista superior
self.camAt = np.array([0,0,0])
self.camUp = np.array([0, 1, 0])
print('Camara Superior')
elif key == glfw.KEY_X:
if self.showAxis:
self.showAxis = False
else:
self.showAxis = True
elif key == glfw.KEY_SPACE:
if self.trayectoria:
self.trayectoria = False
else:
self.trayectoria = True
elif key == glfw.KEY_S:
if self.stop:
self.stop = False
else:
self.stop = True
elif key == glfw.KEY_A:
if self.agua:
self.agua = False
else:
self.agua = True
# Cualquier otra cosa
else:
print('Unknown key')