camera pausing, weird resizing crashes. Not sure what to tackle next.

master
mitchellhansen 4 years ago
parent 813a5c5e64
commit d12083506b

@ -73,7 +73,7 @@ pub struct CameraController {
scroll: f32, scroll: f32,
speed: f32, speed: f32,
sensitivity: f32, sensitivity: f32,
last_frame: Instant, active: bool,
} }
impl CameraController { impl CameraController {
@ -90,7 +90,7 @@ impl CameraController {
scroll: 0.0, scroll: 0.0,
speed, speed,
sensitivity, sensitivity,
last_frame: Instant::now(), active: true
} }
} }
@ -100,6 +100,16 @@ impl CameraController {
} else { } else {
0.0 0.0
}; };
let active = match key {
VirtualKeyCode::P => {
if state == ElementState::Pressed {
self.active = !self.active;
}
self.active
},
_ => {self.active}
};
if active {
match key { match key {
VirtualKeyCode::W | VirtualKeyCode::Up => { VirtualKeyCode::W | VirtualKeyCode::Up => {
self.amount_forward = amount; self.amount_forward = amount;
@ -127,12 +137,17 @@ impl CameraController {
} }
_ => false, _ => false,
} }
} else {
false
}
} }
pub fn process_mouse(&mut self, mouse_dx: f64, mouse_dy: f64) { pub fn process_mouse(&mut self, mouse_dx: f64, mouse_dy: f64) {
if self.active {
self.rotate_horizontal = -mouse_dx as f32; self.rotate_horizontal = -mouse_dx as f32;
self.rotate_vertical = mouse_dy as f32; self.rotate_vertical = mouse_dy as f32;
} }
}
pub fn update_camera(&mut self, camera: &mut Camera, dt: f32) { pub fn update_camera(&mut self, camera: &mut Camera, dt: f32) {
// Move forward/backward and left/right // Move forward/backward and left/right

@ -742,7 +742,7 @@ impl WinitPlatform {
/// * window size / dpi factor changes are applied /// * window size / dpi factor changes are applied
/// * keyboard state is updated /// * keyboard state is updated
/// * mouse state is updated /// * mouse state is updated
//#[cfg(any(feature = "winit-22", feature = "winit-23", feature = "winit-24"))] #[cfg(any(feature = "winit-22", feature = "winit-23", feature = "winit-24"))]
pub fn handle_event<T>(&mut self, io: &mut Io, window: &Window, event: &OwnedEvent<T>) { pub fn handle_event<T>(&mut self, io: &mut Io, window: &Window, event: &OwnedEvent<T>) {
match *event { match *event {
OwnedEvent::WindowEvent { OwnedEvent::WindowEvent {
@ -979,7 +979,7 @@ impl WinitPlatform {
} }
} }
//#[cfg(any(feature = "winit-23", feature = "winit-24"))] #[cfg(any(feature = "winit-23", feature = "winit-24"))]
fn handle_window_event(&mut self, io: &mut Io, window: &Window, event: &OwnedWindowEvent) { fn handle_window_event(&mut self, io: &mut Io, window: &Window, event: &OwnedWindowEvent) {
match *event { match *event {
OwnedWindowEvent::Resized(physical_size) => { OwnedWindowEvent::Resized(physical_size) => {

@ -3,12 +3,9 @@ use std::path::PathBuf;
use gilrs::Event as GilEvent; use gilrs::Event as GilEvent;
use legion::world::SubWorld; use legion::world::SubWorld;
use legion::*; use legion::*;
use winit_24::dpi::{PhysicalPosition, PhysicalSize}; use winit_24::dpi::{PhysicalPosition, PhysicalSize, LogicalPosition};
use winit_24::event::DeviceEvent::MouseMotion; use winit_24::event::DeviceEvent::MouseMotion;
use winit_24::event::{ use winit_24::event::{AxisId, DeviceEvent, DeviceId, ElementState, Event, KeyboardInput, ModifiersState, MouseButton, MouseScrollDelta, StartCause, Touch, TouchPhase, WindowEvent, VirtualKeyCode};
AxisId, DeviceEvent, DeviceId, ElementState, Event, KeyboardInput, ModifiersState, MouseButton,
MouseScrollDelta, StartCause, Touch, TouchPhase, WindowEvent,
};
use winit_24::window::{Theme, WindowId, Window}; use winit_24::window::{Theme, WindowId, Window};
use crate::camera::{Camera, CameraController}; use crate::camera::{Camera, CameraController};
@ -266,6 +263,7 @@ pub fn event_dispatch(
for (camera_controller) in query.iter_mut(world) { for (camera_controller) in query.iter_mut(world) {
camera_controller.process_mouse(delta.0, delta.1); camera_controller.process_mouse(delta.0, delta.1);
} }
}, },
OwnedEvent::DeviceEvent { OwnedEvent::DeviceEvent {
event: winit_24::event::DeviceEvent::Key(keyboard_input), event: winit_24::event::DeviceEvent::Key(keyboard_input),
@ -279,21 +277,23 @@ pub fn event_dispatch(
); );
} }
// match keyboard_input.virtual_keycode.unwrap() { match keyboard_input.virtual_keycode.unwrap() {
// VirtualKeyCode::A => { VirtualKeyCode::A => {
// if keyboard_input.state == ElementState::Pressed {} if keyboard_input.state == ElementState::Pressed {
// } println!("cursorijf");
// VirtualKeyCode::S => { winit_window.set_cursor_position(
// if keyboard_input.state == ElementState::Pressed {} LogicalPosition{ x: 100.0, y: 100.0 }
// } );
// VirtualKeyCode::P => { //winit_window.set_cursor_grab(true);
// if keyboard_input.state == ElementState::Pressed { }
// let data = world.write_resource::<VkProcessor>().read_compute_buffer(compute_buffer.clone()); }
// image::save_buffer(&Path::new("image.png"), data.as_slice(), (image_data.1).0, (image_data.1).1, image::RGBA(8)); VirtualKeyCode::S => {
// } if keyboard_input.state == ElementState::Pressed {
// } //winit_window.set_cursor_grab(false);
// _ => () }
// } }
_ => ()
}
} }
_ => {} _ => {}
} }

Loading…
Cancel
Save