Skip to content

Commit c635f19

Browse files
committed
Push pixel_coords_to_space_coords to Window
1 parent 8645894 commit c635f19

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

manimlib/camera/camera.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,6 @@ def resize_frame_shape(self, fixed_dimension=0):
316316
self.frame.set_height(frame_height)
317317
self.frame.set_width(frame_width)
318318

319-
def pixel_coords_to_space_coords(self, px, py, relative=False):
320-
pw, ph = self.fbo.size
321-
fw, fh = self.get_frame_shape()
322-
fc = self.get_frame_center()
323-
if relative:
324-
return 2 * np.array([px / pw, py / ph, 0])
325-
else:
326-
# Only scale wrt one axis
327-
scale = fh / ph
328-
return fc + scale * np.array([(px - pw / 2), (py - ph / 2), 0])
329-
330319
# Rendering
331320
def capture(self, *mobjects, **kwargs):
332321
self.refresh_perspective_uniforms()

manimlib/window.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import numpy as np
12
import moderngl_window as mglw
23
from moderngl_window.context.pyglet.window import Window as PygletWindow
34
from moderngl_window.timers.clock import Timer
@@ -59,7 +60,17 @@ def find_initial_position(self, size):
5960

6061
# Delegate event handling to scene
6162
def pixel_coords_to_space_coords(self, px, py, relative=False):
62-
return self.scene.camera.pixel_coords_to_space_coords(px, py, relative)
63+
pw, ph = self.size
64+
fw, fh = self.scene.camera.get_frame_shape()
65+
fc = self.scene.camera.get_frame_center()
66+
if relative:
67+
return np.array([px / pw, py / ph, 0])
68+
else:
69+
return np.array([
70+
fc[0] + px * fw / pw - fw / 2,
71+
fc[1] + py * fh / ph - fh / 2,
72+
0
73+
])
6374

6475
def on_mouse_motion(self, x, y, dx, dy):
6576
super().on_mouse_motion(x, y, dx, dy)

0 commit comments

Comments
 (0)