diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-07 15:15:19 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-07 15:15:19 +0100 |
commit | e32de26dcb5e1498f2b2fa19cacb593bec518ef4 (patch) | |
tree | 8a5d3d0e4629d04527e1f8203adbfcbe9d03838a /client/src/window.rs | |
parent | d81eebe423fd3e00df5ff035ec24fe7fb37f2c62 (diff) | |
download | weareserver-e32de26dcb5e1498f2b2fa19cacb593bec518ef4.tar weareserver-e32de26dcb5e1498f2b2fa19cacb593bec518ef4.tar.bz2 weareserver-e32de26dcb5e1498f2b2fa19cacb593bec518ef4.tar.zst |
camera controller broken
Diffstat (limited to 'client/src/window.rs')
-rw-r--r-- | client/src/window.rs | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/client/src/window.rs b/client/src/window.rs index 6ee7fa4..ac90f71 100644 --- a/client/src/window.rs +++ b/client/src/window.rs @@ -1,10 +1,12 @@ use crate::state::State; +use glam::Vec3; use log::{info, warn}; use std::net::TcpStream; use winit::{ application::ApplicationHandler, - event::WindowEvent, + event::{DeviceEvent, ElementState, WindowEvent}, event_loop::ActiveEventLoop, + keyboard::{KeyCode, PhysicalKey}, window::{Window, WindowAttributes, WindowId}, }; @@ -47,6 +49,21 @@ impl ApplicationHandler for WindowState { sta.draw(); win.request_redraw(); } + WindowEvent::KeyboardInput { event, .. } => { + if event.repeat { + return; + } + sta.delta.move_dir += match event.physical_key { + PhysicalKey::Code(KeyCode::KeyW) => Vec3::X, + PhysicalKey::Code(KeyCode::KeyS) => Vec3::NEG_X, + PhysicalKey::Code(KeyCode::KeyA) => Vec3::NEG_Z, + PhysicalKey::Code(KeyCode::KeyD) => Vec3::Z, + _ => Vec3::ZERO, + } * match event.state { + ElementState::Pressed => 1., + ElementState::Released => -1., + }; + } WindowEvent::CloseRequested => { event_loop.exit(); } @@ -54,6 +71,22 @@ impl ApplicationHandler for WindowState { } } } + fn device_event( + &mut self, + _event_loop: &ActiveEventLoop, + _device_id: winit::event::DeviceId, + event: winit::event::DeviceEvent, + ) { + if let Some((_win, sta)) = &mut self.window { + match event { + DeviceEvent::MouseMotion { delta } => { + sta.delta.mouse_acc.x += delta.0 as f32; + sta.delta.mouse_acc.y += delta.1 as f32; + } + _ => (), + } + } + } fn about_to_wait(&mut self, _event_loop: &ActiveEventLoop) { if let Some((_win, sta)) = &mut self.window { if let Err(e) = sta.update() { |