diff --git a/arcade/camera/README.md b/arcade/camera/README.md deleted file mode 100644 index 72c5a52a62..0000000000 --- a/arcade/camera/README.md +++ /dev/null @@ -1,90 +0,0 @@ -# Arcade Camera - -This is an overview of how the new Arcade Cameras work. - -## Key Concepts - -### World Space -Whenever an object has a position within Arcade that position is in world space. How much 1 unit in world -space represents is arbitrary. For example when a sprite has a scale of 1.0 then 1 unit in world space is -equal to one pixel of the sprite's source texture. This does not necessarily equate to one pixel on the screen. - -### Screen Space -The final positions of anything drawn to screen is in screen space. The mouse positions returned by window -events like `on_mouse_press` are also in screen space. Moving 1 unit in screen space is equivalent to moving -one pixel. Often positions in screen space are integer values, but this is not a strict rule. - -### View Matrices -The view matrix represents what part of world space should be focused on. It is made of three components. -The first is the position. This represents what world space position should be at (0, 0, 0). The second is -the forward vector. This is the direction which is considered forward and backwards in world space. the -final component is the up vector. Which determines what world space positions are upwards or downwards in -world space. - -The goal of the view matrix is to prepare everything in world space for projection into screen space. It -achieves this by applying its three components to every world space position. In the end any object with -a world space position equal to the view matrix position will be at (0, 0, 0). Any object along the forward -vector after moving will be placed along the z-axis, and any object along the up vector will be place along -the y-axis. This transformation moves the objects from screen space into view space. Importantly one unit in -world space is equal to one unit in view space - -### Projection Matrices -The projection matrix takes the positions of objects in view space and projects them into screen space. -depending on the type of projection matrix how this exactly applies changes. Projection matrices alone -do not fully project objects into screen space, instead they transform positions into unit space. This -special coordinate space ranges from -1 to 1 in the x, y, and z axis. Anything within this range will -be transformed into screen space, and everything outside this range is discarded and left undrawn. -you can conceptualise projection matrices as taking a 6 sided 3D volume in view space and -squashing it down into a uniformly sized cube. In every case the closest position projected along the -z-axis is given by the near value, while the furthest is given by the far value. - -#### orthographic -In an orthographic projection the distance from the origin does not impact how much a position gets projected. -This type of projection can be visualised as a rectangular prism with a set width, height, and depth -determined by left, right, bottom, top, near, far values. These values tell you the bounding box of positions -in view space which get projected. - -#### perspective -In an orthographic projection the distance from the origin directly impacts how much a position is projected. -This type of projection can be visualised as a rectangular prism with the sharp end removed. This shape means -that more positions further away from the origin will be squashed down into unit space. This makes objects -that are further away appear smaller. The shape of the prism is determined by an aspect ratio, the field of view, -and the near and far values. The aspect ratio defines the ratio between the height and width of the projection. -The field of view is half of the angle used to determine the height of the projection at a particular depth. - -### Viewports -The final concept to cover is the viewport. This is the pixel area which the unit space will scale to. The ratio -between the size of the viewport and the size of the projection determines the relationship between units in -world space and pixels in screen space. For example if width and height of an orthographic projection is equal -to the width and height of the viewport then one unit in world space will equal one pixel in screen space. This -is the default for arcade. - -The viewport also defines which pixels get drawn to in the final image. Generally this is equal to the entire -screen, but it is possible to draw to only a specific area by defining the right viewport. Note that doing this -will change the ratio of the viewport and projection, so ensure that they match if you would like to keep the same -unit to pixel ratio. Any position outside the viewport which would normally be a valid pixel position will -not be drawn. - -## Key Objects - -- Objects which modify the view and perspective matrices are called "Projectors" - - `arcade.camera.Projector` is a `Protocol` used internally by arcade - - `Projector.use()` sets the internal projection and view matrices used by Arcade and Pyglet - - `Projector.activate()` is the same as use, but works within a context manager using the `with` syntax - - `Projector.unproject(screen_coordinate)` -provides a way to find the world position of any pixel position on screen. - - `Projector.project(world_coordinate)` -provides a way to find the screen position of any position in the world. -- There are multiple data types which provide the information required to make view and projection matrices - - `camera.CameraData` holds the position, forward, and up vectors along with a zoom value used to create the -view matrix - - `camera.OrthographicProjectionData` holds the left, right, bottom, top, near, far values needed to create a -orthographic projection matrix - - `camera.PerspectiveProjectionData` holds the aspect ratio, field of view, near and far needed to create a -perspective projection matrix. -- There are three primary `Projectors` in `arcade.camera` - - `arcade.camera.Camera2D` is locked to the x-y plane and is perfect for most use cases within arcade. - - `arcade.camera.OrthographicProjector` can be freely positioned in 3D space, but the scale of objects does not -depend on the distance to the projector - - `arcade.camera.PerspectiveProjector` can be freely position in 3D space, -and objects look smaller the further from the camera they are diff --git a/arcade/examples/background_blending.py b/arcade/examples/background_blending.py index 5a982c4d98..9c192e000a 100644 --- a/arcade/examples/background_blending.py +++ b/arcade/examples/background_blending.py @@ -24,7 +24,7 @@ class GameView(arcade.View): def __init__(self): super().__init__() - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() # Load the first background from file. Sized to match the screen self.background_1 = background.Background.from_file( diff --git a/arcade/examples/background_groups.py b/arcade/examples/background_groups.py index 42d2d9d876..7bb9827426 100644 --- a/arcade/examples/background_groups.py +++ b/arcade/examples/background_groups.py @@ -29,7 +29,7 @@ def __init__(self): # Set the background color to equal to that of the first background. self.background_color = (5, 44, 70) - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() # create a background group which will hold all the backgrounds. self.backgrounds = background.BackgroundGroup() diff --git a/arcade/examples/background_parallax.py b/arcade/examples/background_parallax.py index 85c0b6b16d..102a22d894 100644 --- a/arcade/examples/background_parallax.py +++ b/arcade/examples/background_parallax.py @@ -40,7 +40,7 @@ def __init__(self): # Set the background color to match the sky in the background images self.background_color = (162, 84, 162, 255) - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() # Create a background group to hold all the landscape's layers self.backgrounds = background.ParallaxGroup() diff --git a/arcade/examples/background_scrolling.py b/arcade/examples/background_scrolling.py index 00423adfe9..43a9b86a99 100644 --- a/arcade/examples/background_scrolling.py +++ b/arcade/examples/background_scrolling.py @@ -24,7 +24,7 @@ class GameView(arcade.View): def __init__(self): super().__init__() - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() # Load the background from file. Sized to match the screen self.background = background.Background.from_file( diff --git a/arcade/examples/background_stationary.py b/arcade/examples/background_stationary.py index 14ec658eab..b08acb4a55 100644 --- a/arcade/examples/background_stationary.py +++ b/arcade/examples/background_stationary.py @@ -23,7 +23,7 @@ class GameView(arcade.View): def __init__(self): super().__init__() - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() # Load the background from file. It defaults to the size of the texture # with the bottom left corner at (0, 0). diff --git a/arcade/examples/camera_platform.py b/arcade/examples/camera_platform.py index 09e0c1d69e..da59fd52b0 100644 --- a/arcade/examples/camera_platform.py +++ b/arcade/examples/camera_platform.py @@ -68,7 +68,7 @@ def __init__(self): self.fps_message = None # Cameras - self.camera: arcade.camera.Camera2D = None + self.camera: arcade.Camera2D = None self.gui_camera = None self.camera_shake = None @@ -131,7 +131,7 @@ def setup(self): self.player_sprite.center_y = 128 self.scene.add_sprite("Player", self.player_sprite) - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() self.camera_shake = arcade.camera.grips.ScreenShake2D(self.camera.view_data, max_amplitude=12.5, diff --git a/arcade/examples/full_screen_example.py b/arcade/examples/full_screen_example.py index 72796196e7..18282de52b 100644 --- a/arcade/examples/full_screen_example.py +++ b/arcade/examples/full_screen_example.py @@ -43,7 +43,7 @@ def __init__(self): self.example_image = arcade.load_texture(":resources:images/tiles/boxCrate_double.png") # The camera used to update the viewport and projection on screen resize. - self.camera = arcade.camera.Camera2D( + self.camera = arcade.Camera2D( position=(0, 0), projection=LRBT(left=0, right=WINDOW_WIDTH, bottom=0, top=WINDOW_HEIGHT), viewport=self.window.rect diff --git a/arcade/examples/gl/custom_sprite.py b/arcade/examples/gl/custom_sprite.py index cc4b9f21a9..2718be7b07 100644 --- a/arcade/examples/gl/custom_sprite.py +++ b/arcade/examples/gl/custom_sprite.py @@ -34,7 +34,7 @@ class GeoSprites(arcade.Window): def __init__(self): super().__init__(800, 600, "Custom Sprites", resizable=True) - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() self.program = self.ctx.program( vertex_shader=""" #version 330 diff --git a/arcade/examples/light_demo.py b/arcade/examples/light_demo.py index 0dca24efc1..82031d338d 100644 --- a/arcade/examples/light_demo.py +++ b/arcade/examples/light_demo.py @@ -47,7 +47,7 @@ def __init__(self): self.physics_engine = None # Camera - self.camera: arcade.camera.Camera2D = None + self.camera: arcade.Camera2D = None # --- Light related --- # List of all the lights @@ -59,7 +59,7 @@ def setup(self): """ Create everything """ # Create camera - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() # Create sprite lists self.background_sprite_list = arcade.SpriteList() diff --git a/arcade/examples/line_of_sight.py b/arcade/examples/line_of_sight.py index 54f0e6dee7..e3fcb380af 100644 --- a/arcade/examples/line_of_sight.py +++ b/arcade/examples/line_of_sight.py @@ -70,7 +70,7 @@ def setup(self): """ Set up the game and initialize the variables. """ # Camera - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() # Sprite lists self.player_list = arcade.SpriteList() diff --git a/arcade/examples/maze_depth_first.py b/arcade/examples/maze_depth_first.py index da2b66ceca..8f423d29ba 100644 --- a/arcade/examples/maze_depth_first.py +++ b/arcade/examples/maze_depth_first.py @@ -196,7 +196,7 @@ def setup(self): self.background_color = arcade.color.AMAZON # Setup Camera - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() def on_draw(self): """ diff --git a/arcade/examples/maze_recursive.py b/arcade/examples/maze_recursive.py index 3cb90eb588..ec6e4b4707 100644 --- a/arcade/examples/maze_recursive.py +++ b/arcade/examples/maze_recursive.py @@ -249,7 +249,7 @@ def setup(self): self.background_color = arcade.color.AMAZON # setup camera - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() def on_draw(self): """ Render the screen. """ diff --git a/arcade/examples/minimap_camera.py b/arcade/examples/minimap_camera.py index 9035490e4a..947a7480ab 100644 --- a/arcade/examples/minimap_camera.py +++ b/arcade/examples/minimap_camera.py @@ -60,7 +60,7 @@ def __init__(self): minimap_projection = arcade.XYWH( 0.0, 0.0, MAP_PROJECTION_WIDTH, MAP_PROJECTION_HEIGHT ) - self.camera_minimap = arcade.camera.Camera2D( + self.camera_minimap = arcade.Camera2D( viewport=minimap_viewport, projection=minimap_projection ) @@ -70,8 +70,8 @@ def __init__(self): self.physics_engine = None # Camera for sprites, and one for our GUI - self.camera_sprites = arcade.camera.Camera2D() - self.camera_gui = arcade.camera.Camera2D() + self.camera_sprites = arcade.Camera2D() + self.camera_gui = arcade.Camera2D() self.selected_camera = self.camera_minimap # texts diff --git a/arcade/examples/minimap_texture.py b/arcade/examples/minimap_texture.py index a817617afb..97d310f58e 100644 --- a/arcade/examples/minimap_texture.py +++ b/arcade/examples/minimap_texture.py @@ -62,8 +62,8 @@ def __init__(self): self.physics_engine = None # Camera for sprites, and one for our GUI - self.camera_sprites = arcade.camera.Camera2D() - self.camera_gui = arcade.camera.Camera2D() + self.camera_sprites = arcade.Camera2D() + self.camera_gui = arcade.Camera2D() def setup(self): """ Set up the game and initialize the variables. """ diff --git a/arcade/examples/perspective.py b/arcade/examples/perspective.py index efeb4ba2ab..315218a5b4 100644 --- a/arcade/examples/perspective.py +++ b/arcade/examples/perspective.py @@ -112,7 +112,7 @@ def __init__(self): # Create a 2D camera for rendering to the fbo # by setting the camera's render target it will automatically # size and position itself correctly - self.offscreen_cam = arcade.camera.Camera2D( + self.offscreen_cam = arcade.Camera2D( render_target=self.fbo ) diff --git a/arcade/examples/platform_tutorial/07_camera.py b/arcade/examples/platform_tutorial/07_camera.py index b33eddff0b..002862eeaf 100644 --- a/arcade/examples/platform_tutorial/07_camera.py +++ b/arcade/examples/platform_tutorial/07_camera.py @@ -96,7 +96,7 @@ def setup(self): ) # Initialize our camera, setting a viewport the size of our window. - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() self.background_color = arcade.csscolor.CORNFLOWER_BLUE diff --git a/arcade/examples/platform_tutorial/08_coins.py b/arcade/examples/platform_tutorial/08_coins.py index 8add596dbd..dfe0fdf260 100644 --- a/arcade/examples/platform_tutorial/08_coins.py +++ b/arcade/examples/platform_tutorial/08_coins.py @@ -108,7 +108,7 @@ def setup(self): ) # Initialize our camera, setting a viewport the size of our window. - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() self.background_color = arcade.csscolor.CORNFLOWER_BLUE diff --git a/arcade/examples/platform_tutorial/09_sound.py b/arcade/examples/platform_tutorial/09_sound.py index 485a48a0b2..3524b4cb94 100644 --- a/arcade/examples/platform_tutorial/09_sound.py +++ b/arcade/examples/platform_tutorial/09_sound.py @@ -112,7 +112,7 @@ def setup(self): ) # Initialize our camera, setting a viewport the size of our window. - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() self.background_color = arcade.csscolor.CORNFLOWER_BLUE diff --git a/arcade/examples/platform_tutorial/10_score.py b/arcade/examples/platform_tutorial/10_score.py index c12e1c9bf5..d183abc1c8 100644 --- a/arcade/examples/platform_tutorial/10_score.py +++ b/arcade/examples/platform_tutorial/10_score.py @@ -121,10 +121,10 @@ def setup(self): ) # Initialize our camera, setting a viewport the size of our window. - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() # Initialize our gui camera, initial settings are the same as our world camera. - self.gui_camera = arcade.camera.Camera2D() + self.gui_camera = arcade.Camera2D() # Reset our score to 0 self.score = 0 diff --git a/arcade/examples/platform_tutorial/11_scene.py b/arcade/examples/platform_tutorial/11_scene.py index 90b88b1e72..ae22ee5023 100644 --- a/arcade/examples/platform_tutorial/11_scene.py +++ b/arcade/examples/platform_tutorial/11_scene.py @@ -110,10 +110,10 @@ def setup(self): ) # Initialize our camera, setting a viewport the size of our window. - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() # Initialize our gui camera, initial settings are the same as our world camera. - self.gui_camera = arcade.camera.Camera2D() + self.gui_camera = arcade.Camera2D() # Reset our score to 0 self.score = 0 diff --git a/arcade/examples/platform_tutorial/12_tiled.py b/arcade/examples/platform_tutorial/12_tiled.py index 6bdb9e34a2..995358957a 100644 --- a/arcade/examples/platform_tutorial/12_tiled.py +++ b/arcade/examples/platform_tutorial/12_tiled.py @@ -97,10 +97,10 @@ def setup(self): ) # Initialize our camera, setting a viewport the size of our window. - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() # Initialize our gui camera, initial settings are the same as our world camera. - self.gui_camera = arcade.camera.Camera2D() + self.gui_camera = arcade.Camera2D() # Reset our score to 0 self.score = 0 diff --git a/arcade/examples/platform_tutorial/13_more_layers.py b/arcade/examples/platform_tutorial/13_more_layers.py index a0f950c9b5..c3fe1298b4 100644 --- a/arcade/examples/platform_tutorial/13_more_layers.py +++ b/arcade/examples/platform_tutorial/13_more_layers.py @@ -105,10 +105,10 @@ def setup(self): ) # Initialize our camera, setting a viewport the size of our window. - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() # Initialize our gui camera, initial settings are the same as our world camera. - self.gui_camera = arcade.camera.Camera2D() + self.gui_camera = arcade.Camera2D() # Reset our score to 0 self.score = 0 diff --git a/arcade/examples/platform_tutorial/14_multiple_levels.py b/arcade/examples/platform_tutorial/14_multiple_levels.py index 9c456dea57..9daeb96426 100644 --- a/arcade/examples/platform_tutorial/14_multiple_levels.py +++ b/arcade/examples/platform_tutorial/14_multiple_levels.py @@ -114,10 +114,10 @@ def setup(self): ) # Initialize our camera, setting a viewport the size of our window. - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() # Initialize our gui camera, initial settings are the same as our world camera. - self.gui_camera = arcade.camera.Camera2D() + self.gui_camera = arcade.Camera2D() # Reset the score if we should if self.reset_score: diff --git a/arcade/examples/platform_tutorial/15_ladders_moving_platforms.py b/arcade/examples/platform_tutorial/15_ladders_moving_platforms.py index e35bd479ef..d0a0a9c106 100644 --- a/arcade/examples/platform_tutorial/15_ladders_moving_platforms.py +++ b/arcade/examples/platform_tutorial/15_ladders_moving_platforms.py @@ -114,10 +114,10 @@ def setup(self): ) # Initialize our camera, setting a viewport the size of our window. - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() # Initialize our gui camera, initial settings are the same as our world camera. - self.gui_camera = arcade.camera.Camera2D() + self.gui_camera = arcade.Camera2D() # Reset the score if we should if self.reset_score: diff --git a/arcade/examples/platform_tutorial/16_better_input.py b/arcade/examples/platform_tutorial/16_better_input.py index 3b0fa58f8e..714f1d1e1a 100644 --- a/arcade/examples/platform_tutorial/16_better_input.py +++ b/arcade/examples/platform_tutorial/16_better_input.py @@ -120,10 +120,10 @@ def setup(self): ) # Initialize our camera, setting a viewport the size of our window. - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() # Initialize our gui camera, initial settings are the same as our world camera. - self.gui_camera = arcade.camera.Camera2D() + self.gui_camera = arcade.Camera2D() # Reset the score if we should if self.reset_score: diff --git a/arcade/examples/platform_tutorial/17_animations.py b/arcade/examples/platform_tutorial/17_animations.py index aa1c16d2b5..b6f36e65ff 100644 --- a/arcade/examples/platform_tutorial/17_animations.py +++ b/arcade/examples/platform_tutorial/17_animations.py @@ -200,10 +200,10 @@ def setup(self): ) # Initialize our camera, setting a viewport the size of our window. - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() # Initialize our gui camera, initial settings are the same as our world camera. - self.gui_camera = arcade.camera.Camera2D() + self.gui_camera = arcade.Camera2D() # Reset the score if we should if self.reset_score: diff --git a/arcade/examples/platform_tutorial/18_enemies.py b/arcade/examples/platform_tutorial/18_enemies.py index 2752c2fe44..148d38d24b 100644 --- a/arcade/examples/platform_tutorial/18_enemies.py +++ b/arcade/examples/platform_tutorial/18_enemies.py @@ -277,10 +277,10 @@ def setup(self): ) # Initialize our camera, setting a viewport the size of our window. - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() # Initialize our gui camera, initial settings are the same as our world camera. - self.gui_camera = arcade.camera.Camera2D() + self.gui_camera = arcade.Camera2D() # Reset the score if we should if self.reset_score: diff --git a/arcade/examples/platform_tutorial/19_shooting.py b/arcade/examples/platform_tutorial/19_shooting.py index 732c20bd61..428d962778 100644 --- a/arcade/examples/platform_tutorial/19_shooting.py +++ b/arcade/examples/platform_tutorial/19_shooting.py @@ -284,10 +284,10 @@ def setup(self): ) # Initialize our camera, setting a viewport the size of our window. - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() # Initialize our gui camera, initial settings are the same as our world camera. - self.gui_camera = arcade.camera.Camera2D() + self.gui_camera = arcade.Camera2D() # Reset the score if we should if self.reset_score: diff --git a/arcade/examples/platform_tutorial/20_views.py b/arcade/examples/platform_tutorial/20_views.py index a2417c4ca2..8f12a760a2 100644 --- a/arcade/examples/platform_tutorial/20_views.py +++ b/arcade/examples/platform_tutorial/20_views.py @@ -305,10 +305,10 @@ def setup(self): ) # Initialize our camera, setting a viewport the size of our window. - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() # Initialize our gui camera, initial settings are the same as our world camera. - self.gui_camera = arcade.camera.Camera2D() + self.gui_camera = arcade.Camera2D() # Reset the score if we should if self.reset_score: diff --git a/arcade/examples/procedural_caves_bsp.py b/arcade/examples/procedural_caves_bsp.py index 52dce63f83..8efb0f578a 100644 --- a/arcade/examples/procedural_caves_bsp.py +++ b/arcade/examples/procedural_caves_bsp.py @@ -287,8 +287,8 @@ def __init__(self): # Create the cameras. One for the GUI, one for the sprites. # We scroll the 'sprite world' but not the GUI. - self.camera_sprites = arcade.camera.Camera2D() - self.camera_gui = arcade.camera.Camera2D() + self.camera_sprites = arcade.Camera2D() + self.camera_gui = arcade.Camera2D() self.background_color = arcade.color.BLACK diff --git a/arcade/examples/procedural_caves_cellular.py b/arcade/examples/procedural_caves_cellular.py index 907f92835a..6ed1bd22ef 100644 --- a/arcade/examples/procedural_caves_cellular.py +++ b/arcade/examples/procedural_caves_cellular.py @@ -163,8 +163,8 @@ def __init__(self): # Create the cameras. One for the GUI, one for the sprites. # We scroll the 'sprite world' but not the GUI. - self.camera_sprites = arcade.camera.Camera2D() - self.camera_gui = arcade.camera.Camera2D() + self.camera_sprites = arcade.Camera2D() + self.camera_gui = arcade.Camera2D() self.window.background_color = arcade.color.BLACK diff --git a/arcade/examples/sprite_move_scrolling.py b/arcade/examples/sprite_move_scrolling.py index ecdf753bb1..8bc3a52542 100644 --- a/arcade/examples/sprite_move_scrolling.py +++ b/arcade/examples/sprite_move_scrolling.py @@ -54,8 +54,8 @@ def __init__(self): # Create the cameras. One for the GUI, one for the sprites. # We scroll the 'sprite world' but not the GUI. - self.camera_sprites = arcade.camera.Camera2D() - self.camera_gui = arcade.camera.Camera2D() + self.camera_sprites = arcade.Camera2D() + self.camera_gui = arcade.Camera2D() def setup(self): """ Set up the game and initialize the variables. """ diff --git a/arcade/examples/sprite_move_scrolling_box.py b/arcade/examples/sprite_move_scrolling_box.py index 880a8f02a3..c0d5dbd53f 100644 --- a/arcade/examples/sprite_move_scrolling_box.py +++ b/arcade/examples/sprite_move_scrolling_box.py @@ -61,8 +61,8 @@ def __init__(self): self.up_pressed = False self.down_pressed = False - self.camera_sprites = arcade.camera.Camera2D() - self.camera_gui = arcade.camera.Camera2D() + self.camera_sprites = arcade.Camera2D() + self.camera_gui = arcade.Camera2D() def setup(self): """ Set up the game and initialize the variables. """ diff --git a/arcade/examples/sprite_move_scrolling_shake.py b/arcade/examples/sprite_move_scrolling_shake.py index e0f3f58cc8..c26d94c8bb 100644 --- a/arcade/examples/sprite_move_scrolling_shake.py +++ b/arcade/examples/sprite_move_scrolling_shake.py @@ -53,7 +53,7 @@ def __init__(self): self.physics_engine = None # Create camera that will follow the player sprite. - self.camera_sprites = arcade.camera.Camera2D() + self.camera_sprites = arcade.Camera2D() self.camera_shake = arcade.camera.grips.ScreenShake2D( self.camera_sprites.view_data, diff --git a/arcade/examples/sprite_moving_platforms.py b/arcade/examples/sprite_moving_platforms.py index 41df824e67..c7ba7be86a 100644 --- a/arcade/examples/sprite_moving_platforms.py +++ b/arcade/examples/sprite_moving_platforms.py @@ -54,8 +54,8 @@ def __init__(self): # Create the cameras. One for the GUI, one for the sprites. # We scroll the 'sprite world' but not the GUI. - self.camera_sprites = arcade.camera.Camera2D() - self.camera_gui = arcade.camera.Camera2D() + self.camera_sprites = arcade.Camera2D() + self.camera_gui = arcade.Camera2D() self.left_down = False self.right_down = False diff --git a/arcade/examples/sprite_tiled_map.py b/arcade/examples/sprite_tiled_map.py index 0ab2b64550..59e8f17bca 100644 --- a/arcade/examples/sprite_tiled_map.py +++ b/arcade/examples/sprite_tiled_map.py @@ -121,8 +121,8 @@ def setup(self): self.player_sprite, walls, gravity_constant=GRAVITY ) - self.camera = arcade.camera.Camera2D() - self.gui_camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() + self.gui_camera = arcade.Camera2D() # Use the tilemap to limit the camera's position # we don't offset the max_y position to give a better experience. diff --git a/arcade/examples/sprite_tiled_map_with_levels.py b/arcade/examples/sprite_tiled_map_with_levels.py index 26645cc756..2cd2b0a84e 100644 --- a/arcade/examples/sprite_tiled_map_with_levels.py +++ b/arcade/examples/sprite_tiled_map_with_levels.py @@ -70,8 +70,8 @@ def setup(self): scale=PLAYER_SCALING, ) - self.game_camera = arcade.camera.Camera2D() - self.gui_camera = arcade.camera.Camera2D() + self.game_camera = arcade.Camera2D() + self.gui_camera = arcade.Camera2D() self.fps_text = arcade.Text('FPS:', 10, 10, arcade.color.BLACK, 14) self.game_over_text = arcade.Text( diff --git a/arcade/examples/template_platformer.py b/arcade/examples/template_platformer.py index da7b62ba84..00a53ee0e6 100644 --- a/arcade/examples/template_platformer.py +++ b/arcade/examples/template_platformer.py @@ -37,14 +37,14 @@ def __init__(self): super().__init__() # A Camera that can be used for scrolling the screen - self.camera_sprites = arcade.camera.Camera2D() + self.camera_sprites = arcade.Camera2D() # A rectangle that is used to constrain the camera's position. # we update it when we load the tilemap self.camera_bounds = self.window.rect # A non-scrolling camera that can be used to draw GUI elements - self.camera_gui = arcade.camera.Camera2D() + self.camera_gui = arcade.Camera2D() # The scene which helps draw multiple spritelists in order. self.scene = self.create_scene() diff --git a/doc/programming_guide/camera.rst b/doc/programming_guide/camera.rst index 4efeb2a5e2..1f8645a5f8 100644 --- a/doc/programming_guide/camera.rst +++ b/doc/programming_guide/camera.rst @@ -40,21 +40,21 @@ depending on the type of projection matrix how this exactly applies changes. Pro do not fully project objects into screen space, instead they transform positions into unit space. This special coordinate space ranges from -1 to 1 in the x, y, and z axis. Anything within this range will be transformed into screen space, and everything outside this range is discarded and left undrawn. -you can conceptualise projection matrices as taking a 6 sided 3D volume in view space and +you can conceptualize projection matrices as taking a 6 sided 3D volume in view space and squashing it down into a uniformly sized cube. In every case the closest position projected along the z-axis is given by the near value, while the furthest is given by the far value. orthographic """""""""""" In an orthographic projection the distance from the origin does not impact how much a position gets projected. -This type of projection can be visualised as a rectangular prism with a set width, height, and depth +This type of projection can be visualized as a rectangular prism with a set width, height, and depth determined by left, right, bottom, top, near, far values. These values tell you the bounding box of positions in view space which get projected. perspective """"""""""" In an orthographic projection the distance from the origin directly impacts how much a position is projected. -This type of projection can be visualised as a rectangular prism with the sharp end removed. This shape means +This type of projection can be visualized as a rectangular prism with the sharp end removed. This shape means that more positions further away from the origin will be squashed down into unit space. This makes objects that are further away appear smaller. The shape of the prism is determined by an aspect ratio, the field of view, and the near and far values. The aspect ratio defines the ratio between the height and width of the projection. @@ -79,20 +79,20 @@ Key Objects - Objects which modify the view and perspective matrices are called "Projectors" - - :py:class:`arcade.camera.Projector` is a :py:class:`Protocol` used internally by arcade - - :py:func:`Projector.use()` sets the internal projection and view matrices used by Arcade and Pyglet - - :py:func:`Projector.activate()` is the same as use, but works within a context manager using the ``with`` syntax - - :py:func:`Projector.unproject(screen_coordinate)` provides a way to find the world position of any pixel position on screen. - - :py:func:`Projector.project(world_coordinate)` provides a way to find the screen position of any position in the world. + - :py:class:`~arcade.camera.Projector` is a :py:class:`Protocol` used internally by arcade + - :py:func:`~arcade.camera.Projector.use` sets the internal projection and view matrices used by Arcade and Pyglet + - :py:func:`~arcade.camera.Projector.activate` is the same as use, but works within a context manager using the ``with`` syntax + - :py:func:`~arcade.camera.Projector.unproject` provides a way to find the world position of any pixel position on screen. + - :py:func:`~arcade.camera.Projector.project` provides a way to find the screen position of any position in the world. - There are multiple data types which provide the information required to make view and projection matrices - - :py:class:`camera.CameraData` holds the position, forward, and up vectors along with a zoom value used to create the view matrix - - :py:class:`camera.OrthographicProjectionData` holds the left, right, bottom, top, near, far values needed to create a orthographic projection matrix - - :py:class:`camera.PerspectiveProjectionData` holds the aspect ratio, field of view, near and far needed to create a perspective projection matrix. + - :py:class:`~arcade.camera.CameraData` holds the position, forward, and up vectors along with a zoom value used to create the view matrix + - :py:class:`~arcade.camera.OrthographicProjectionData` holds the left, right, bottom, top, near, far values needed to create a orthographic projection matrix + - :py:class:`~arcade.camera.PerspectiveProjectionData` holds the aspect ratio, field of view, near and far needed to create a perspective projection matrix. - There are three primary `Projectors` in `arcade.camera` - - :py:class:`arcade.camera.Camera2D` is locked to the x-y plane and is perfect for most use cases within arcade. - - :py:class:`arcade.camera.OrthographicProjector` can be freely positioned in 3D space, and the scale of objects does not depend on the distance from the projector. - - :py:class:`arcade.camera.PerspectiveProjector` can be freely positioned in 3D space, and objects look smaller the further from the camera they are. + - :py:class:`~arcade.Camera2D` is locked to the x-y plane and is perfect for most use cases within arcade. + - :py:class:`~arcade.camera.OrthographicProjector` can be freely positioned in 3D space, and the scale of objects does not depend on the distance from the projector. + - :py:class:`~arcade.camera.PerspectiveProjector` can be freely positioned in 3D space, and objects look smaller the further from the camera they are. diff --git a/doc/tutorials/lights/01_light_demo.py b/doc/tutorials/lights/01_light_demo.py index a7043e2c3c..94bb598752 100644 --- a/doc/tutorials/lights/01_light_demo.py +++ b/doc/tutorials/lights/01_light_demo.py @@ -52,7 +52,7 @@ def setup(self): self.physics_engine = arcade.PhysicsEngineSimple(self.player_sprite, self.wall_list) # setup camera - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() def on_draw(self): """ Draw everything. """ diff --git a/doc/tutorials/lights/light_demo.py b/doc/tutorials/lights/light_demo.py index fb85fbb0c2..6fb8feb01b 100644 --- a/doc/tutorials/lights/light_demo.py +++ b/doc/tutorials/lights/light_demo.py @@ -186,7 +186,7 @@ def setup(self): self.physics_engine = arcade.PhysicsEngineSimple(self.player_sprite, self.wall_list) # setup camera - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() def on_draw(self): """ Draw everything. """ diff --git a/doc/tutorials/platform_tutorial/step_07.rst b/doc/tutorials/platform_tutorial/step_07.rst index 27a29ccf4c..3fca0fdd49 100644 --- a/doc/tutorials/platform_tutorial/step_07.rst +++ b/doc/tutorials/platform_tutorial/step_07.rst @@ -7,7 +7,7 @@ Now that our player can move and jump around, we need to give them a way to expl beyond the original window. If you've ever played a platformer game, you might be familiar with the concept of the screen scrolling to reveal more of the map as the player moves. -To achieve this, we can use a Camera. Since we are making a 2D game, ``arcade.camera.Camera2D`` will +To achieve this, we can use a Camera. Since we are making a 2D game, :py:class:`~arcade.Camera2D` will be easiest. To start with, let's go ahead and add a variable in our ``__init__`` function to hold it: @@ -20,9 +20,9 @@ Next we can go to our setup function, and initialize it like so: .. code-block:: - self.camera = arcade.camera.Camera2D() + self.camera = arcade.Camera2D() -Since we're drawing to the entire screen, we can use ``Camera2D``'s default settings. +Since we're drawing to the entire screen, we can use :py:class:`~arcade.Camera2D`'s default settings. In other circumstances, we can create or adjust the camera so it has a different viewport. In order to use our camera when drawing things to the screen, we only need to add one line to our ``on_draw`` diff --git a/doc/tutorials/raycasting/step_08.py b/doc/tutorials/raycasting/step_08.py index 22df7eccd6..b613a8cb17 100644 --- a/doc/tutorials/raycasting/step_08.py +++ b/doc/tutorials/raycasting/step_08.py @@ -44,8 +44,8 @@ def __init__(self, width, height, title): self.physics_engine = None # Create cameras used for scrolling - self.camera_sprites = arcade.camera.Camera2D() - self.camera_gui = arcade.camera.Camera2D() + self.camera_sprites = arcade.Camera2D() + self.camera_gui = arcade.Camera2D() self.generate_sprites() diff --git a/util/doc_helpers/import_resolver.py b/util/doc_helpers/import_resolver.py index ff45ab3d01..259875a8c7 100644 --- a/util/doc_helpers/import_resolver.py +++ b/util/doc_helpers/import_resolver.py @@ -30,24 +30,29 @@ def get_full_module_path(self) -> str: return f"{name}.{self.name}" return self.name - def resolve(self, full_path: str) -> str: + def resolve(self, full_path: str, level=0) -> str | None: """Return the lowest import of a member in the tree.""" name = full_path.split(".")[-1] # Find an import in this module likely to be the one we want. for imp in self.imports: if imp.name == name and imp.from_module in full_path: + print(f"Found: {imp.name} in {imp.module}") return f"{imp.module}.{imp.name}" # Move on to children for child in self.children: - result = child.resolve(full_path) + print(f"Checking child: {child.name}") + result = child.resolve(full_path, level + 1) if result: return result - # Return the full path if we can't find any relevant imports. - # It means the member is in a sub-module and are not importer anywhere. - return full_path + # We're back from recursing and didn't find anything. + if level == 0: + return full_path + + # Nothing was found in this subtree. + return None def print_tree(self, depth=0): """Print the tree.""" @@ -138,3 +143,5 @@ def _parse_import_node_recursive( print(path) path = root.resolve("arcade.camera.Camera2D") print(path) + path = root.resolve("arcade.camera.data_types.Projector") + print(path)