Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions arcade/camera/camera_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ZeroProjectionDimension
)
from arcade.gl import Framebuffer
from arcade.types import AsFloat

from arcade.window_commands import get_window

Expand Down Expand Up @@ -313,11 +314,10 @@ def projection(self) -> Tuple[float, float, float, float]:
exception if any axis pairs are equal. You can handle this
exception as a :py:class:`ValueError`.
"""
_p = self._projection_data
return _p.left, _p.right, _p.bottom, _p.top
return self._projection_data.lrbt

@projection.setter
def projection(self, value: Tuple[float, float, float, float]) -> None:
def projection(self, value: Tuple[AsFloat, AsFloat, AsFloat, AsFloat]) -> None:

# Unpack and validate
left, right, bottom, top = value
Expand All @@ -331,11 +331,12 @@ def projection(self, value: Tuple[float, float, float, float]) -> None:
f"and {top=}"))

# Modify the projection data itself.
_p = self._projection_data
_p.left = left
_p.right = right
_p.bottom = bottom
_p.top = top
self._projection_data.lrbt = (
float(left),
float(right),
float(bottom),
float(top)
)

@property
def projection_width(self) -> float:
Expand Down Expand Up @@ -368,16 +369,20 @@ def projection_width_scaled(self) -> float:
If this isn't what you want,
use projection_width instead.
"""
return (self._projection_data.right - self._projection_data.left) / self._camera_data.zoom
_p = self._projection_data
left, right, _, _ = _p.lrbt
return (right - left) / self._camera_data.zoom

@projection_width_scaled.setter
def projection_width_scaled(self, _width: float) -> None:
w = self.projection_width * self._camera_data.zoom
l = self.projection_left / w # Normalised Projection left
r = self.projection_right / w # Normalised Projection Right
_p = self._projection_data
left, right, bottom, top = _p.lrbt

self.projection_left = l * _width
self.projection_right = r * _width
width_scaled = (right - left) * self._camera_data.zoom
left_scaled = self.projection_left / width_scaled
right_scaled = self.projection_right / width_scaled

_p.lrbt = left_scaled, right_scaled, bottom, top

@property
def projection_height(self) -> float:
Expand Down
21 changes: 20 additions & 1 deletion arcade/camera/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
'ZeroProjectionDimension',
]

from arcade.types import AsFloat


class ZeroProjectionDimension(ValueError):
"""A projection's dimensions were zero along at least one axis.
Expand Down Expand Up @@ -136,9 +138,26 @@ def __init__(
# Viewport for setting which pixels to draw to
self.viewport: Tuple[int, int, int, int] = viewport

@property
def lrbt(self) -> Tuple[float, float, float, float]:
"""Get/set a tuple for ``(left, right, bottom, top)``.

This will be wired into rectangle abstractions in future
commits.
"""
return self.left, self.right, self.bottom, self.top

@lrbt.setter
def lrbt(self, new_lrbt: Tuple[AsFloat, AsFloat, AsFloat, AsFloat]) -> None:
left, right, bottom, top = new_lrbt
self.left = float(left)
self.right = float(right)
self.top = float(top)
self.bottom = float(bottom)

def __str__(self):
return (f"OrthographicProjection<"
f"LRBT={(self.left, self.right, self.bottom, self.top)}, "
f"LRBT={self.lrbt}, "
f"{self.near=}, "
f"{self.far=}, "
f"{self.viewport=}>")
Expand Down