Compare commits

...

2 Commits

Author SHA1 Message Date
Wynd 5e8716acf0 Some cleanup 2024-11-08 13:08:12 +02:00
Wynd 9127c4ddac Smooth spotlight scaling 2024-11-08 10:13:34 +02:00
5 changed files with 19 additions and 15 deletions

View File

@ -25,15 +25,8 @@ anyhow = "1.0"
pollster = "0.4" pollster = "0.4"
cgmath = "0.18" cgmath = "0.18"
[profile.dev] [profile.dev]
codegen-backend = "cranelift" codegen-backend = "cranelift"
opt-level = 0
lto = false
incremental = true
[profile.release] [profile.release]
opt-level = 3
strip = true strip = true
lto = true
codegen-units = 1

View File

@ -59,9 +59,9 @@ impl<'a> ApplicationHandler for App<'a> {
event_loop.exit(); event_loop.exit();
} }
WindowEvent::RedrawRequested => { WindowEvent::RedrawRequested => {
state.window.request_redraw();
state.update(); state.update();
state.render().unwrap(); state.render().unwrap();
state.window.request_redraw();
} }
WindowEvent::Resized(new_size) => { WindowEvent::Resized(new_size) => {
state.resize(new_size); state.resize(new_size);

View File

@ -65,15 +65,16 @@ impl CameraController {
(x, y) (x, y)
} }
false => { false => {
let movement_speed = self.movement_speed / 3.0;
let x = match position.x { let x = match position.x {
x if x < 100.0 => -0.0005, x if x < 100.0 => -movement_speed,
x if x > window_size.0 - 100.0 => 0.0005, x if x > window_size.0 - 100.0 => movement_speed,
_ => 0.0, _ => 0.0,
}; };
let y = match position.y { let y = match position.y {
y if y < 100.0 => 0.0005, y if y < 100.0 => movement_speed,
y if y > window_size.1 - 100.0 => -0.0005, y if y > window_size.1 - 100.0 => -movement_speed,
_ => 0.0, _ => 0.0,
}; };

View File

@ -11,7 +11,7 @@ pub mod vertex;
pub fn capture() -> anyhow::Result<()> { pub fn capture() -> anyhow::Result<()> {
let event_loop = EventLoop::new()?; let event_loop = EventLoop::new()?;
event_loop.set_control_flow(ControlFlow::Wait); event_loop.set_control_flow(ControlFlow::Poll);
let mut app = App::default(); let mut app = App::default();

View File

@ -8,11 +8,14 @@ use winit::{
use crate::controller::CameraController; use crate::controller::CameraController;
const REFRESH_RATE: f32 = 1.0 / 60.0;
pub struct Spotlight { pub struct Spotlight {
window: Arc<winit::window::Window>, window: Arc<winit::window::Window>,
cursor_position: (f32, f32), cursor_position: (f32, f32),
size: f32, size: f32,
delta_size: f32,
is_ctrl_pressed: bool, is_ctrl_pressed: bool,
} }
@ -31,6 +34,7 @@ impl Spotlight {
cursor_position: (960.0, 540.0), cursor_position: (960.0, 540.0),
size: 50.0, size: 50.0,
delta_size: 0.0,
is_ctrl_pressed: false, is_ctrl_pressed: false,
}; };
@ -108,7 +112,7 @@ impl Spotlight {
WindowEvent::MouseWheel { delta, .. } => { WindowEvent::MouseWheel { delta, .. } => {
if let MouseScrollDelta::LineDelta(_, y) = delta { if let MouseScrollDelta::LineDelta(_, y) = delta {
if self.is_ctrl_pressed { if self.is_ctrl_pressed {
self.size += y * 5.0; self.delta_size += *y;
} }
} }
} }
@ -116,7 +120,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)] #[repr(C)]