Commit 0bba2c17 authored by Guillaume Seguin's avatar Guillaume Seguin

Follow up on c3799528: implement get_modelview_mat in gcview/stlview

parent 1289d3c2
......@@ -24,7 +24,8 @@ from .gl.libtatlin import actors
from .injectgcode import injector, injector_edit
from pyglet.gl import glPushMatrix, glPopMatrix, \
glTranslatef, glRotatef, glScalef, glMultMatrixd
glTranslatef, glRotatef, glScalef, glMultMatrixd, \
glGetDoublev, GL_MODELVIEW_MATRIX, GLdouble
from .gviz import GvizBaseFrame
......@@ -153,6 +154,25 @@ class GcodeViewPanel(wxGLPanel):
glPopMatrix()
glPopMatrix()
# ==========================================================================
# Utils
# ==========================================================================
def get_modelview_mat(self, local_transform):
mvmat = (GLdouble * 16)()
if local_transform:
glPushMatrix()
# Rotate according to trackball
glMultMatrixd(build_rotmatrix(self.basequat))
# Move origin to bottom left of platform
platformx0 = -self.build_dimensions[3] - self.parent.platform.width / 2
platformy0 = -self.build_dimensions[4] - self.parent.platform.depth / 2
glTranslatef(platformx0, platformy0, 0)
glGetDoublev(GL_MODELVIEW_MATRIX, mvmat)
glPopMatrix()
else:
glGetDoublev(GL_MODELVIEW_MATRIX, mvmat)
return mvmat
def double(self, event):
if hasattr(self.parent, "clickcb") and self.parent.clickcb:
self.parent.clickcb(event)
......
......@@ -38,9 +38,9 @@ from pyglet.gl import glEnable, glDisable, GL_LIGHTING, glLightfv, \
GL_MODELVIEW_MATRIX, GL_ONE_MINUS_SRC_ALPHA, glOrtho, \
GL_PROJECTION, GL_PROJECTION_MATRIX, glScalef, \
GL_SRC_ALPHA, glTranslatef, gluPerspective, gluUnProject, \
glViewport, GL_VIEWPORT, glPushMatrix, glPopMatrix, glMultMatrixd
glViewport, GL_VIEWPORT
from pyglet import gl
from .trackball import trackball, mulquat, build_rotmatrix
from .trackball import trackball, mulquat
from .libtatlin.actors import vec
class wxGLPanel(wx.Panel):
......@@ -248,19 +248,12 @@ class wxGLPanel(wx.Panel):
# ==========================================================================
# Utils
# ==========================================================================
def get_modelview_mat(self, mult_rot):
def get_modelview_mat(self, local_transform):
mvmat = (GLdouble * 16)()
if mult_rot:
glPushMatrix()
# Rotate according to trackball
glMultMatrixd(build_rotmatrix(self.basequat))
glGetDoublev(GL_MODELVIEW_MATRIX, mvmat)
glPopMatrix()
else:
glGetDoublev(GL_MODELVIEW_MATRIX, mvmat)
return mvmat
def mouse_to_3d(self, x, y, z = 1.0, mult_rot = False):
def mouse_to_3d(self, x, y, z = 1.0, local_transform = False):
x = float(x)
y = self.height - float(y)
# The following could work if we were not initially scaling to zoom on
......@@ -268,7 +261,7 @@ class wxGLPanel(wx.Panel):
# if self.orthographic:
# return (x - self.width / 2, y - self.height / 2, 0)
pmat = (GLdouble * 16)()
mvmat = self.get_modelview_mat(mult_rot)
mvmat = self.get_modelview_mat(local_transform)
viewport = (GLint * 4)()
px = (GLdouble)()
py = (GLdouble)()
......@@ -279,7 +272,7 @@ class wxGLPanel(wx.Panel):
gluUnProject(x, y, z, mvmat, pmat, viewport, px, py, pz)
return (px.value, py.value, pz.value)
def mouse_to_ray(self, x, y, mult_rot = False):
def mouse_to_ray(self, x, y, local_transform = False):
x = float(x)
y = self.height - float(y)
pmat = (GLdouble * 16)()
......@@ -290,7 +283,7 @@ class wxGLPanel(wx.Panel):
pz = (GLdouble)()
glGetIntegerv(GL_VIEWPORT, viewport)
glGetDoublev(GL_PROJECTION_MATRIX, pmat)
mvmat = self.get_modelview_mat(mult_rot)
mvmat = self.get_modelview_mat(local_transform)
gluUnProject(x, y, 0, mvmat, pmat, viewport, px, py, pz)
ray_far = (px.value, py.value, pz.value)
gluUnProject(x, y, 1., mvmat, pmat, viewport, px, py, pz)
......
......@@ -27,7 +27,8 @@ from pyglet.gl import GL_AMBIENT_AND_DIFFUSE, glBegin, glClearColor, \
GL_LIGHT1, glLightfv, GL_LIGHTING, GL_LINE, glMaterialf, glMaterialfv, \
glMultMatrixd, glNormal3f, glPolygonMode, glPopMatrix, GL_POSITION, \
glPushMatrix, glRotatef, glScalef, glShadeModel, GL_SHININESS, \
GL_SMOOTH, GL_SPECULAR, glTranslatef, GL_TRIANGLES, glVertex3f
GL_SMOOTH, GL_SPECULAR, glTranslatef, GL_TRIANGLES, glVertex3f, \
glGetDoublev, GL_MODELVIEW_MATRIX, GLdouble
from pyglet import gl
from .gl.panel import wxGLPanel
......@@ -180,7 +181,7 @@ class StlViewPanel(wxGLPanel):
delta = event.GetWheelRotation()
factor = 1.05
x, y = event.GetPositionTuple()
x, y, _ = self.mouse_to_3d(x, y)
x, y, _ = self.mouse_to_3d(x, y, local_transform = True)
if delta > 0:
self.zoom(factor, (x, y))
else:
......@@ -310,6 +311,24 @@ class StlViewPanel(wxGLPanel):
glPopMatrix()
glPopMatrix()
# ==========================================================================
# Utils
# ==========================================================================
def get_modelview_mat(self, local_transform):
mvmat = (GLdouble * 16)()
if local_transform:
glPushMatrix()
# Rotate according to trackball
glTranslatef(0, 0, -self.dist)
glMultMatrixd(build_rotmatrix(self.basequat)) # Rotate according to trackball
glTranslatef(- self.build_dimensions[3] - self.platform.width / 2,
- self.build_dimensions[4] - self.platform.depth / 2, 0) # Move origin to bottom left of platform
glGetDoublev(GL_MODELVIEW_MATRIX, mvmat)
glPopMatrix()
else:
glGetDoublev(GL_MODELVIEW_MATRIX, mvmat)
return mvmat
def main():
app = wx.App(redirect = False)
frame = wx.Frame(None, -1, "GL Window", size = (400, 400))
......
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