|
|
|
|
@ -1,5 +1,3 @@
|
|
|
|
|
use bevy::input::mouse::MouseButtonInput;
|
|
|
|
|
|
|
|
|
|
use crate::prelude::*;
|
|
|
|
|
|
|
|
|
|
/// Menu Plugin; empty struct for Plugin impl
|
|
|
|
|
@ -7,7 +5,8 @@ pub(crate) struct CameraPlugin;
|
|
|
|
|
|
|
|
|
|
impl Plugin for CameraPlugin {
|
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
|
app.add_systems(Update, editor_fly_camera);
|
|
|
|
|
app.add_systems(Update, move_editor_fly_camera);
|
|
|
|
|
app.add_systems(Update, rotate_editor_fly_camera);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -16,19 +15,21 @@ pub(crate) struct FlyCamera;
|
|
|
|
|
|
|
|
|
|
/// Fly camera system for moving around like a drone
|
|
|
|
|
/// TODO: Only if key is pressed!
|
|
|
|
|
fn editor_fly_camera(
|
|
|
|
|
fn move_editor_fly_camera(
|
|
|
|
|
mut cameras: Query<(&Camera, &mut Transform), With<FlyCamera>>,
|
|
|
|
|
windows: Query<&Window>,
|
|
|
|
|
primary_window: Query<Entity, With<PrimaryWindow>>,
|
|
|
|
|
keys: Res<ButtonInput<KeyCode>>,
|
|
|
|
|
mouse: Res<ButtonInput<MouseButton>>,
|
|
|
|
|
mut cursor_events: EventReader<CursorMoved>,
|
|
|
|
|
time: Res<Time>,
|
|
|
|
|
) {
|
|
|
|
|
let any_keys_pressed = keys.any_pressed([ KeyCode::KeyW, KeyCode::KeyS, KeyCode::KeyA, KeyCode::KeyD, KeyCode::KeyQ, KeyCode::KeyE ]);
|
|
|
|
|
let cursor_movement = cursor_events.len() > 0;
|
|
|
|
|
|
|
|
|
|
(any_keys_pressed || cursor_movement).then(|| {
|
|
|
|
|
(keys.any_pressed([
|
|
|
|
|
KeyCode::KeyW,
|
|
|
|
|
KeyCode::KeyS,
|
|
|
|
|
KeyCode::KeyA,
|
|
|
|
|
KeyCode::KeyD,
|
|
|
|
|
KeyCode::KeyQ,
|
|
|
|
|
KeyCode::KeyE
|
|
|
|
|
])).then(|| {
|
|
|
|
|
// Iterate over all cameras
|
|
|
|
|
cameras.iter_mut().for_each(|(c, mut t)| {
|
|
|
|
|
// Determine which window this camera is attached to
|
|
|
|
|
@ -65,7 +66,29 @@ fn editor_fly_camera(
|
|
|
|
|
}
|
|
|
|
|
t.translation += delta;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn rotate_editor_fly_camera(
|
|
|
|
|
mut cameras: Query<(&Camera, &mut Transform), With<FlyCamera>>,
|
|
|
|
|
windows: Query<&Window>,
|
|
|
|
|
primary_window: Query<Entity, With<PrimaryWindow>>,
|
|
|
|
|
mouse: Res<ButtonInput<MouseButton>>,
|
|
|
|
|
mut cursor_events: EventReader<CursorMoved>,
|
|
|
|
|
) {
|
|
|
|
|
(cursor_events.len() > 0).then(|| {
|
|
|
|
|
// Iterate over all cameras
|
|
|
|
|
cameras.iter_mut().for_each(|(c, mut t)| {
|
|
|
|
|
// Determine which window this camera is attached to
|
|
|
|
|
let target_window = match c.target {
|
|
|
|
|
RenderTarget::Window(wr) => match wr {
|
|
|
|
|
WindowRef::Entity(e) => Some(e),
|
|
|
|
|
WindowRef::Primary => Some(primary_window.get_single().unwrap()),
|
|
|
|
|
},
|
|
|
|
|
_ => None,
|
|
|
|
|
};
|
|
|
|
|
let window = windows.get(target_window.unwrap()).unwrap();
|
|
|
|
|
if mouse.pressed(MouseButton::Middle) {
|
|
|
|
|
cursor_events.read().filter_map(|CursorMoved { delta, window, .. }| {
|
|
|
|
|
(*window == target_window.unwrap()).then_some(delta)
|
|
|
|
|
|