Smooth spotlight scaling
parent
1a8097be9b
commit
9127c4ddac
|
@ -25,7 +25,6 @@ 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
|
opt-level = 0
|
||||||
|
|
|
@ -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,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -17,3 +17,12 @@ pub fn capture() -> anyhow::Result<()> {
|
||||||
|
|
||||||
Ok(event_loop.run_app(&mut app)?)
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -6,15 +6,20 @@ use winit::{
|
||||||
keyboard::{Key, NamedKey},
|
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 {
|
pub struct Spotlight {
|
||||||
window: Arc<winit::window::Window>,
|
window: Arc<winit::window::Window>,
|
||||||
|
|
||||||
cursor_position: (f32, f32),
|
cursor_position: (f32, f32),
|
||||||
|
accel: f32,
|
||||||
size: f32,
|
size: f32,
|
||||||
|
delta_size: f32,
|
||||||
|
|
||||||
is_ctrl_pressed: bool,
|
is_ctrl_pressed: bool,
|
||||||
|
scrolling: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SpotlightInfo {
|
pub struct SpotlightInfo {
|
||||||
|
@ -30,9 +35,12 @@ impl Spotlight {
|
||||||
window,
|
window,
|
||||||
|
|
||||||
cursor_position: (960.0, 540.0),
|
cursor_position: (960.0, 540.0),
|
||||||
|
accel: 0.0,
|
||||||
size: 50.0,
|
size: 50.0,
|
||||||
|
delta_size: 0.0,
|
||||||
|
|
||||||
is_ctrl_pressed: false,
|
is_ctrl_pressed: false,
|
||||||
|
scrolling: 0.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
let layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||||
|
@ -108,7 +116,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 +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)]
|
#[repr(C)]
|
||||||
|
|
Loading…
Reference in New Issue