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,
speed: f32,
sensitivity: f32,
last_frame: Instant,
active: bool,
}
impl CameraController {
@ -90,7 +90,7 @@ impl CameraController {
scroll: 0.0,
speed,
sensitivity,
last_frame: Instant::now(),
active: true
}
}
@ -100,38 +100,53 @@ impl CameraController {
} else {
0.0
};
match key {
VirtualKeyCode::W | VirtualKeyCode::Up => {
self.amount_forward = amount;
true
}
VirtualKeyCode::S | VirtualKeyCode::Down => {
self.amount_backward = amount;
true
}
VirtualKeyCode::A | VirtualKeyCode::Left => {
self.amount_left = amount;
true
}
VirtualKeyCode::D | VirtualKeyCode::Right => {
self.amount_right = amount;
true
}
VirtualKeyCode::Space => {
self.amount_up = amount;
true
}
VirtualKeyCode::LShift => {
self.amount_down = amount;
true
let active = match key {
VirtualKeyCode::P => {
if state == ElementState::Pressed {
self.active = !self.active;
}
self.active
},
_ => {self.active}
};
if active {
match key {
VirtualKeyCode::W | VirtualKeyCode::Up => {
self.amount_forward = amount;
true
}
VirtualKeyCode::S | VirtualKeyCode::Down => {
self.amount_backward = amount;
true
}
VirtualKeyCode::A | VirtualKeyCode::Left => {
self.amount_left = amount;
true
}
VirtualKeyCode::D | VirtualKeyCode::Right => {
self.amount_right = amount;
true
}
VirtualKeyCode::Space => {
self.amount_up = amount;
true
}
VirtualKeyCode::LShift => {
self.amount_down = amount;
true
}
_ => false,
}
_ => false,
} else {
false
}
}
pub fn process_mouse(&mut self, mouse_dx: f64, mouse_dy: f64) {
self.rotate_horizontal = -mouse_dx as f32;
self.rotate_vertical = mouse_dy as f32;
if self.active {
self.rotate_horizontal = -mouse_dx as f32;
self.rotate_vertical = mouse_dy as f32;
}
}
pub fn update_camera(&mut self, camera: &mut Camera, dt: f32) {

@ -742,7 +742,7 @@ impl WinitPlatform {
/// * window size / dpi factor changes are applied
/// * keyboard 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>) {
match *event {
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) {
match *event {
OwnedWindowEvent::Resized(physical_size) => {

@ -3,12 +3,9 @@ use std::path::PathBuf;
use gilrs::Event as GilEvent;
use legion::world::SubWorld;
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::{
AxisId, DeviceEvent, DeviceId, ElementState, Event, KeyboardInput, ModifiersState, MouseButton,
MouseScrollDelta, StartCause, Touch, TouchPhase, WindowEvent,
};
use winit_24::event::{AxisId, DeviceEvent, DeviceId, ElementState, Event, KeyboardInput, ModifiersState, MouseButton, MouseScrollDelta, StartCause, Touch, TouchPhase, WindowEvent, VirtualKeyCode};
use winit_24::window::{Theme, WindowId, Window};
use crate::camera::{Camera, CameraController};
@ -266,6 +263,7 @@ pub fn event_dispatch(
for (camera_controller) in query.iter_mut(world) {
camera_controller.process_mouse(delta.0, delta.1);
}
},
OwnedEvent::DeviceEvent {
event: winit_24::event::DeviceEvent::Key(keyboard_input),
@ -279,21 +277,23 @@ pub fn event_dispatch(
);
}
// match keyboard_input.virtual_keycode.unwrap() {
// VirtualKeyCode::A => {
// if keyboard_input.state == ElementState::Pressed {}
// }
// VirtualKeyCode::S => {
// if keyboard_input.state == ElementState::Pressed {}
// }
// VirtualKeyCode::P => {
// 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));
// }
// }
// _ => ()
// }
match keyboard_input.virtual_keycode.unwrap() {
VirtualKeyCode::A => {
if keyboard_input.state == ElementState::Pressed {
println!("cursorijf");
winit_window.set_cursor_position(
LogicalPosition{ x: 100.0, y: 100.0 }
);
//winit_window.set_cursor_grab(true);
}
}
VirtualKeyCode::S => {
if keyboard_input.state == ElementState::Pressed {
//winit_window.set_cursor_grab(false);
}
}
_ => ()
}
}
_ => {}
}

Loading…
Cancel
Save