From c635f19f2a33e916509e53ded46f55e2afa8f5f2 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Tue, 24 Aug 2021 11:26:43 -0700 Subject: [PATCH] Push pixel_coords_to_space_coords to Window --- manimlib/camera/camera.py | 11 ----------- manimlib/window.py | 13 ++++++++++++- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/manimlib/camera/camera.py b/manimlib/camera/camera.py index 7ce70271..c10a6d17 100644 --- a/manimlib/camera/camera.py +++ b/manimlib/camera/camera.py @@ -316,17 +316,6 @@ class Camera(object): self.frame.set_height(frame_height) self.frame.set_width(frame_width) - def pixel_coords_to_space_coords(self, px, py, relative=False): - pw, ph = self.fbo.size - fw, fh = self.get_frame_shape() - fc = self.get_frame_center() - if relative: - return 2 * np.array([px / pw, py / ph, 0]) - else: - # Only scale wrt one axis - scale = fh / ph - return fc + scale * np.array([(px - pw / 2), (py - ph / 2), 0]) - # Rendering def capture(self, *mobjects, **kwargs): self.refresh_perspective_uniforms() diff --git a/manimlib/window.py b/manimlib/window.py index ed3a6fb5..63d0ffd1 100644 --- a/manimlib/window.py +++ b/manimlib/window.py @@ -1,3 +1,4 @@ +import numpy as np import moderngl_window as mglw from moderngl_window.context.pyglet.window import Window as PygletWindow from moderngl_window.timers.clock import Timer @@ -59,7 +60,17 @@ class Window(PygletWindow): # Delegate event handling to scene def pixel_coords_to_space_coords(self, px, py, relative=False): - return self.scene.camera.pixel_coords_to_space_coords(px, py, relative) + pw, ph = self.size + fw, fh = self.scene.camera.get_frame_shape() + fc = self.scene.camera.get_frame_center() + if relative: + return np.array([px / pw, py / ph, 0]) + else: + return np.array([ + fc[0] + px * fw / pw - fw / 2, + fc[1] + py * fh / ph - fh / 2, + 0 + ]) def on_mouse_motion(self, x, y, dx, dy): super().on_mouse_motion(x, y, dx, dy)