aboutsummaryrefslogtreecommitdiff
path: root/channel_3d_gl_interop.py
diff options
context:
space:
mode:
Diffstat (limited to 'channel_3d_gl_interop.py')
-rw-r--r--channel_3d_gl_interop.py29
1 files changed, 8 insertions, 21 deletions
diff --git a/channel_3d_gl_interop.py b/channel_3d_gl_interop.py
index 569580d..535d595 100644
--- a/channel_3d_gl_interop.py
+++ b/channel_3d_gl_interop.py
@@ -18,7 +18,7 @@ from geometry.cylinder import Cylinder
from utility.projection import Projection, Rotation
from utility.opengl import MomentsVertexBuffer
-from utility.mouse import MouseDragMonitor
+from utility.mouse import MouseDragMonitor, MouseScrollMonitor
lattice_x = 256
lattice_y = 64
@@ -273,24 +273,11 @@ def on_display():
glutSwapBuffers()
-mouse_monitor = MouseDragMonitor(
- GLUT_LEFT_BUTTON,
- drag_callback = lambda dx, dy: rotation.update(0.005*dy, 0.005*dx),
- zoom_callback = lambda zoom: projection.update_distance(5*zoom))
-
-def on_keyboard(key, x, y):
- global rotation
-
- x = {
- b'w': -numpy.pi/10,
- b's': numpy.pi/10
- }.get(key, 0.0)
- z = {
- b'a': numpy.pi/10,
- b'd': -numpy.pi/10
- }.get(key, 0.0)
-
- rotation.update(x,z)
+mouse_monitors = [
+ MouseDragMonitor(GLUT_LEFT_BUTTON, lambda dx, dy: rotation.update(0.005*dy, 0.005*dx)),
+ MouseDragMonitor(GLUT_RIGHT_BUTTON, lambda dx, dy: rotation.shift(0.25*dx, 0.25*dy)),
+ MouseScrollMonitor(lambda zoom: projection.update_distance(5*zoom))
+]
def on_timer(t):
glutTimerFunc(t, on_timer, t)
@@ -298,8 +285,8 @@ def on_timer(t):
glutDisplayFunc(on_display)
glutReshapeFunc(lambda w, h: projection.update_ratio(w, h))
-glutMouseFunc(mouse_monitor.on_mouse)
-glutMotionFunc(mouse_monitor.on_mouse_move)
+glutMouseFunc(lambda *args: list(map(lambda m: m.on_mouse(*args), mouse_monitors)))
+glutMotionFunc(lambda *args: list(map(lambda m: m.on_mouse_move(*args), mouse_monitors)))
glutTimerFunc(10, on_timer, 10)
glutMainLoop()