From ab930a71ca076480f78a6a5f42ac2ff5cef24d08 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 22 Sep 2019 15:56:40 +0200 Subject: Enable mouse-based view rotation --- utility/mouse.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 utility/mouse.py (limited to 'utility') 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) -- cgit v1.2.3