1111import arcade
1212from arcade .math import clamp
1313from arcade .gl import geometry
14- from pyglet .math import Mat4
14+ from pyglet .math import Mat4 , Vec3
1515from pyglet .graphics import Batch
1616
1717
@@ -98,19 +98,19 @@ def __init__(self, width, height, title):
9898 self .rot_y = 0
9999 self .wireframe = True
100100 self .vert_count = 0.5
101- self .drag = False
102- self .time = 0
101+ self .drag_time = None
103102 self .flags = set ([self .ctx .DEPTH_TEST ])
104103
105104 def on_draw (self ):
106105 self .clear ()
107106 self .ctx .enable_only (* self .flags )
108107 self .ctx .wireframe = self .wireframe
108+ time = self .drag_time or self .time
109109
110110 # Position and rotate the sphere
111- translate = Mat4 .from_translation ((0 , 0 , - 2.5 ))
112- rx = Mat4 .from_rotation (self . time + self .rot_x , (0 , 1 , 0 ))
113- ry = Mat4 .from_rotation (self . time + self .rot_y , (1 , 0 , 0 ))
111+ translate = Mat4 .from_translation (Vec3 (0 , 0 , - 2.5 ))
112+ rx = Mat4 .from_rotation (time + self .rot_x , Vec3 (0 , 1 , 0 ))
113+ ry = Mat4 .from_rotation (time + self .rot_y , Vec3 (1 , 0 , 0 ))
114114 # Set matrices and draw
115115 self .view = translate @ rx @ ry
116116 self .projection = Mat4 .perspective_projection (self .aspect_ratio , 0.1 , 100 , fov = 60 )
@@ -125,10 +125,6 @@ def on_draw(self):
125125 with self .ctx .enabled_only ():
126126 self .text_batch .draw ()
127127
128- def on_update (self , dt ):
129- if not self .drag :
130- self .time += dt / 2
131-
132128 def on_key_press (self , key , modifiers ):
133129 if key == arcade .key .ESCAPE :
134130 self .close ()
@@ -157,12 +153,12 @@ def on_key_press(self, key, modifiers):
157153 self .text_cull .text = f"F2: Toggle cull face ({ self .ctx .CULL_FACE in self .flags } )"
158154
159155 def on_mouse_drag (self , x , y , dx , dy , buttons , modifiers ):
160- self .drag = True
156+ self .drag_time = self . time
161157 self .rot_x += dx / 100
162158 self .rot_y -= dy / 100
163159
164160 def on_mouse_release (self , x , y , button , modifiers ):
165- self .drag = False
161+ self .drag_time = None
166162
167163 def on_mouse_scroll (self , x : int , y : int , scroll_x : int , scroll_y : int ):
168164 self .vert_count = clamp (self .vert_count + scroll_y / 500 , 0.0 , 1.0 )
0 commit comments