refactoring camera::run_camera_controller
This commit is contained in:
parent
6e3d958638
commit
7431c4f594
|
@ -15,7 +15,8 @@ impl Plugin for CameraControllerPlugin {
|
||||||
app.add_systems(Update, handle_input);
|
app.add_systems(Update, handle_input);
|
||||||
app.add_systems(Update, manage_player_actor);
|
app.add_systems(Update, manage_player_actor);
|
||||||
app.add_systems(Update, sync_camera_to_player);
|
app.add_systems(Update, sync_camera_to_player);
|
||||||
app.add_systems(Update, run_camera_controller);
|
app.add_systems(Update, update_fov);
|
||||||
|
app.add_systems(Update, apply_input_to_player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +69,17 @@ pub fn sync_camera_to_player(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update_fov(
|
||||||
|
q_player: Query<&actor::LifeForm, With<actor::Player>>,
|
||||||
|
mut q_camera: Query<&mut Projection, With<Camera>>,
|
||||||
|
) {
|
||||||
|
if let (Ok(lifeform), Ok(mut projection)) = (q_player.get_single(), q_camera.get_single_mut())
|
||||||
|
{
|
||||||
|
let fov = (lifeform.adrenaline.powf(3.0) * 45.0 + 45.0).to_radians();
|
||||||
|
*projection = Projection::Perspective(PerspectiveProjection { fov: fov, ..default() });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn handle_input(
|
pub fn handle_input(
|
||||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
mut settings: ResMut<settings::Settings>,
|
mut settings: ResMut<settings::Settings>,
|
||||||
|
@ -96,7 +108,7 @@ fn manage_player_actor(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn run_camera_controller(
|
fn apply_input_to_player(
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
settings: Res<settings::Settings>,
|
settings: Res<settings::Settings>,
|
||||||
mut windows: Query<&mut Window, With<PrimaryWindow>>,
|
mut windows: Query<&mut Window, With<PrimaryWindow>>,
|
||||||
|
@ -106,8 +118,6 @@ fn run_camera_controller(
|
||||||
rocket_sound_controller: Query<&AudioSink, With<audio::ComponentRocketSound>>,
|
rocket_sound_controller: Query<&AudioSink, With<audio::ComponentRocketSound>>,
|
||||||
ion_sound_controller: Query<&AudioSink, With<audio::ComponentIonSound>>,
|
ion_sound_controller: Query<&AudioSink, With<audio::ComponentIonSound>>,
|
||||||
mut q_engine: Query<&mut actor::Engine, With<actor::PlayerDrivesThis>>,
|
mut q_engine: Query<&mut actor::Engine, With<actor::PlayerDrivesThis>>,
|
||||||
mut q_camera: Query<&mut Projection, With<Camera>>,
|
|
||||||
q_player: Query<&actor::LifeForm, With<actor::Player>>,
|
|
||||||
mut q_playercam: Query<(
|
mut q_playercam: Query<(
|
||||||
&mut Transform,
|
&mut Transform,
|
||||||
&mut actor::Engine,
|
&mut actor::Engine,
|
||||||
|
@ -124,11 +134,7 @@ fn run_camera_controller(
|
||||||
focused = window_result.unwrap().focused;
|
focused = window_result.unwrap().focused;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let (
|
if let Ok((mut player_transform, player_engine, mut angularvelocity, mut v)) = q_playercam.get_single_mut() {
|
||||||
Ok(mut projection),
|
|
||||||
Ok(lifeform),
|
|
||||||
Ok((mut player_transform, player_engine, mut angularvelocity, mut v)),
|
|
||||||
) = (q_camera.get_single_mut(), q_player.get_single(), q_playercam.get_single_mut()) {
|
|
||||||
|
|
||||||
if angularvelocity.length_squared() > 0.0001 {
|
if angularvelocity.length_squared() > 0.0001 {
|
||||||
angularvelocity.x *= 0.98;
|
angularvelocity.x *= 0.98;
|
||||||
|
@ -223,9 +229,6 @@ fn run_camera_controller(
|
||||||
player_transform.rotation *= Quat::from_euler(EulerRot::ZYX, 0.0, -yaw, pitch).normalize();
|
player_transform.rotation *= Quat::from_euler(EulerRot::ZYX, 0.0, -yaw, pitch).normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
let fov = (lifeform.adrenaline * lifeform.adrenaline * lifeform.adrenaline * 45.0 + 45.0).to_radians();
|
|
||||||
*projection = Projection::Perspective(PerspectiveProjection { fov: fov, ..default() });
|
|
||||||
|
|
||||||
if let Ok(sink) = thruster_sound_controller.get_single() {
|
if let Ok(sink) = thruster_sound_controller.get_single() {
|
||||||
if play_thruster_sound && engine.engine_type == actor::EngineType::Monopropellant {
|
if play_thruster_sound && engine.engine_type == actor::EngineType::Monopropellant {
|
||||||
sink.play()
|
sink.play()
|
||||||
|
|
Loading…
Reference in a new issue