Skip to content

Commit

Permalink
Merge branch 'panning' of https://github.com/dvj/pyqtgraph into dvj-p…
Browse files Browse the repository at this point in the history
…anning
  • Loading branch information
campagnola committed Jun 5, 2018
2 parents 01c349e + 87efc24 commit 741e65c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pyqtgraph/opengl/GLViewWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,22 @@ def mouseMoveEvent(self, ev):
self.mousePos = ev.pos()

if ev.buttons() == QtCore.Qt.LeftButton:
self.orbit(-diff.x(), diff.y())
#print self.opts['azimuth'], self.opts['elevation']
if (ev.modifiers() & QtCore.Qt.ControlModifier):
# pan in plane of camera
elev = np.radians(self.opts['elevation'])
azim = np.radians(self.opts['azimuth'])
fov = np.radians(self.opts['fov'])
dist = (self.opts['center'] - self.cameraPosition()).length()
fov_factor = np.tan(fov / 2) * 2
scale_factor = dist * fov_factor / self.width()
dx = diff.x()
dy = diff.y()
z = scale_factor * np.cos(elev) * dy
x = scale_factor * (np.sin(azim) * dx - np.sin(elev) * np.cos(azim) * dy)
y = scale_factor * (np.cos(azim) * dx + np.sin(elev) * np.sin(azim) * dy)
self.pan(x, -y, z, relative=False)
else:
self.orbit(-diff.x(), diff.y())
elif ev.buttons() == QtCore.Qt.MidButton:
if (ev.modifiers() & QtCore.Qt.ControlModifier):
self.pan(diff.x(), 0, diff.y(), relative=True)
Expand Down

0 comments on commit 741e65c

Please sign in to comment.