diff --git a/Cargo.toml b/Cargo.toml index b1e61cf..662e1fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,6 @@ anyhow = "1.0" pollster = "0.4" cgmath = "0.18" - [profile.dev] codegen-backend = "cranelift" opt-level = 0 diff --git a/src/controller.rs b/src/controller.rs index cac5115..4027a7f 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -65,15 +65,16 @@ impl CameraController { (x, y) } false => { + let movement_speed = self.movement_speed / 3.0; let x = match position.x { - x if x < 100.0 => -0.0005, - x if x > window_size.0 - 100.0 => 0.0005, + x if x < 100.0 => -movement_speed, + x if x > window_size.0 - 100.0 => movement_speed, _ => 0.0, }; let y = match position.y { - y if y < 100.0 => 0.0005, - y if y > window_size.1 - 100.0 => -0.0005, + y if y < 100.0 => movement_speed, + y if y > window_size.1 - 100.0 => -movement_speed, _ => 0.0, }; diff --git a/src/lib.rs b/src/lib.rs index bdce0b9..65eaf75 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,3 +17,12 @@ pub fn capture() -> anyhow::Result<()> { Ok(event_loop.run_app(&mut app)?) } + +pub fn ease_in_out_cubic(x: f32) -> f32 { + if x < 0.5 { + 4.0 * x * x * x + } + else { + 1.0 - (-2.0 * x + 2.0).powf(3.0) / 2.0 + } +} diff --git a/src/spotlight.rs b/src/spotlight.rs index a05895f..2f7c4e3 100644 --- a/src/spotlight.rs +++ b/src/spotlight.rs @@ -6,15 +6,20 @@ use winit::{ keyboard::{Key, NamedKey}, }; -use crate::controller::CameraController; +use crate::{controller::CameraController, ease_in_out_cubic}; + +const REFRESH_RATE: f32 = 1.0 / 60.0; pub struct Spotlight { window: Arc, cursor_position: (f32, f32), + accel: f32, size: f32, + delta_size: f32, is_ctrl_pressed: bool, + scrolling: f32, } pub struct SpotlightInfo { @@ -30,9 +35,12 @@ impl Spotlight { window, cursor_position: (960.0, 540.0), + accel: 0.0, size: 50.0, + delta_size: 0.0, is_ctrl_pressed: false, + scrolling: 0.0, }; let layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { @@ -108,7 +116,7 @@ impl Spotlight { WindowEvent::MouseWheel { delta, .. } => { if let MouseScrollDelta::LineDelta(_, y) = delta { if self.is_ctrl_pressed { - self.size += y * 5.0; + self.delta_size += *y; } } } @@ -116,7 +124,13 @@ impl Spotlight { } } - pub fn update(&mut self) {} + pub fn update(&mut self) { + if self.is_ctrl_pressed && self.delta_size.abs() > 0.01 { + self.size = (self.size + self.delta_size * REFRESH_RATE).max(0.01); + self.size = self.size.clamp(5.0, 250.0); + self.delta_size -= self.delta_size * REFRESH_RATE * 0.1; + } + } } #[repr(C)]