camera speed, window settings

This commit is contained in:
Lauri Räsänen 2022-10-02 22:32:32 +03:00
parent 3838b5d7c6
commit b741202111
2 changed files with 22 additions and 1 deletions

View file

@ -1,7 +1,7 @@
use std::time::Duration;
use cgmath::num_traits::clamp;
use winit::event::*;
use winit::{dpi::PhysicalPosition, event::*};
pub struct Camera {
pub position: cgmath::Point3<f32>,
@ -211,6 +211,24 @@ impl CameraController {
_ => false,
}
}
WindowEvent::MouseWheel { delta, .. } => match delta {
MouseScrollDelta::LineDelta(_, scroll) => {
if *scroll > 0.0 {
self.speed *= 2.0;
} else {
self.speed /= 2.0;
}
return true;
}
MouseScrollDelta::PixelDelta(PhysicalPosition { y: scroll, .. }) => {
if *scroll > 0.0 {
self.speed *= 2.0;
} else {
self.speed /= 2.0;
}
return true;
}
},
_ => false,
},
};

View file

@ -10,6 +10,9 @@ use winit::{
pub async fn run() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
window.set_cursor_grab(true).unwrap();
window.set_cursor_visible(false);
window.set_decorations(false);
let mut state = State::new(&window).await;
let mut last_render = Instant::now();