aboutsummaryrefslogtreecommitdiff
path: root/utility
diff options
context:
space:
mode:
authorAdrian Kummerlaender2019-09-22 15:56:40 +0200
committerAdrian Kummerlaender2019-09-22 15:56:40 +0200
commitab930a71ca076480f78a6a5f42ac2ff5cef24d08 (patch)
tree8d4d72c2a35f2edd838ceed43b39992d0747d256 /utility
parent86a98e34f93e20cf811a0a7965d211b5fe891018 (diff)
downloadsymlbm_playground-ab930a71ca076480f78a6a5f42ac2ff5cef24d08.tar
symlbm_playground-ab930a71ca076480f78a6a5f42ac2ff5cef24d08.tar.gz
symlbm_playground-ab930a71ca076480f78a6a5f42ac2ff5cef24d08.tar.bz2
symlbm_playground-ab930a71ca076480f78a6a5f42ac2ff5cef24d08.tar.lz
symlbm_playground-ab930a71ca076480f78a6a5f42ac2ff5cef24d08.tar.xz
symlbm_playground-ab930a71ca076480f78a6a5f42ac2ff5cef24d08.tar.zst
symlbm_playground-ab930a71ca076480f78a6a5f42ac2ff5cef24d08.zip
Enable mouse-based view rotation
Diffstat (limited to 'utility')
-rw-r--r--utility/mouse.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/utility/mouse.py b/utility/mouse.py
new file mode 100644
index 0000000..c36d7e8
--- /dev/null
+++ b/utility/mouse.py
@@ -0,0 +1,21 @@
+from OpenGL.GLUT import *
+
+class MouseDragMonitor:
+ def __init__(self, button, callback):
+ self.button = button
+ self.callback = callback
+ self.active = False
+
+ def on_mouse(self, button, state, x, y):
+ if button == self.button:
+ self.active = (state == GLUT_DOWN)
+ self.last_x = x
+ self.last_y = y
+
+ def on_mouse_move(self, x, y):
+ if self.active:
+ delta_x = self.last_x - x
+ delta_y = y - self.last_y
+ self.last_x = x
+ self.last_y = y
+ self.callback(delta_x, delta_y)