fix scroll

This commit is contained in:
Stephen Adamson
2025-05-28 11:03:57 +01:00
parent e8d3f1bafb
commit 0def6af6e8
+7 -3
View File
@@ -82,6 +82,7 @@ pub fn spawn_panning_camera(mut commands: Commands) {
pub fn scroll_events(mut evr_scroll: EventReader<MouseWheel>, mut query: Query<&mut Projection>) {
const ZOOM_SENSITIVITY: f32 = 0.035;
const PIXEL_SENSITIVITY: f32 = 0.001;
const MIN_SCALE: f32 = 0.2;
const MAX_SCALE: f32 = 2.0;
@@ -90,17 +91,20 @@ pub fn scroll_events(mut evr_scroll: EventReader<MouseWheel>, mut query: Query<&
let current_scale = match &*projection_component {
Projection::Orthographic(ortho_proj) => ortho_proj.scale,
Projection::Perspective(_) => 1.0,
Projection::Custom(_custom_projection) => todo!(),
Projection::Custom(_custom_projection) => {
continue;
}
};
let new_scale = match ev.unit {
MouseScrollUnit::Line => current_scale + ev.y * ZOOM_SENSITIVITY,
MouseScrollUnit::Pixel => todo!(),
MouseScrollUnit::Pixel => current_scale + ev.y * PIXEL_SENSITIVITY,
};
*projection_component = Projection::Orthographic(OrthographicProjection {
scale: new_scale.max(MIN_SCALE).min(MAX_SCALE),
..OrthographicProjection::default_2d()
});
}
}
}
}