Commit 1a5c64a1 authored by sumpfralle's avatar sumpfralle

r650@erker: lars | 2010-02-14 03:05:14 +0100

 moving the camera with the mouse works now (a bit)


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@115 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 1787c8ca
...@@ -12,7 +12,8 @@ import pycam.Cutters ...@@ -12,7 +12,8 @@ import pycam.Cutters
import pycam.PathGenerators import pycam.PathGenerators
import pycam.PathProcessors import pycam.PathProcessors
import pycam.Gui.ode_objects as ode_objects import pycam.Gui.ode_objects as ode_objects
from pycam.Geometry.utils import INFINITE import pycam.Geometry.utils as utils
from pycam.Geometry.Point import Point
import threading import threading
import pygtk import pygtk
import gtk import gtk
...@@ -28,7 +29,7 @@ BUTTON_ZOOM = gtk.gdk.BUTTON2_MASK ...@@ -28,7 +29,7 @@ BUTTON_ZOOM = gtk.gdk.BUTTON2_MASK
BUTTON_MOVE = gtk.gdk.BUTTON3_MASK BUTTON_MOVE = gtk.gdk.BUTTON3_MASK
VIEWS = { VIEWS = {
"reset": {"distance": (0.0, 5.0, 5.0), "center": (0.0, 0.0, 0.0), "up": (0.0, 0.0, 1.0), "znear": 0.1, "zfar": 1000.0, "fovy": 30.0}, "reset": {"distance": (4.0, 4.0, 4.0), "center": (0.0, 0.0, 0.0), "up": (0.0, 0.0, 1.0), "znear": 0.1, "zfar": 1000.0, "fovy": 30.0},
"top": {"distance": (0.0, 0.0, 10.0), "center": (0.0, 0.0, 0.0), "up": (1.0, 0.0, 0.0), "znear": 0.1, "zfar": 1000.0, "fovy": 30.0}, "top": {"distance": (0.0, 0.0, 10.0), "center": (0.0, 0.0, 0.0), "up": (1.0, 0.0, 0.0), "znear": 0.1, "zfar": 1000.0, "fovy": 30.0},
"bottom": {"distance": (0.0, 0.0, -10.0), "center": (0.0, 0.0, 0.0), "up": (1.0, 0.0, 0.0), "znear": 0.1, "zfar": 1000.0, "fovy": 30.0}, "bottom": {"distance": (0.0, 0.0, -10.0), "center": (0.0, 0.0, 0.0), "up": (1.0, 0.0, 0.0), "znear": 0.1, "zfar": 1000.0, "fovy": 30.0},
"left": {"distance": (-10.0, 0.0, 0.0), "center": (0.0, 0.0, 0.0), "up": (0.0, 0.0, 1.0), "znear": 0.1, "zfar": 1000.0, "fovy": 30.0}, "left": {"distance": (-10.0, 0.0, 0.0), "center": (0.0, 0.0, 0.0), "up": (0.0, 0.0, 1.0), "znear": 0.1, "zfar": 1000.0, "fovy": 30.0},
...@@ -131,6 +132,7 @@ class GLView: ...@@ -131,6 +132,7 @@ class GLView:
GL.glClearDepth(1.) GL.glClearDepth(1.)
GL.glEnable(GL.GL_DEPTH_TEST) GL.glEnable(GL.GL_DEPTH_TEST)
GL.glDepthFunc(GL.GL_LEQUAL) GL.glDepthFunc(GL.GL_LEQUAL)
GL.glDepthMask(GL.GL_TRUE)
GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST) GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST)
GL.glMatrixMode(GL.GL_MODELVIEW) GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, (0.1, 0.1, 0.1, 1.0)) GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, (0.1, 0.1, 0.1, 1.0))
...@@ -163,6 +165,7 @@ class GLView: ...@@ -163,6 +165,7 @@ class GLView:
else: else:
return return
else: else:
# not more than 25 frames per second (enough for decent visualization)
if time.time() - last_timestamp < 0.04: if time.time() - last_timestamp < 0.04:
return return
# a button was pressed before # a button was pressed before
...@@ -182,23 +185,36 @@ class GLView: ...@@ -182,23 +185,36 @@ class GLView:
elif state == self.mouse["button"] == BUTTON_MOVE: elif state == self.mouse["button"] == BUTTON_MOVE:
start_x, start_y = self.mouse["start_pos"] start_x, start_y = self.mouse["start_pos"]
self.mouse["start_pos"] = [x, y] self.mouse["start_pos"] = [x, y]
self.restore_view_setting()
prev_mode = GL.glGetDoublev(GL.GL_MATRIX_MODE)
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glPushMatrix()
#GL.glLoadIdentity()
height = self.area.allocation.height height = self.area.allocation.height
start_z = GL.glReadPixelsf(start_x, height - start_y, 1, 1, GL.GL_DEPTH_COMPONENT)[0][0] width = self.area.allocation.width
z = GL.glReadPixelsf(x, height - y, 1, 1, GL.GL_DEPTH_COMPONENT)[0][0] # the "up" vector defines, in what proportion each axis of the model is in line with the screen's y axis
print "%d / %d / %d" % (x, y, z) v_up = self.view["up"]
print self.get_current_projection_matrix() factors_y = (v_up[0], v_up[1], v_up[2])
#print "%f / %f / %f" % (x, y, z) # calculate the proportion of each model axis according to the x axis of the screen
print GLU.gluUnProject(x, y, z) distv = self.view["distance"]
GL.glPopMatrix() distv = Point(v[0], v[1], v[2]).normalize()
GL.glMatrixMode(prev_mode) factors_x = distv.cross(Point(v_up[0], v_up[1], v_up[2])).normalize()
factors_x = (factors_x.x, factors_x.y, factors_x.z)
# determine the biggest dimension (x/y/z) for moving the screen's center in relation to this value
obj_dim = []
obj_dim.append(self.settings.get("maxx") - self.settings.get("minx"))
obj_dim.append(self.settings.get("maxy") - self.settings.get("miny"))
obj_dim.append(self.settings.get("maxz") - self.settings.get("minz"))
max_dim = max(max(obj_dim[0], obj_dim[1]), obj_dim[2])
# relation of x/y movement to the respective screen dimension
win_x_rel = (0.0 + x - start_x)/width
win_y_rel = (0.0 + y - start_y)/height
# update the model position that should be centered on the screen
old_center = self.view["center"]
new_center = []
for i in range(3):
new_center.append(old_center[i] + max_dim * (win_x_rel * factors_x[i] + win_y_rel * factors_y[i]))
self.view["center"] = tuple(new_center)
self._paint_ignore_busy()
else: else:
# button was released # button was released
self.mouse["button"] = None self.mouse["button"] = None
self._paint_ignore_busy()
self.mouse["timestamp"] = time.time() self.mouse["timestamp"] = time.time()
def store_view_setting(self): def store_view_setting(self):
...@@ -351,7 +367,7 @@ class ProjectGui: ...@@ -351,7 +367,7 @@ class ProjectGui:
self.notify_visual.acquire() self.notify_visual.acquire()
self.notify_visual.notify() self.notify_visual.notify()
self.notify_visual.release() self.notify_visual.release()
self.view3d.reset_view() self.view3d.paint()
def reload_model(self): def reload_model(self):
self.physics = GuiCommon.generate_physics(self.settings) self.physics = GuiCommon.generate_physics(self.settings)
...@@ -373,7 +389,7 @@ class ProjectGui: ...@@ -373,7 +389,7 @@ class ProjectGui:
# do the gl initialization # do the gl initialization
self.view3d = GLView(self.gui, self.settings) self.view3d = GLView(self.gui, self.settings)
if self.model and self.view3d.enabled: if self.model and self.view3d.enabled:
self.reset_bounds(None) self.reset_bounds()
self.view3d.reset_view() self.view3d.reset_view()
#self.thread3d = VisualThread(self.notify_visual, self.settings) #self.thread3d = VisualThread(self.notify_visual, self.settings)
#self.thread3d.start() #self.thread3d.start()
...@@ -452,7 +468,7 @@ class ProjectGui: ...@@ -452,7 +468,7 @@ class ProjectGui:
self.update_view() self.update_view()
@gui_activity_guard @gui_activity_guard
def reset_bounds(self, widget, data=None): def reset_bounds(self, widget=None, data=None):
xwidth = self.model.maxx - self.model.minx xwidth = self.model.maxx - self.model.minx
ywidth = self.model.maxy - self.model.miny ywidth = self.model.maxy - self.model.miny
zwidth = self.model.maxz - self.model.minz zwidth = self.model.maxz - self.model.minz
...@@ -485,6 +501,8 @@ class ProjectGui: ...@@ -485,6 +501,8 @@ class ProjectGui:
if callable(filename): if callable(filename):
filename = filename() filename = filename()
self.model = pycam.Importers.STLImporter.ImportModel(filename) self.model = pycam.Importers.STLImporter.ImportModel(filename)
# do some initialization
self.append_to_queue(self.reset_bounds)
self.append_to_queue(self.toggle_3d_view, True) self.append_to_queue(self.toggle_3d_view, True)
self.append_to_queue(self.reload_model) self.append_to_queue(self.reload_model)
...@@ -536,11 +554,11 @@ class ProjectGui: ...@@ -536,11 +554,11 @@ class ProjectGui:
if samples>1: if samples>1:
dx = (maxx-minx)/(samples-1) dx = (maxx-minx)/(samples-1)
else: else:
dx = INFINITE dx = utils.INFINITE
if lines>1: if lines>1:
dy = (maxy-miny)/(lines-1) dy = (maxy-miny)/(lines-1)
else: else:
dy = INFINITE dy = utils.INFINITE
if direction == "x": if direction == "x":
self.toolpath = self.pathgenerator.GenerateToolPath(minx, maxx, miny, maxy, minz, maxz, dx, dy, 0) self.toolpath = self.pathgenerator.GenerateToolPath(minx, maxx, miny, maxy, minz, maxz, dx, dy, 0)
elif direction == "y": elif direction == "y":
...@@ -563,15 +581,15 @@ class ProjectGui: ...@@ -563,15 +581,15 @@ class ProjectGui:
if pathprocessor == "ContourCutter" and samples>1: if pathprocessor == "ContourCutter" and samples>1:
dx = (maxx-minx)/(samples-1) dx = (maxx-minx)/(samples-1)
else: else:
dx = INFINITE dx = utils.INFINITE
if lines>1: if lines>1:
dy = (maxy-miny)/(lines-1) dy = (maxy-miny)/(lines-1)
else: else:
dy = INFINITE dy = utils.INFINITE
if layers>1: if layers>1:
dz = (maxz-minz)/(layers-1) dz = (maxz-minz)/(layers-1)
else: else:
dz = INFINITE dz = utils.INFINITE
if direction == "x": if direction == "x":
self.toolpath = self.pathgenerator.GenerateToolPath(minx, maxx, miny, maxy, minz, maxz, 0, dy, dz) self.toolpath = self.pathgenerator.GenerateToolPath(minx, maxx, miny, maxy, minz, maxz, 0, dy, dz)
elif direction == "y": elif direction == "y":
......
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