Skip to content

Camera zoom changes#1431

Merged
einarf merged 8 commits intopythonarcade:developmentfrom
alejcas:camera/update
Feb 1, 2023
Merged

Camera zoom changes#1431
einarf merged 8 commits intopythonarcade:developmentfrom
alejcas:camera/update

Conversation

@alejcas
Copy link
Member

@alejcas alejcas commented Dec 7, 2022

This PR changes a bit how zoom is controlled and applied to cameras.

@einarf sorry to ping but I would like you to review if this is somehow the right approach. In the end what's send to the gl context should be the same, but now the users gets correct and consistent info about the zoom applied.

A) Before, you could set a zoom that would change the projection matrix, but you could also change the ratio between the viewport and the projection effectively changing the zoom level again:

# ...
camera = arcade.Camera(viewport=(0, 0, 800, 600))
# at this point projection and viewport matches

camera.zoom = 0.5
# now camera zoom is 0.5

camera.projection = (0, camera.viewport[2] / 2, 0, camera.viewport[3] / 2)
# now, by changing the projection I have applied a zoom indirectly,

# BUT. camera.zoom still says 0.5 when it's not:
print(camera.zoom)  # returns 0.5

With this PR, a change in zoom will effectively change the projection (adding or removing width and height to the projection).
Getting camera.zoom will show the ratio between projection and viewport (not an scalar value set by the user).
Setting camera.zoom will effectively change the projection like this:

left, right, bottom, top =  camera.projection
camera.projection = left, right * camera.zoom, bottom, top * camera.zoom

Also if the user decides to not change camera.zoom but instead change the ratio between viewport and projection the camera.zoom property will return a good value, effectively showing the zoom applied.

Also, as you may probably notice by now, changing the projection so it's 1/2 of the viewport or setting camera.zoom to 0.5 will produce the same effect and reflect the same values across all camera attributes.

B) I've added a camera.scale property that returns the x, y ratio between projection and viewport. And camera.zoom will return the width scale (if x, y scale is not the same, then zoom will return a result that's not completely correct).
Setting camera.zoom will set camera.scale to the same value.

C) As a result of this change, zoom is now available in SimpleCamera (as SimpleCamera allows to change viewport and projection).

D) This also fixes an error in camera.center. Later the center method was not taking into account the projection to view ratio.

E) I've also added an example so you can see all this changes in action and also show how you can draw into the screen using cameras instead of using atlas render into.

Alejandro Casanovas added 6 commits December 2, 2022 15:43
- minimap with camera instead of atlas render into
- camera zoom usage
- camera viewport change
@alejcas
Copy link
Member Author

alejcas commented Dec 7, 2022

Btw I don't know what's failing in self hosted

Alejandro Casanovas and others added 2 commits December 8, 2022 22:16
Co-authored-by: pushfoo <36696816+pushfoo@users.noreply.github.com>
Remove prints
@einarf
Copy link
Member

einarf commented Feb 1, 2023

Let's just merge this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants