Commit aef07c3e authored by Guillaume Seguin's avatar Guillaume Seguin

Cleanup rotation & translation code

parent 6f7906eb
...@@ -291,22 +291,11 @@ class GcodeViewPanel(wxGLPanel): ...@@ -291,22 +291,11 @@ class GcodeViewPanel(wxGLPanel):
if self.parent.clickcb: if self.parent.clickcb:
self.parent.clickcb(event) self.parent.clickcb(event)
def move(self, event): def handle_rotation(self, event):
"""react to mouse actions:
no mouse: show red mousedrop
LMB: rotate viewport
RMB: move viewport
"""
if event.Entering():
self.canvas.SetFocus()
event.Skip()
return
if event.Dragging() and event.LeftIsDown():
if self.initpos == None: if self.initpos == None:
self.initpos = event.GetPositionTuple() self.initpos = event.GetPositionTuple()
else: else:
p1 = self.initpos p1 = self.initpos
self.initpos = None
p2 = event.GetPositionTuple() p2 = event.GetPositionTuple()
sz = self.GetClientSize() sz = self.GetClientSize()
p1x = float(p1[0]) / (sz[0] / 2) - 1 p1x = float(p1[0]) / (sz[0] / 2) - 1
...@@ -315,22 +304,39 @@ class GcodeViewPanel(wxGLPanel): ...@@ -315,22 +304,39 @@ class GcodeViewPanel(wxGLPanel):
p2y = 1 - float(p2[1]) / (sz[1] / 2) p2y = 1 - float(p2[1]) / (sz[1] / 2)
quat = trackball(p1x, p1y, p2x, p2y, self.dist / 250.0) quat = trackball(p1x, p1y, p2x, p2y, self.dist / 250.0)
self.basequat = mulquat(self.basequat, quat) self.basequat = mulquat(self.basequat, quat)
self.initpos = p2
elif event.ButtonUp(wx.MOUSE_BTN_LEFT): def handle_translation(self, event):
if self.initpos is not None:
self.initpos = None
elif event.ButtonUp(wx.MOUSE_BTN_RIGHT):
if self.initpos is not None:
self.initpos = None
elif event.Dragging() and event.RightIsDown():
if self.initpos is None: if self.initpos is None:
self.initpos = event.GetPositionTuple() self.initpos = event.GetPositionTuple()
else: else:
p1 = self.initpos p1 = self.initpos
p2 = event.GetPositionTuple() p2 = event.GetPositionTuple()
if self.orthographic:
x1, y1, _ = self.mouse_to_3d(p1[0], p1[1])
x2, y2, _ = self.mouse_to_3d(p2[0], p2[1])
glTranslatef(x2 - x1, y2 - y1, 0)
else:
glTranslatef(p2[0] - p1[0], -(p2[1] - p1[1]), 0) glTranslatef(p2[0] - p1[0], -(p2[1] - p1[1]), 0)
self.initpos = p2
def move(self, event):
"""react to mouse actions:
no mouse: show red mousedrop
LMB: rotate viewport
RMB: move viewport
"""
if event.Entering():
self.canvas.SetFocus()
event.Skip()
return
if event.Dragging() and event.LeftIsDown():
self.handle_rotation(event)
elif event.Dragging() and event.RightIsDown():
self.handle_translation(event)
elif event.ButtonUp(wx.MOUSE_BTN_LEFT):
self.initpos = None
elif event.ButtonUp(wx.MOUSE_BTN_RIGHT):
self.initpos = None self.initpos = None
else: else:
event.Skip() event.Skip()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment