mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
A few improvements to mouse interactions
This commit is contained in:
parent
c65a7fb340
commit
20f5ba409f
1 changed files with 13 additions and 15 deletions
|
@ -57,8 +57,6 @@ class Scene(object):
|
||||||
# Items associated with interaction
|
# Items associated with interaction
|
||||||
self.mouse_point = Point()
|
self.mouse_point = Point()
|
||||||
self.mouse_drag_point = Point()
|
self.mouse_drag_point = Point()
|
||||||
self.zoom_on_scroll = False
|
|
||||||
self.quit_interaction = False
|
|
||||||
|
|
||||||
# Much nicer to work with deterministic scenes
|
# Much nicer to work with deterministic scenes
|
||||||
if self.random_seed is not None:
|
if self.random_seed is not None:
|
||||||
|
@ -101,7 +99,7 @@ class Scene(object):
|
||||||
# the hood calling the pyglet event loop
|
# the hood calling the pyglet event loop
|
||||||
self.quit_interaction = False
|
self.quit_interaction = False
|
||||||
self.lock_static_mobject_data()
|
self.lock_static_mobject_data()
|
||||||
while not self.window.is_closing and not self.quit_interaction:
|
while not (self.window.is_closing or self.quit_interaction):
|
||||||
self.update_frame()
|
self.update_frame()
|
||||||
if self.window.is_closing:
|
if self.window.is_closing:
|
||||||
self.window.destroy()
|
self.window.destroy()
|
||||||
|
@ -517,9 +515,15 @@ class Scene(object):
|
||||||
|
|
||||||
def on_mouse_drag(self, point, d_point, buttons, modifiers):
|
def on_mouse_drag(self, point, d_point, buttons, modifiers):
|
||||||
self.mouse_drag_point.move_to(point)
|
self.mouse_drag_point.move_to(point)
|
||||||
# Only if 3d rotation is enabled?
|
frame = self.camera.frame
|
||||||
self.camera.frame.increment_theta(-d_point[0])
|
if self.window.is_key_pressed(ord("d")):
|
||||||
self.camera.frame.increment_phi(d_point[1])
|
frame.increment_theta(-d_point[0])
|
||||||
|
frame.increment_phi(d_point[1])
|
||||||
|
elif self.window.is_key_pressed(ord("s")):
|
||||||
|
transform = frame.get_inverse_camera_position_matrix()
|
||||||
|
shift = np.dot(transform[:3, :3].T, d_point)
|
||||||
|
shift *= frame.get_height()
|
||||||
|
frame.shift(-shift)
|
||||||
|
|
||||||
def on_mouse_press(self, point, button, mods):
|
def on_mouse_press(self, point, button, mods):
|
||||||
pass
|
pass
|
||||||
|
@ -528,22 +532,16 @@ class Scene(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def on_mouse_scroll(self, point, offset):
|
def on_mouse_scroll(self, point, offset):
|
||||||
frame = self.camera.frame
|
if self.window.is_key_pressed(ord("z")):
|
||||||
if self.zoom_on_scroll:
|
|
||||||
factor = 1 + np.arctan(10 * offset[1])
|
factor = 1 + np.arctan(10 * offset[1])
|
||||||
frame.scale(factor, about_point=point)
|
self.camera.frame.scale(factor, about_point=point)
|
||||||
else:
|
|
||||||
frame.shift(-30 * offset)
|
|
||||||
|
|
||||||
def on_key_release(self, symbol, modifiers):
|
def on_key_release(self, symbol, modifiers):
|
||||||
if chr(symbol) == "z":
|
pass
|
||||||
self.zoom_on_scroll = False
|
|
||||||
|
|
||||||
def on_key_press(self, symbol, modifiers):
|
def on_key_press(self, symbol, modifiers):
|
||||||
if chr(symbol) == "r":
|
if chr(symbol) == "r":
|
||||||
self.camera.frame.to_default_state()
|
self.camera.frame.to_default_state()
|
||||||
elif chr(symbol) == "z":
|
|
||||||
self.zoom_on_scroll = True
|
|
||||||
elif chr(symbol) == "q":
|
elif chr(symbol) == "q":
|
||||||
self.quit_interaction = True
|
self.quit_interaction = True
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue