johanhelsing / bevy_pancam

A bevy plugin for panning orthographic cameras
Apache License 2.0
173 stars 26 forks source link

unexpected behavior when initializing with clamped values that conflict with existing projection scale #43

Open MeoMix opened 1 year ago

MeoMix commented 1 year ago

Consider an example similar to the one shown in examples/clamped_borders.rs but modified to account for the concern highlighted in https://github.com/johanhelsing/bevy_pancam/issues/42

So, we have code like this:

    commands.spawn(SpriteBundle {
        transform: Transform::from_xyz(0.0, 0.0, 0.0),
        sprite: Sprite {
            color: Color::BLUE,
            custom_size: Some(Vec2::splat(spacing * n as f32)),
            ..default()
        },
        ..default()
    });

which renders a 1000x1000 square centered at 0,0 center anchor.

Now, consider initializing bevy_pancam with the following:

    commands.spawn((
        Camera2dBundle::default(),
        PanCam {
            min_x: Some(-(spacing * n) as f32 / 2.0),
            max_x: Some((spacing * n) as f32 / 2.0),
            min_y: Some(-(spacing * n) as f32 / 2.0),
            max_y: Some((spacing * n) as f32 / 2.0),
            ..default()
        },
    ));

These settings attempt to ensure that the blue square always covers the entire viewport. If the viewport is square then the two will scale to fit perfectly. Otherwise, the blue square will overflow in one dimension and be bounded by the viewport in the other. If I apply only one of these four properties at a time then I am able to see the square snap to the left/right/top/bottom side.

On load, the application looks like this:

image

if I click the screen it then updates and looks like this:

image

if, instead of clicking, I scroll my mousewheel forward once as if I were zooming in, then the UI looks like this:

image

if, instead of clicking, I scroll my mousewheel forward twice as if I were zooming in repeatedly, then the UI looks like this:

image

This last perspective is correct / desired. It shows projection.scale adjusted such that the blue square fully covers the viewport. I am able to zoom inward and pan around, but I am not able to zoom out past the bounds of the blue square. I am able to pan up/down the page because the scale is such that the height of blue square exceeds that of the viewport.

1. As a user, I do not expect variations in projection.scale or clamping behavior when I click, scroll once, or scroll multiple times. If I take an action, and the current scale and clamped bounds are invalid, then the action's response should be to apply the clamped bounds in such a way that all three actions result in consistent UIs.

2. As a user, I do not expect projection.scale to be invalid on first load when applying clamped boundaries. I want the initial projection.scale to respect the provided clamp boundaries.

I think if these two issues are address that, as a side-effect, the concern I highlight in https://github.com/johanhelsing/bevy_pancam/pull/38 will be addressed.

MeoMix commented 1 year ago

@johanhelsing here is where I explain :)