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 glam::{Quat, Vec3};
|
||||||
use winit::event::DeviceEvent::MouseMotion;
|
use winit::event::DeviceEvent::MouseMotion;
|
||||||
use winit::event::{ElementState, Event, MouseButton, WindowEvent};
|
use winit::event::{ElementState, Event, MouseButton, WindowEvent};
|
||||||
use winit::keyboard::PhysicalKey;
|
use winit::keyboard::{KeyCode, PhysicalKey};
|
||||||
use winit::window::CursorGrabMode;
|
use winit::window::CursorGrabMode;
|
||||||
use raidillon_assets::model_path;
|
use raidillon_assets::model_path;
|
||||||
use raidillon_platform::Camera;
|
use raidillon_platform::Camera;
|
||||||
|
|
||||||
pub struct FPSCameraSystem {
|
pub struct FPSDebugCameraSystem {
|
||||||
mouse_delta: (f64, f64),
|
mouse_delta: (f64, f64),
|
||||||
mouse_enabled: bool,
|
mouse_enabled: bool,
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
|
|
@ -17,7 +17,7 @@ pub struct FPSCameraSystem {
|
||||||
sensitivity: f32,
|
sensitivity: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for FPSCameraSystem {
|
impl Default for FPSDebugCameraSystem {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
mouse_delta: Default::default(),
|
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) {
|
fn load_world(&mut self, ctx: &mut SystemContext) {
|
||||||
ctx.scene.world.spawn((Camera {
|
ctx.scene.world.spawn((Camera {
|
||||||
eye: Vec3::new(0.0, 0.0, 2.0),
|
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);
|
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)| {
|
ctx.scene.world.query_mut::<&mut Camera>().into_iter().for_each(|(_, camera)| {
|
||||||
camera.eye = self.position;
|
camera.eye = self.position;
|
||||||
camera.center = self.position + self.front();
|
camera.center = self.position + front;
|
||||||
});
|
});
|
||||||
self.mouse_delta = (0.0, 0.0);
|
self.mouse_delta = (0.0, 0.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FPSCameraSystem {
|
impl FPSDebugCameraSystem {
|
||||||
pub fn front(&self) -> Vec3 {
|
pub fn front(&self) -> Vec3 {
|
||||||
let yaw_rad = self.yaw.to_radians();
|
let yaw_rad = self.yaw.to_radians();
|
||||||
let pitch_rad = self.pitch.to_radians();
|
let pitch_rad = self.pitch.to_radians();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue