Add FlycamWidget keyboard processing
This commit is contained in:
parent
cffe12c930
commit
c816b6629e
|
@ -1,3 +1,4 @@
|
|||
use crate::winit;
|
||||
use cyborg::camera::Flycam;
|
||||
|
||||
pub struct UserInterface {
|
||||
|
@ -156,9 +157,40 @@ impl egui::Widget for &mut ViewportWidget {
|
|||
ui.painter().add(Shape::mesh(mesh));
|
||||
|
||||
if response.dragged() {
|
||||
println!("dragging");
|
||||
let delta = response.drag_delta();
|
||||
self.flycam.process_mouse(delta.x as f64, delta.y as f64);
|
||||
|
||||
for event in ui.input().events.iter() {
|
||||
match event {
|
||||
egui::Event::Key { key, pressed, .. } => {
|
||||
use winit::event::{ElementState, VirtualKeyCode};
|
||||
|
||||
let key = match key {
|
||||
egui::Key::W => Some(VirtualKeyCode::W),
|
||||
egui::Key::A => Some(VirtualKeyCode::A),
|
||||
egui::Key::S => Some(VirtualKeyCode::S),
|
||||
egui::Key::D => Some(VirtualKeyCode::D),
|
||||
// TODO remap from shift key somehow?
|
||||
egui::Key::E => Some(VirtualKeyCode::E),
|
||||
egui::Key::Q => Some(VirtualKeyCode::Q),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let state = if *pressed {
|
||||
ElementState::Pressed
|
||||
} else {
|
||||
ElementState::Released
|
||||
};
|
||||
|
||||
if let Some(key) = key {
|
||||
self.flycam.process_keyboard(key, state);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
} else if response.drag_released() {
|
||||
self.flycam.defocus();
|
||||
}
|
||||
|
||||
println!("{:#?}", self.flycam);
|
||||
|
|
Loading…
Reference in New Issue