From 850a3ac48046e3630524c67ecac5e2f26d499b3f Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Tue, 8 Oct 2019 20:55:57 +0200 Subject: Improve mouse monitoring, add 3d view shift support --- utility/mouse.py | 25 ++++++++++++++++--------- utility/projection.py | 7 +++++++ 2 files changed, 23 insertions(+), 9 deletions(-) (limited to 'utility') diff --git a/utility/mouse.py b/utility/mouse.py index 29d660d..5d7dd5d 100644 --- a/utility/mouse.py +++ b/utility/mouse.py @@ -1,11 +1,10 @@ from OpenGL.GLUT import * class MouseDragMonitor: - def __init__(self, button, drag_callback, zoom_callback): + def __init__(self, button, callback): self.button = button self.active = False - self.drag_callback = drag_callback - self.zoom_callback = zoom_callback + self.callback = callback def on_mouse(self, button, state, x, y): if button == self.button: @@ -13,15 +12,23 @@ class MouseDragMonitor: self.last_x = x self.last_y = y - if button == 3: - self.zoom_callback(-1.0) - elif button == 4: - self.zoom_callback(1.0) - 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.drag_callback(delta_x, delta_y) + self.callback(delta_x, delta_y) + +class MouseScrollMonitor: + def __init__(self, callback): + self.callback = callback + + def on_mouse(self, button, state, x, y): + if button == 3: + self.callback(-1.0) + elif button == 4: + self.callback(1.0) + + def on_mouse_move(self, x, y): + pass diff --git a/utility/projection.py b/utility/projection.py index 335e488..1750fac 100644 --- a/utility/projection.py +++ b/utility/projection.py @@ -39,6 +39,13 @@ class Rotation: self.rotation_x = quaternion.Quaternion() self.update(x,z) + def shift(self, x, z): + self.matrix = numpy.matmul( + self.matrix, + matrix44.create_from_translation([x,0,z]) + ) + self.inverse_matrix = numpy.linalg.inv(self.matrix) + def update(self, x, z): rotation_x = quaternion.Quaternion(quaternion.create_from_eulers([x,0,0])) rotation_z = self.rotation_x.conjugate.cross( -- cgit v1.2.3