Add WASD keys to FPSDebugCamera system, rename to FPSDebugCameraSystem
This commit is contained in:
parent
46c8c32819
commit
7732280229
1 changed files with 23 additions and 6 deletions
|
|
@ -2,12 +2,12 @@ use crate::system::{System, SystemContext};
|
|||
use glam::{Quat, Vec3};
|
||||
use winit::event::DeviceEvent::MouseMotion;
|
||||
use winit::event::{ElementState, Event, MouseButton, WindowEvent};
|
||||
use winit::keyboard::PhysicalKey;
|
||||
use winit::keyboard::{KeyCode, PhysicalKey};
|
||||
use winit::window::CursorGrabMode;
|
||||
use raidillon_assets::model_path;
|
||||
use raidillon_platform::Camera;
|
||||
|
||||
pub struct FPSCameraSystem {
|
||||
pub struct FPSDebugCameraSystem {
|
||||
mouse_delta: (f64, f64),
|
||||
mouse_enabled: bool,
|
||||
position: Vec3,
|
||||
|
|
@ -17,7 +17,7 @@ pub struct FPSCameraSystem {
|
|||
sensitivity: f32,
|
||||
}
|
||||
|
||||
impl Default for FPSCameraSystem {
|
||||
impl Default for FPSDebugCameraSystem {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
mouse_delta: Default::default(),
|
||||
|
|
@ -31,7 +31,7 @@ impl Default for FPSCameraSystem {
|
|||
}
|
||||
}
|
||||
|
||||
impl System for FPSCameraSystem {
|
||||
impl System for FPSDebugCameraSystem {
|
||||
fn load_world(&mut self, ctx: &mut SystemContext) {
|
||||
ctx.scene.world.spawn((Camera {
|
||||
eye: Vec3::new(0.0, 0.0, 2.0),
|
||||
|
|
@ -93,15 +93,32 @@ impl System for FPSCameraSystem {
|
|||
self.pitch = self.pitch.clamp(-89.0, 89.0);
|
||||
}
|
||||
|
||||
let front = self.front();
|
||||
let right_vec = front.cross(Vec3::Y).normalize();
|
||||
let input = ctx.input_state.borrow_mut();
|
||||
|
||||
if input.key_held(KeyCode::KeyW) {
|
||||
self.position += front * ctx.platform_context.time_ctx.frame_dt * self.speed;
|
||||
}
|
||||
if input.key_held(KeyCode::KeyS) {
|
||||
self.position -= front * ctx.platform_context.time_ctx.frame_dt * self.speed;
|
||||
}
|
||||
if input.key_held(KeyCode::KeyA) {
|
||||
self.position -= right_vec * ctx.platform_context.time_ctx.frame_dt * self.speed;
|
||||
}
|
||||
if input.key_held(KeyCode::KeyD) {
|
||||
self.position += right_vec * ctx.platform_context.time_ctx.frame_dt * self.speed;
|
||||
}
|
||||
|
||||
ctx.scene.world.query_mut::<&mut Camera>().into_iter().for_each(|(_, camera)| {
|
||||
camera.eye = self.position;
|
||||
camera.center = self.position + self.front();
|
||||
camera.center = self.position + front;
|
||||
});
|
||||
self.mouse_delta = (0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl FPSCameraSystem {
|
||||
impl FPSDebugCameraSystem {
|
||||
pub fn front(&self) -> Vec3 {
|
||||
let yaw_rad = self.yaw.to_radians();
|
||||
let pitch_rad = self.pitch.to_radians();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue