41
41
GL_SRC_ALPHA , glTranslatef , gluPerspective , gluUnProject , \
42
42
glViewport , GL_VIEWPORT
43
43
from pyglet import gl
44
- from .trackball import trackball , mulquat
44
+ from .trackball import trackball , mulquat , axis_to_quat
45
45
from .libtatlin .actors import vec
46
46
47
47
class wxGLPanel (wx .Panel ):
48
48
'''A simple class for using OpenGL with wxPython.'''
49
49
50
+ orbit_control = True
50
51
orthographic = True
51
52
color_background = (0.98 , 0.98 , 0.78 , 1 )
52
53
do_lights = True
@@ -80,6 +81,9 @@ def __init__(self, parent, id, pos = wx.DefaultPosition,
80
81
self .rot_lock = Lock ()
81
82
self .basequat = [0 , 0 , 0 , 1 ]
82
83
self .zoom_factor = 1.0
84
+ # top view
85
+ self .angle_z = 0
86
+ self .angle_x = 0 #math.radians(90);
83
87
84
88
self .gl_broken = False
85
89
@@ -324,6 +328,18 @@ def zoom_to_center(self, factor):
324
328
x , y , _ = self .mouse_to_3d (self .width / 2 , self .height / 2 )
325
329
self .zoom (factor , (x , y ))
326
330
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
+
327
343
def handle_rotation (self , event ):
328
344
if self .initpos is None :
329
345
self .initpos = event .GetPositionTuple ()
@@ -335,9 +351,13 @@ def handle_rotation(self, event):
335
351
p1y = 1 - float (p1 [1 ]) / (sz [1 ] / 2 )
336
352
p2x = float (p2 [0 ]) / (sz [0 ] / 2 ) - 1
337
353
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 )
341
361
self .initpos = p2
342
362
343
363
def handle_translation (self , event ):
0 commit comments