Commit 0354fb22 authored by Guillaume Seguin's avatar Guillaume Seguin

Start cleaning up move handling in gcview

parent 449b78e8
...@@ -97,13 +97,11 @@ class wxGLPanel(wx.Panel): ...@@ -97,13 +97,11 @@ class wxGLPanel(wx.Panel):
def OnInitGL(self): def OnInitGL(self):
'''Initialize OpenGL for use in the window.''' '''Initialize OpenGL for use in the window.'''
#create a pyglet context for this panel #create a pyglet context for this panel
self.pmat = (GLdouble * 16)()
self.mvmat = (GLdouble * 16)() self.mvmat = (GLdouble * 16)()
self.pygletcontext = gl.Context(gl.current_context) self.pygletcontext = gl.Context(gl.current_context)
self.pygletcontext.canvas = self self.pygletcontext.canvas = self
self.pygletcontext.set_current() self.pygletcontext.set_current()
self.dist = 1000 self.dist = 1000
self.vpmat = None
#normal gl init #normal gl init
glClearColor(0.98, 0.98, 0.78, 1) glClearColor(0.98, 0.98, 0.78, 1)
glClearDepth(1.0) # set depth value to 1 glClearDepth(1.0) # set depth value to 1
...@@ -126,8 +124,9 @@ class wxGLPanel(wx.Panel): ...@@ -126,8 +124,9 @@ class wxGLPanel(wx.Panel):
gluPerspective(60., width / float(height), .1, 1000.) gluPerspective(60., width / float(height), .1, 1000.)
glMatrixMode(GL_MODELVIEW) glMatrixMode(GL_MODELVIEW)
glLoadIdentity() glLoadIdentity()
self.vpmat = (GLint * 4)(0, 0, *list(self.GetClientSize())) glTranslatef(*self.transv)
glGetDoublev(GL_PROJECTION_MATRIX, self.pmat) glMultMatrixd(build_rotmatrix(self.basequat))
glGetDoublev(GL_MODELVIEW_MATRIX, self.mvmat)
# Wrap text to the width of the window # Wrap text to the width of the window
if self.GLinitialized: if self.GLinitialized:
...@@ -240,7 +239,6 @@ class GcodeViewPanel(wxGLPanel): ...@@ -240,7 +239,6 @@ class GcodeViewPanel(wxGLPanel):
def __init__(self, parent, id = wx.ID_ANY, build_dimensions = None, realparent = None): def __init__(self, parent, id = wx.ID_ANY, build_dimensions = None, realparent = None):
super(GcodeViewPanel, self).__init__(parent, id, wx.DefaultPosition, wx.DefaultSize, 0) super(GcodeViewPanel, self).__init__(parent, id, wx.DefaultPosition, wx.DefaultSize, 0)
self.batches = [] self.batches = []
self.rot = 0
self.canvas.Bind(wx.EVT_MOUSE_EVENTS, self.move) self.canvas.Bind(wx.EVT_MOUSE_EVENTS, self.move)
self.canvas.Bind(wx.EVT_LEFT_DCLICK, self.double) self.canvas.Bind(wx.EVT_LEFT_DCLICK, self.double)
self.canvas.Bind(wx.EVT_KEY_DOWN, self.keypress) self.canvas.Bind(wx.EVT_KEY_DOWN, self.keypress)
...@@ -268,16 +266,10 @@ class GcodeViewPanel(wxGLPanel): ...@@ -268,16 +266,10 @@ class GcodeViewPanel(wxGLPanel):
def draw_objects(self): def draw_objects(self):
'''called in the middle of ondraw after the buffer has been cleared''' '''called in the middle of ondraw after the buffer has been cleared'''
if self.vpmat is None:
return
self.create_objects() self.create_objects()
if self.rot == 1: glLoadIdentity()
glLoadIdentity() glMultMatrixd(self.mvmat)
glMultMatrixd(self.mvmat)
else:
glLoadIdentity()
glTranslatef(*self.transv)
glPushMatrix() glPushMatrix()
glTranslatef(-self.parent.platform.width/2, -self.parent.platform.depth/2, 0) glTranslatef(-self.parent.platform.width/2, -self.parent.platform.depth/2, 0)
...@@ -323,18 +315,12 @@ class GcodeViewPanel(wxGLPanel): ...@@ -323,18 +315,12 @@ class GcodeViewPanel(wxGLPanel):
p2y = -(float(p2[1]) - sz[1] / 2) / (sz[1] / 2) p2y = -(float(p2[1]) - sz[1] / 2) / (sz[1] / 2)
#print p1x, p1y, p2x, p2y #print p1x, p1y, p2x, p2y
quat = trackball(p1x, p1y, p2x, p2y, -self.transv[2] / 250.0) quat = trackball(p1x, p1y, p2x, p2y, -self.transv[2] / 250.0)
if self.rot: self.basequat = mulquat(self.basequat, quat)
self.basequat = mulquat(self.basequat, quat)
#else:
glGetDoublev(GL_MODELVIEW_MATRIX, self.mvmat)
#self.basequat = quatx
mat = build_rotmatrix(self.basequat) mat = build_rotmatrix(self.basequat)
glLoadIdentity() glLoadIdentity()
glTranslatef(self.transv[0], self.transv[1], 0) glTranslatef(*self.transv)
glTranslatef(0, 0, self.transv[2])
glMultMatrixd(mat) glMultMatrixd(mat)
glGetDoublev(GL_MODELVIEW_MATRIX, self.mvmat) glGetDoublev(GL_MODELVIEW_MATRIX, self.mvmat)
self.rot = 1
elif event.ButtonUp(wx.MOUSE_BTN_LEFT): elif event.ButtonUp(wx.MOUSE_BTN_LEFT):
if self.initpos is not None: if self.initpos is not None:
...@@ -361,12 +347,9 @@ class GcodeViewPanel(wxGLPanel): ...@@ -361,12 +347,9 @@ class GcodeViewPanel(wxGLPanel):
self.transv = map(lambda x, y, z, c: c - self.dist * (x - y) / z, p1, p2, sz, self.transv) self.transv = map(lambda x, y, z, c: c - self.dist * (x - y) / z, p1, p2, sz, self.transv)
glLoadIdentity() glLoadIdentity()
glTranslatef(self.transv[0], self.transv[1], 0) glTranslatef(*self.transv)
glTranslatef(0, 0, self.transv[2]) glMultMatrixd(build_rotmatrix(self.basequat))
if self.rot:
glMultMatrixd(build_rotmatrix(self.basequat))
glGetDoublev(GL_MODELVIEW_MATRIX, self.mvmat) glGetDoublev(GL_MODELVIEW_MATRIX, self.mvmat)
self.rot = 1
self.initpos = None self.initpos = None
else: else:
event.Skip() event.Skip()
...@@ -393,12 +376,11 @@ class GcodeViewPanel(wxGLPanel): ...@@ -393,12 +376,11 @@ class GcodeViewPanel(wxGLPanel):
def zoom(self, dist): def zoom(self, dist):
self.transv[2] += dist self.transv[2] += dist
glMatrixMode(GL_MODELVIEW)
glLoadIdentity() glLoadIdentity()
glTranslatef(*self.transv) glTranslatef(*self.transv)
if self.rot: glMultMatrixd(build_rotmatrix(self.basequat))
glMultMatrixd(build_rotmatrix(self.basequat))
glGetDoublev(GL_MODELVIEW_MATRIX, self.mvmat) glGetDoublev(GL_MODELVIEW_MATRIX, self.mvmat)
self.rot = 1
wx.CallAfter(self.Refresh) wx.CallAfter(self.Refresh)
def wheel(self, event): def wheel(self, event):
......
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