Skip to content

Commit 4b41b5d

Browse files
committed
!U view control updated to more better way
1 parent 30de434 commit 4b41b5d

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

printrun/gl/panel.py

+24-4
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@
4141
GL_SRC_ALPHA, glTranslatef, gluPerspective, gluUnProject, \
4242
glViewport, GL_VIEWPORT
4343
from pyglet import gl
44-
from .trackball import trackball, mulquat
44+
from .trackball import trackball, mulquat,axis_to_quat
4545
from .libtatlin.actors import vec
4646

4747
class wxGLPanel(wx.Panel):
4848
'''A simple class for using OpenGL with wxPython.'''
4949

50+
orbit_control = True
5051
orthographic = True
5152
color_background = (0.98, 0.98, 0.78, 1)
5253
do_lights = True
@@ -80,6 +81,9 @@ def __init__(self, parent, id, pos = wx.DefaultPosition,
8081
self.rot_lock = Lock()
8182
self.basequat = [0, 0, 0, 1]
8283
self.zoom_factor = 1.0
84+
# top view
85+
self.angle_z = 0
86+
self.angle_x = 0 #math.radians(90);
8387

8488
self.gl_broken = False
8589

@@ -324,6 +328,18 @@ def zoom_to_center(self, factor):
324328
x, y, _ = self.mouse_to_3d(self.width / 2, self.height / 2)
325329
self.zoom(factor, (x, y))
326330

331+
def orbit(self, p1x, p1y, p2x, p2y):
332+
333+
rz = p2x-p1x;
334+
self.angle_z-=rz
335+
rotz = axis_to_quat([0.0,0.0,1.0],self.angle_z)
336+
337+
rx = p2y-p1y;
338+
self.angle_x+=rx
339+
rota = axis_to_quat([1.0,0.0,0.0],self.angle_x)
340+
341+
return mulquat(rotz,rota)
342+
327343
def handle_rotation(self, event):
328344
if self.initpos is None:
329345
self.initpos = event.GetPositionTuple()
@@ -335,9 +351,13 @@ def handle_rotation(self, event):
335351
p1y = 1 - float(p1[1]) / (sz[1] / 2)
336352
p2x = float(p2[0]) / (sz[0] / 2) - 1
337353
p2y = 1 - float(p2[1]) / (sz[1] / 2)
338-
quat = trackball(p1x, p1y, p2x, p2y, self.dist / 250.0)
339-
with self.rot_lock:
340-
self.basequat = mulquat(self.basequat, quat)
354+
if self.orbit_control:
355+
with self.rot_lock:
356+
self.basequat = self.orbit(p1x, p1y, p2x, p2y)
357+
else:
358+
quat = trackball(p1x, p1y, p2x, p2y, self.dist / 250.0)
359+
with self.rot_lock:
360+
self.basequat = mulquat(self.basequat, quat)
341361
self.initpos = p2
342362

343363
def handle_translation(self, event):

0 commit comments

Comments
 (0)