Skip to content

Commit 6e777fc

Browse files
DragonMoffoneinarfCleptomaniapushfoo
authored
Camera overhaul simple (#1965)
* Setup primary files for experimental refactor of the Camera, Backgrounds, and Scenes. See the #Possible Scene Improvements #Cameras topics in the arcade-dev forum on the Python Arcade discord server. * Completed the Camera2DOrthographic class with doc strings and comments, and started the Camera2DController, and SimpleCamera classes. See the #Possible Scene Improvements #Cameras topics in the arcade-dev forum on the Python Arcade discord server for more info. * Slight change to Cameras to allow for a perspective projection matrix. Created basic Perspective and Orthographic Cameras. See the #Possible Scene Improvements #Cameras topics in the arcade-dev forum on the Python Arcade discord server for more info. * Completed Orthographic Camera. Had some issues with the view matrix, This has been fixed and applied to both of the base cameras. Added a new get map coordinates function (open to change). Placed framework for backwards compatible simple camera. See the #Possible Scene Improvements #Cameras topics in the arcade-dev forum on the Python Arcade discord server for more info. * Update camera_refactor.py Finished Simple Camera. Is backwards compatible with current Simple Camera implementation. * PR cleanup Cleaning up PR to only include camera refactor * New Camera Code Integration Moved experimental code into new "cinematic" folder within arcade. Also made the default camera in arcade the "DefaultCamera" class. and made it's type be "Projector" * Code inspection Clean up * Inspection Fix 2 * Code inspection fix 3 * Round 4 * Writitng initial Unit Tests Created files for unit tests, and wrote a few. Started work on Camera2D (replacement for simple camera) * Finished base of Camera2D class. The basics for Camera2D have been provided with full doc strings. Other helper methods may be added in the future. * code-inspection clean-up on Camera2D Fixed `mypy`, `pyright`, `ruff` errors. Also added __all__ property to every file for a better importing experience. NOTE arcade/camera.py is still there, and it does not match the current system so the code-inspection still complains. Will resolve later. * Removed all reference to old camera system. This included deleting `arcade/camera.py`, and fixing the ui and sections to use either the Default Ortho Projector. NOTE I removed a quick index to the `camera.rst`. That will need to be fixed. Hey look I linted before pushing for once! * whoops circular imports * circular imports 2 * type checking * Started work on some controllers Made a few function controllers which are mega simple. Also changed name from arcade.cinematic to arcade.camera. Also moved the controllers to arcade.camera.controllers. * fixing silly pycharm muck-up when I changed the file name it didn't update any imports tsk tsk. * removing doc ref Have not setup camera documentation so removing old ref. DO NOT PULL PR UNTIL FIXED. * Updated Orthographic Unit Tests grrrrr pycharm * Fixed all the examples NOTE this is a quick fix. It removed shaking from two examples. CANNOT BE PULLED IN WHILE THIS IS UNRESOLVED. Weirdly the linters didn't pick up on these errors * linting fix 1-million * 1-million and 1 * 1-million and 2 * MOAR example fixing * Setup 4 Splines for SplineController setup lerp, quadratic, cubic, b-spline Contemplating how to do spline controller * Removed splines from this PR Removed Splines Made Isometric Controller Fixed small issue with facing direction doing temp rendering test so don't mind `log.png` * General work * Cleaned up Offscreen renderer Added 'nother default glsl shader. Also cleaned up some linting. * Squashed commit of the following: commit 7d56d39 Author: DragonMoffon <happydog.aja@gmail.com> Date: Fri Aug 18 05:16:55 2023 +1200 Created a camera shake class Created a camera shake class. It isn't exactly like the shake provided before so people might what to have a review. * added screen shake doc * lovely useless doc strings NOTE: The doc strings aren't useless. The code just is. Going to completely change the class. * improving screen shake * touch-ups * Finalised Core camera functionality - Removed all reference to arcade.ser_viewport method - fixed incorrect forward direction for SimpleCamera - Includes projectors, SimpleCamera, and Camera2D - Includes minimal functions for moving cameras. * Removed references to projection_2d * Fixing unit tests * Solved pytest issues in GUI due to Camera Code * Fixed small linting issue * Fixed double brackets caused by find and replace * Whoops didn't run integration tests * Created Camera Shake Controller. Created a camera shake controller to replace the one removed. * Completed Doc Strings * Replacing all references of SimpleCamera with Camera2D * Fixing integration test errors, and examples. Did not get to all examples * attempting to fix gui part 1 * Fixed erroneous ui behaviour with new camera. * fixed linting issues * Fixing Issues from pvcraven´s review resolved pvcraven´s review. Also created a perspective camera demo. setup unit tests. * Fixed issues pointed out by MiCurry thanks MiCurry for the editing on that! Also did linting. Currently fails on the camera_perspective_demo.py because of how I threw it together. Will fix in next commit * Improved Camera Shake and Unit Tests Changed the screen shake to store the shake dir but not vector so it should work with rotating the camera now. Added a `readjust_camera` method to the SceenShakeController. Also finished it´s unit tests. * Improved Orthographic and Perspective Unit Tests * Added cull_mode to spritelists Currently only picks between 'orthographic' and 'disabled' * Started working on simple camera controller unit tests * continue perspective work * Removed unfinished perspective camera To allow the new camera code to be integrated into 3.0 the perspective camera was removed. Unit tests for controller methods have not been finished. * Missing tuple import * hwidth -> width * Revert cull_mode in SpriteList * Add & improve type annotations * Add missing annotations in simple_controller_classes.py * Add missing return annotation to OrthographicProjector.use() * Add missing return annotation to SimpleCamerea.use() * Add Camera Protocol type to arcade.camera.types * Correct overly-wide lines in ViewportProjector.__init__ * Add missing return annotation to ViewportProjector.viewport property * Fix return annotation + overwide lines in ViewportProjector.viewport setter * Add return type annotation to ViewportProjector.use() * Add return annotation to DefaultProjector.use() * Add return annotation to Camera2D.projection_width setter * Add return annotation to Camera2D.angle setter * Add Camera protocol to __all__ in arcade.camera.types * Use recursive definition in Projector Protocol * Remove pos from Camera2D * Add method to duplicate CameraData * Fix typing for linting as always >:) * Working test_strafe * Docstring fixes * Initializer docs should be in the class docstring * Convert all google style docstrings to standard format * Improve camera docs, typing, and style (#2) * Cleanup the docstrings for properties in Camera2D * Simplify projection initialization in Camera2D * Remove redundant bool() calls in Camera2D.__init__ * Further simplify Camera2D.__init__ * Docstring cleanup for arcade.camera.data * Camera2D top-level docstring improvements * Moving protocols and making the PoDs into slots classes * Fixing linting (Thanks Push) * Extract non PoD arguments from the Camera2D init and add a RenderTarget property to Camera2D The render target change was discussed with @einarf. May extend to other camera types later. * Added an easy screenshot method to window commands CURRENTLY DOES NOT WORK NEED TO DEBUG WITH @einarf * created a depth of field example * Revert "created a depth of field example" This reverts commit 1536ecd. * Revert "Added an easy screenshot method to window commands" This reverts commit a54a570. * Updating arcade.math changed lerp_vec to lerp_2d created lerp_3d, and quaternion_rotation methods. Also updated any methods which used lerp_vec * gave arcade.camera.Camera2D default init arguments * Added function to constrain arcade.camera.CameraData * moved arcade.camera.controllers to arcade.camera.grips * updated examples to use new functions for camera control * remove example from arcade.math.quaternion_rotation * improving typing for ui_manager * Revert "improving typing for ui_manager" This reverts commit 3b118c8. * Revert "Merge branch 'development' into Camera-Overhaul-Simple" This reverts commit 94b3128, reversing changes made to bb2c1d8. * update map_coordiantes to map_screen_to_world_coordinates * Adding a temporary README to cameras for documentation * Completed clean-up and sanity check * Revert "Revert "Merge branch 'development' into Camera-Overhaul-Simple"" This reverts commit 788072e. * Fix typing issues in ui manager * Fixed WindowProxy to use modern camera sensibilities * Give the data PoDs __str__ and __repr__ methods * Linting fix for __repr__ methods * Updated unit tests to parameterize window size * Improving the state reset between unit tests --------- Co-authored-by: Einar Forselv <eforselv@gmail.com> Co-authored-by: Darren Eberly <darren@eber.ly> Co-authored-by: pushfoo <36696816+pushfoo@users.noreply.github.com>
1 parent 99e5b36 commit 6e777fc

File tree

75 files changed

+3103
-1325
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+3103
-1325
lines changed

arcade/__init__.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@ def configure_logging(level: Optional[int] = None):
7979
from .window_commands import schedule
8080
from .window_commands import run
8181
from .window_commands import set_background_color
82-
from .window_commands import set_viewport
8382
from .window_commands import set_window
8483
from .window_commands import start_render
8584
from .window_commands import unschedule
8685
from .window_commands import schedule_once
8786

88-
from .camera import SimpleCamera, Camera
8987
from .sections import Section, SectionManager
9088

9189
from .application import MOUSE_BUTTON_LEFT
@@ -221,6 +219,7 @@ def configure_logging(level: Optional[int] = None):
221219
# Module imports
222220
from arcade import color as color
223221
from arcade import csscolor as csscolor
222+
from arcade import camera as camera
224223
from arcade import key as key
225224
from arcade import resources as resources
226225
from arcade import types as types
@@ -243,8 +242,6 @@ def configure_logging(level: Optional[int] = None):
243242
'TextureAnimation',
244243
'TextureKeyframe',
245244
'ArcadeContext',
246-
'Camera',
247-
'SimpleCamera',
248245
'ControllerManager',
249246
'FACE_DOWN',
250247
'FACE_LEFT',
@@ -358,7 +355,6 @@ def configure_logging(level: Optional[int] = None):
358355
'run',
359356
'schedule',
360357
'set_background_color',
361-
'set_viewport',
362358
'set_window',
363359
'start_render',
364360
'stop_sound',

arcade/application.py

+18-33
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717

1818
import arcade
1919
from arcade import get_display_size
20-
from arcade import set_viewport
2120
from arcade import set_window
2221
from arcade.color import TRANSPARENT_BLACK
2322
from arcade.context import ArcadeContext
2423
from arcade.types import Color, RGBOrA255, RGBANormalized
2524
from arcade import SectionManager
2625
from arcade.utils import is_raspberry_pi
26+
from arcade.camera import Projector
27+
from arcade.camera.default import DefaultProjector
2728

2829
LOG = logging.getLogger(__name__)
2930

@@ -211,17 +212,17 @@ def __init__(
211212
# self.invalid = False
212213
set_window(self)
213214

215+
self._ctx: ArcadeContext = ArcadeContext(self, gc_mode=gc_mode, gl_api=gl_api)
216+
self._background_color: Color = TRANSPARENT_BLACK
217+
214218
self._current_view: Optional[View] = None
215-
self.current_camera: Optional[arcade.SimpleCamera] = None
219+
self._default_camera = DefaultProjector(window=self)
220+
self.current_camera: Projector = self._default_camera
216221
self.textbox_time = 0.0
217222
self.key: Optional[int] = None
218223
self.flip_count: int = 0
219224
self.static_display: bool = False
220225

221-
self._ctx: ArcadeContext = ArcadeContext(self, gc_mode=gc_mode, gl_api=gl_api)
222-
set_viewport(0, self.width, 0, self.height)
223-
self._background_color: Color = TRANSPARENT_BLACK
224-
225226
# See if we should center the window
226227
if center_window:
227228
self.center_window()
@@ -606,13 +607,8 @@ def on_resize(self, width: int, height: int):
606607
# The arcade context is not created at that time
607608
if hasattr(self, "_ctx"):
608609
# Retain projection scrolling if applied
609-
original_viewport = self._ctx.projection_2d
610-
self.set_viewport(
611-
original_viewport[0],
612-
original_viewport[0] + width,
613-
original_viewport[2],
614-
original_viewport[2] + height
615-
)
610+
self._ctx.viewport = (0, 0, width, height)
611+
self.default_camera.use()
616612

617613
def set_min_size(self, width: int, height: int):
618614
""" Wrap the Pyglet window call to set minimum size
@@ -676,30 +672,19 @@ def set_visible(self, visible: bool = True):
676672
"""
677673
super().set_visible(visible)
678674

679-
# noinspection PyMethodMayBeStatic
680-
def set_viewport(self, left: float, right: float, bottom: float, top: float):
681-
"""
682-
Set the viewport. (What coordinates we can see.
683-
Used to scale and/or scroll the screen).
684-
685-
See :py:func:`arcade.set_viewport` for more detailed information.
686-
687-
:param left:
688-
:param right:
689-
:param bottom:
690-
:param top:
691-
"""
692-
set_viewport(left, right, bottom, top)
693-
694-
# noinspection PyMethodMayBeStatic
695-
def get_viewport(self) -> Tuple[float, float, float, float]:
696-
""" Get the viewport. (What coordinates we can see.) """
697-
return self.ctx.projection_2d
698-
699675
def use(self):
700676
"""Bind the window's framebuffer for rendering commands"""
701677
self.ctx.screen.use()
702678

679+
@property
680+
def default_camera(self):
681+
"""
682+
Provides a reference to the default arcade camera.
683+
Automatically sets projection and view to the size
684+
of the screen. Good for resetting the screen.
685+
"""
686+
return self._default_camera
687+
703688
def test(self, frames: int = 10):
704689
"""
705690
Used by unit test cases. Runs the event loop a few times and stops.

0 commit comments

Comments
 (0)