Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Craven committed Jan 10, 2025
1 parent 0d0ee61 commit b37b2c2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
10 changes: 9 additions & 1 deletion arcade/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import logging
import os
import time
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Sequence

import pyglet
import pyglet.gl as gl
Expand Down Expand Up @@ -318,6 +318,14 @@ def __init__(
# rendered to the window when the event loop starts.
self._start_finish_render_data: StartFinishRenderData | None = None

def _create(self) -> None:
"""Internal function to create the window."""
pass

def _recreate(self, changes: Sequence[str]) -> None:
"""Internal function to recreate the window."""
pass

@property
def current_view(self) -> View | None:
"""
Expand Down
8 changes: 4 additions & 4 deletions arcade/camera/camera_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ def top_left(self, new_corner: Point2):
left = self.left

x, y = new_corner
self.position = (x - ux * top - rx * left, y - uy * top - ry * left)
self.position = Vec2(x - ux * top - rx * left, y - uy * top - ry * left)

# top_center
@property
Expand Down Expand Up @@ -982,7 +982,7 @@ def bottom_right(self, new_corner: Point2):
right = self.right

x, y = new_corner
self.position = (
self.position = Vec2(
x - ux * bottom - rx * right,
y - uy * bottom - ry * right,
)
Expand All @@ -1003,7 +1003,7 @@ def bottom_center(self, new_bottom: Point2):
bottom = self.bottom

x, y = new_bottom
self.position = x - ux * bottom, y - uy * bottom
self.position = Vec2(x - ux * bottom, y - uy * bottom)

# bottom_left
@property
Expand Down Expand Up @@ -1044,4 +1044,4 @@ def center_left(self, new_left: Point2):
left = self.left

x, y = new_left
self.position = x - uy * left, y + ux * left
self.position = Vec2(x - uy * left, y + ux * left)
6 changes: 3 additions & 3 deletions arcade/camera/perspective.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ def project(self, world_coordinate: Point) -> Vec2:
Returns:
A 2D screen pixel coordinate.
"""
x, y, *z = world_coordinate
x, y, *zp = world_coordinate
z = (
(
0.5
* self.viewport.height
/ tan(radians(0.5 * self._projection.fov / self._view.zoom))
)
if not z
else z[0]
if not zp
else zp[0]
)

_projection = generate_perspective_matrix(self._projection, self._view.zoom)
Expand Down
16 changes: 8 additions & 8 deletions arcade/camera/projection_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def project_orthographic(
view_matrix: Mat4,
projection_matrix: Mat4,
) -> Vec2:
x, y, *z = world_coordinate
z = 0.0 if not z else z[0]
x, y, *zp = world_coordinate
z = 0.0 if not zp else zp[0]

world_position = Vec4(x, y, z, 1.0)

Expand All @@ -144,8 +144,8 @@ def unproject_orthographic(
view_matrix: Mat4,
projection_matrix: Mat4,
) -> Vec3:
x, y, *z = screen_coordinate
z = 0.0 if not z else z[0]
x, y, *zp = screen_coordinate
z = 0.0 if not zp else zp[0]

screen_x = 2.0 * (x - viewport[0]) / viewport[2] - 1
screen_y = 2.0 * (y - viewport[1]) / viewport[3] - 1
Expand All @@ -165,8 +165,8 @@ def project_perspective(
view_matrix: Mat4,
projection_matrix: Mat4,
) -> Vec2:
x, y, *z = world_coordinate
z = 1.0 if not z else z[0]
x, y, *zp = world_coordinate
z = 1.0 if not zp else zp[0]

world_position = Vec4(x, y, z, 1.0)

Expand All @@ -188,8 +188,8 @@ def unproject_perspective(
view_matrix: Mat4,
projection_matrix: Mat4,
) -> Vec3:
x, y, *z = screen_coordinate
z = 1.0 if not z else z[0]
x, y, *zp = screen_coordinate
z = 1.0 if not zp else zp[0]

screen_x = 2.0 * (x - viewport[0]) / viewport[2] - 1
screen_y = 2.0 * (y - viewport[1]) / viewport[3] - 1
Expand Down
2 changes: 1 addition & 1 deletion arcade/examples/gl/3d_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
def on_mouse_release(self, x, y, button, modifiers):
self.drag_time = None

def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int):
def on_mouse_scroll(self, x: int, y: int, scroll_x: float, scroll_y: float):
self.vert_count = clamp(self.vert_count + scroll_y / 500, 0.0, 1.0)


Expand Down
2 changes: 1 addition & 1 deletion arcade/examples/gl/normal_mapping_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def on_mouse_motion(self, x: int, y: int, dx: int, dy: int):
# (0.0, 0.0) is bottom left, (1.0, 1.0) is top right
self.mouse_x, self.mouse_y = x / self.width, y / self.height

def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int):
def on_mouse_scroll(self, x: int, y: int, scroll_x: float, scroll_y: float):
"""Zoom in/out with the mouse wheel."""
self.mouse_z += scroll_y * 0.05

Expand Down

0 comments on commit b37b2c2

Please sign in to comment.