Add Flycam::defocus()

This commit is contained in:
mars 2022-05-15 15:55:00 -06:00
parent 23234c2263
commit cffe12c930
2 changed files with 19 additions and 0 deletions

View File

@ -121,6 +121,18 @@ impl Flycam {
self.aspect = (width as f32) / (height as f32);
}
/// disable all key presses
pub fn defocus(&mut self) {
self.is_world_down_pressed = false;
self.is_world_up_pressed = false;
self.is_cam_down_pressed = false;
self.is_cam_up_pressed = false;
self.is_forward_pressed = false;
self.is_left_pressed = false;
self.is_backward_pressed = false;
self.is_right_pressed = false;
}
/// apply input and update camera movement
pub fn update(&mut self) {
let dt = self.last_update.elapsed();

View File

@ -250,6 +250,10 @@ impl Application {
self.flycam.resize(new_size.width, new_size.height);
}
pub fn on_lost_focus(&mut self) {
self.flycam.defocus();
}
pub fn on_surface_lost(&mut self) {
self.viewport.resize(self.viewport.size);
}
@ -441,6 +445,9 @@ fn main() {
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
application.on_resize(**new_inner_size);
}
WindowEvent::Focused(false) => {
application.on_lost_focus();
}
_ => {}
}
}