Skip to content

Commit

Permalink
Camera: mouse_coordinates_to_world supports scaled window
Browse files Browse the repository at this point in the history
  • Loading branch information
einarf committed Jul 26, 2020
1 parent 96de60b commit 9daab9d
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions arcade/experimental/camera.py
Expand Up @@ -37,14 +37,16 @@ def mouse_coordinates_to_world(self, x, y) -> Tuple[float, float]:
# Account for black borders in viewport
vp = self._adjust_viewport_to_aspect_ratio(self.aspect_ratio, self._viewport)
# Account for projection (including zoom)

vp_width, vp_height = vp[2], vp[3]
proj_width, proj_height = self._projection[1] - self._projection[0], self._projection[3] - self._projection[2]
dx, dy = proj_width / vp_width, proj_height / vp_height

return (
x + self._scroll_x - vp[0],
y + self.scroll_y - vp[1],
(x - vp[0]) * dx + self._scroll_x,
(y - vp[1]) * dy + self._scroll_y,
)

# Mouse coordinates to screen (relative)
#

def _adjust_viewport_to_aspect_ratio(self, aspect_ratio: float, viewport: Tuple[int, int, int, int]):
"""
Expand Down Expand Up @@ -76,15 +78,6 @@ def aspect_ratio(self) -> float:
"""
return (self._projection[1] - self._projection[0]) / (self._projection[3] - self._projection[2])

@property
def viewport_size(self) -> Tuple[int, int]:
"""
Get the x and y dimension of the viewport.
:type: Tuple[int, int]
"""
return self._viewport[2], self._viewport[3]

@property
def window(self):
"""The window this camera belongs to"""
Expand Down

0 comments on commit 9daab9d

Please sign in to comment.