Commit ff4aaf4f authored by Guillaume Seguin's avatar Guillaume Seguin

Store zoom factor and lock quaternion changes

parent 12da0a83
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Printrun. If not, see <http://www.gnu.org/licenses/>. # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
from threading import Lock
import wx import wx
from wx import glcanvas from wx import glcanvas
...@@ -51,6 +53,10 @@ class wxGLPanel(wx.Panel): ...@@ -51,6 +53,10 @@ class wxGLPanel(wx.Panel):
self.sizer.Add(self.canvas, 1, wx.EXPAND) self.sizer.Add(self.canvas, 1, wx.EXPAND)
self.SetSizerAndFit(self.sizer) self.SetSizerAndFit(self.sizer)
self.rot_lock = Lock()
self.basequat = [0, 0, 0, 1]
self.zoom_factor = 1.0
# bind events # bind events
self.canvas.Bind(wx.EVT_ERASE_BACKGROUND, self.processEraseBackgroundEvent) self.canvas.Bind(wx.EVT_ERASE_BACKGROUND, self.processEraseBackgroundEvent)
self.canvas.Bind(wx.EVT_SIZE, self.processSizeEvent) self.canvas.Bind(wx.EVT_SIZE, self.processSizeEvent)
...@@ -144,6 +150,7 @@ class wxGLPanel(wx.Panel): ...@@ -144,6 +150,7 @@ class wxGLPanel(wx.Panel):
glLoadIdentity() glLoadIdentity()
if self.orthographic: if self.orthographic:
ratio = factor * float(min(self.width, self.height)) / self.dist ratio = factor * float(min(self.width, self.height)) / self.dist
self.zoom_factor = 1.0
glScalef(ratio, ratio, 1) glScalef(ratio, ratio, 1)
def OnDraw(self, *args, **kwargs): def OnDraw(self, *args, **kwargs):
...@@ -197,6 +204,7 @@ class wxGLPanel(wx.Panel): ...@@ -197,6 +204,7 @@ class wxGLPanel(wx.Panel):
delta_y = to[1] delta_y = to[1]
glTranslatef(delta_x, delta_y, 0) glTranslatef(delta_x, delta_y, 0)
glScalef(factor, factor, 1) glScalef(factor, factor, 1)
self.zoom_factor *= factor
if to: if to:
glTranslatef(-delta_x, -delta_y, 0) glTranslatef(-delta_x, -delta_y, 0)
wx.CallAfter(self.Refresh) wx.CallAfter(self.Refresh)
...@@ -218,6 +226,7 @@ class wxGLPanel(wx.Panel): ...@@ -218,6 +226,7 @@ class wxGLPanel(wx.Panel):
p2x = float(p2[0]) / (sz[0] / 2) - 1 p2x = float(p2[0]) / (sz[0] / 2) - 1
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)
with self.rot_lock:
self.basequat = mulquat(self.basequat, quat) self.basequat = mulquat(self.basequat, quat)
self.initpos = p2 self.initpos = p2
......
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