Skip to content
Merged
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
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ doctest_optionflags = ["ELLIPSIS", "NORMALIZE_WHITESPACE"]
filterwarnings = [
"error",
"ignore:'count' is passed as positional argument::vispy",
# See https://github.com/pygfx/pygfx/pull/1306
"ignore:Setting the shape on a NumPy array has been deprecated in NumPy 2.5:DeprecationWarning:pygfx.*|vispy.*",
]

# https://coverage.readthedocs.io/
Expand Down
29 changes: 17 additions & 12 deletions src/scenex/model/_nodes/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
from .node import Node

if TYPE_CHECKING:
import numpy.typing as npt

from scenex import View
from scenex.app.events import Event
from scenex.model._transform import Transform

Position2D = tuple[float, float]
Position3D = tuple[float, float, float]
Vector3D = tuple[float, float, float]
Position = Position2D | Position3D
Position2D = tuple[float, float]
Position3D = tuple[float, float, float]
Vector3D = tuple[float, float, float]
Position = Position2D | Position3D
Vec3Like = npt.ArrayLike

AnyController = Annotated[
Union["PanZoom", "Orbit", "None"], Field(discriminator="type")
Expand Down Expand Up @@ -103,7 +106,7 @@ def forward(self) -> Vector3D:
return tuple(vector / np.linalg.norm(vector))

@forward.setter
def forward(self, arg: Vector3D) -> None:
def forward(self, arg: Vec3Like) -> None:
"""Sets the forward direction of the camera."""
# Check for no change - avoid divide-by-zeroes
mag_old = np.linalg.norm(self.forward)
Expand All @@ -129,7 +132,7 @@ def up(self) -> Vector3D:
return tuple(self.transform.map((0, 1, 0)) - self.transform.map((0, 0, 0)))[:3]

@up.setter
def up(self, arg: Vector3D) -> None:
def up(self, arg: Vec3Like) -> None:
"""Sets the up direction of the camera.

Does not affect the forward direction of the camera so long as the new up
Expand All @@ -153,16 +156,18 @@ def up(self, arg: Vector3D) -> None:
.translated(position)
)

def look_at(self, target: Position3D, /, *, up: Vector3D | None = None) -> None:
def look_at(self, target: Vec3Like, /, *, up: Vec3Like | None = None) -> None:
"""Adjusts the camera to look at a target point in the world.

Parameters
----------
target: Position3D
The position in 3D space that the camera should look at.
up: Vector3D, optional
The up direction for the camera. If provided, this vector must be
perpendicular to the forward vector that results from looking at target.
target: array-like
3 element sequence defining the position in 3D space that the camera
should look at.
up: array-like, optional
3 element sequence defining the up direction for the camera. If
provided, this vector must be perpendicular to the forward vector that
results from looking at target.
"""
position = self.transform.map((0, 0, 0))[:3]
self.forward = tuple(target - position)
Expand Down
Loading