diff --git a/src/camera.rs b/src/camera.rs index d2a9eea..f46973d 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -1,5 +1,5 @@ use bevy::prelude::*; -use bevy::input::mouse::MouseMotion; +use bevy::input::mouse::{MouseMotion, MouseWheel}; use bevy::window::PrimaryWindow; use bevy::core_pipeline::bloom::{BloomCompositeMode, BloomSettings}; use bevy::core_pipeline::tonemapping::Tonemapping; @@ -119,6 +119,7 @@ pub fn update_map_camera( q_playercam: Query<&Transform, (With, Without)>, q_target: Query<&Transform, (With, Without, Without)>, mut mouse_events: EventReader, + mut er_mousewheel: EventReader, keyboard_input: Res>, ) { if !settings.map_active || q_camera.is_empty() || q_playercam.is_empty() { @@ -151,12 +152,17 @@ pub fn update_map_camera( mapcam.zoom_level *= target.scale.x * factor; mapcam.initialized = true; } + let mut change_zoom = 0.0; if keyboard_input.pressed(settings.key_map_zoom_out) { - mapcam.target_zoom_level = (mapcam.target_zoom_level * 1.1).min(17e18); + change_zoom += 1.0; } if keyboard_input.pressed(settings.key_map_zoom_in) { - mapcam.target_zoom_level = (mapcam.target_zoom_level / 1.1).max(target.scale.x); + change_zoom -= 1.0; } + for wheel_event in er_mousewheel.read() { + change_zoom -= wheel_event.y * 3.0; + } + mapcam.target_zoom_level = (mapcam.target_zoom_level * 1.1f32.powf(change_zoom)).clamp(target.scale.x, 17e18); let zoom_speed = 0.05; // should be between 0.0001 (slow) and 1.0 (instant) mapcam.zoom_level = zoom_speed * mapcam.target_zoom_level + (1.0 - zoom_speed) * mapcam.zoom_level;