normalize mouse sensitivity across screen resolutions
This commit is contained in:
parent
abaed74424
commit
db3545e9a3
1 changed files with 14 additions and 8 deletions
|
@ -157,7 +157,7 @@ fn manage_player_actor(
|
|||
pub fn apply_input_to_player(
|
||||
time: Res<Time>,
|
||||
settings: Res<settings::Settings>,
|
||||
mut windows: Query<&mut Window, With<PrimaryWindow>>,
|
||||
windows: Query<&Window, With<PrimaryWindow>>,
|
||||
mut mouse_events: EventReader<MouseMotion>,
|
||||
key_input: Res<ButtonInput<KeyCode>>,
|
||||
thruster_sound_controller: Query<&AudioSink, With<audio::ComponentThrusterSound>>,
|
||||
|
@ -177,10 +177,16 @@ pub fn apply_input_to_player(
|
|||
let mut play_thruster_sound = false;
|
||||
let mut axis_input: DVec3 = DVec3::ZERO;
|
||||
|
||||
let window_result = windows.get_single_mut();
|
||||
let (win_res_x, win_res_y): (f32, f32);
|
||||
let mut focused = true;
|
||||
if window_result.is_ok() {
|
||||
focused = window_result.unwrap().focused;
|
||||
if let Ok(window) = &windows.get_single() {
|
||||
focused = window.focused;
|
||||
win_res_x = window.resolution.width();
|
||||
win_res_y = window.resolution.height();
|
||||
}
|
||||
else {
|
||||
win_res_x = 1920.0;
|
||||
win_res_y = 1050.0;
|
||||
}
|
||||
|
||||
let target_v: DVec3 = if let Ok(target) = q_target.get_single() {
|
||||
|
@ -288,10 +294,10 @@ pub fn apply_input_to_player(
|
|||
}
|
||||
if mouse_delta != Vec2::ZERO {
|
||||
if key_input.pressed(settings.key_rotate) {
|
||||
pitch_yaw_rot[2] += mouse_delta.x;
|
||||
pitch_yaw_rot[2] += 1000.0 * mouse_delta.x / win_res_x;
|
||||
} else {
|
||||
pitch_yaw_rot[0] += mouse_delta.y;
|
||||
pitch_yaw_rot[1] -= mouse_delta.x;
|
||||
pitch_yaw_rot[0] += 1000.0 * mouse_delta.y / win_res_y;
|
||||
pitch_yaw_rot[1] -= 1000.0 * mouse_delta.x / win_res_x;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,7 +307,7 @@ pub fn apply_input_to_player(
|
|||
pitch_yaw_rot *= settings.mouse_sensitivity * sensitivity_factor * engine.reaction_wheels;
|
||||
torque.apply_torque(DVec3::from(
|
||||
player_transform.rotation * Vec3::new(
|
||||
pitch_yaw_rot[0] * 2.0,
|
||||
pitch_yaw_rot[0],
|
||||
pitch_yaw_rot[1],
|
||||
pitch_yaw_rot[2])));
|
||||
angularvelocity.0 *= angular_slowdown.clamp(0.97, 1.0) as f64;
|
||||
|
|
Loading…
Add table
Reference in a new issue