add jilk+uo keys for mouseless camera control

This commit is contained in:
yuni 2024-03-30 19:36:43 +01:00
parent 6703431ac6
commit 257094dc8e
3 changed files with 54 additions and 15 deletions

View file

@ -28,9 +28,18 @@ Key features:
- f: toggle 3rd person view - f: toggle 3rd person view
- TAB: toggle augmented reality overlay (HUD, low-light amplifier) - TAB: toggle augmented reality overlay (HUD, low-light amplifier)
Extra key bindings for mouseless playing:
- j: look left
- i: look up
- k: look down
- l: look right
- u: rotate left
- o: rotate right
# System Requirements # System Requirements
- Screen, keyboard, mouse - Screen, keyboard
- Operating System: Linux, Windows, MacOS - Operating System: Linux, Windows, MacOS
- Ideally, a graphics card with vulkan support - Ideally, a graphics card with vulkan support

View file

@ -197,12 +197,13 @@ fn apply_input_to_player(
let mut acceleration_total = actor::ENGINE_SPEED_FACTOR * dt * acceleration_global; let mut acceleration_total = actor::ENGINE_SPEED_FACTOR * dt * acceleration_global;
let threshold = 1e-5; let threshold = 1e-5;
if key_input.pressed(settings.key_stop) { if key_input.pressed(settings.key_stop) {
// Decelerate
for i in 0..3 { for i in 0..3 {
if v[i].abs() < threshold { if v[i].abs() < threshold {
v[i] = 0.0; v[i] = 0.0;
} }
else if v[i].signum() != (v[i] + acceleration_total[i]).signum() { else if v[i].signum() != (v[i] + acceleration_total[i]).signum() {
// Overshoot // Almost stopped, but we overshot v=0
v[i] = 0.0; v[i] = 0.0;
acceleration_total[i] = 0.0; acceleration_total[i] = 0.0;
} }
@ -216,29 +217,46 @@ fn apply_input_to_player(
engine.current_warmup = (engine.current_warmup - dt / engine.warmup_seconds).clamp(0.0, 1.0); engine.current_warmup = (engine.current_warmup - dt / engine.warmup_seconds).clamp(0.0, 1.0);
} }
// Handle mouse input // Handle mouse input and mouse-like key bindings
let mut mouse_delta = Vec2::ZERO; let mut mouse_delta = Vec2::ZERO;
let mut pitch_yaw_rot = Vec3::ZERO;
let mouseless_sensitivity = 8.0;
if key_input.pressed(settings.key_mouseup) {
pitch_yaw_rot[0] -= mouseless_sensitivity;
}
if key_input.pressed(settings.key_mousedown) {
pitch_yaw_rot[0] += mouseless_sensitivity;
}
if key_input.pressed(settings.key_mouseleft) {
pitch_yaw_rot[1] += mouseless_sensitivity;
}
if key_input.pressed(settings.key_mouseright) {
pitch_yaw_rot[1] -= mouseless_sensitivity;
}
if key_input.pressed(settings.key_rotateleft) {
pitch_yaw_rot[2] -= mouseless_sensitivity;
}
if key_input.pressed(settings.key_rotateright) {
pitch_yaw_rot[2] += mouseless_sensitivity;
}
for mouse_event in mouse_events.read() { for mouse_event in mouse_events.read() {
mouse_delta += mouse_event.delta; mouse_delta += mouse_event.delta;
} }
if mouse_delta != Vec2::ZERO { if mouse_delta != Vec2::ZERO {
// Apply look update
let mouse_y_movement = (mouse_delta.y * RADIANS_PER_DOT * settings.mouse_sensitivity).clamp(-PI / 2., PI / 2.);
let mouse_x_movement = -mouse_delta.x * RADIANS_PER_DOT * settings.mouse_sensitivity;
let (pitch, yaw, rot);
if key_input.pressed(settings.key_rotate) { if key_input.pressed(settings.key_rotate) {
pitch = 0.0; pitch_yaw_rot[2] += mouse_delta.x;
yaw = 0.0;
rot = mouse_x_movement;
} else { } else {
pitch = mouse_y_movement; pitch_yaw_rot[0] += mouse_delta.y;
yaw = mouse_x_movement; pitch_yaw_rot[1] -= mouse_delta.x;
rot = 0.0;
} }
player_transform.rotation *= Quat::from_euler(EulerRot::ZYX, rot, yaw, pitch).normalize(); }
if pitch_yaw_rot.length_squared() > 0.0001 {
pitch_yaw_rot *= RADIANS_PER_DOT * settings.mouse_sensitivity;
player_transform.rotation *= Quat::from_euler(EulerRot::ZYX,
pitch_yaw_rot[2], pitch_yaw_rot[1], pitch_yaw_rot[0]).normalize();
} }
// Play sound effects
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()

View file

@ -28,6 +28,12 @@ pub struct Settings {
pub key_vehicle: KeyCode, pub key_vehicle: KeyCode,
pub key_camera: KeyCode, pub key_camera: KeyCode,
pub key_rotate: KeyCode, pub key_rotate: KeyCode,
pub key_mouseup: KeyCode,
pub key_mousedown: KeyCode,
pub key_mouseleft: KeyCode,
pub key_mouseright: KeyCode,
pub key_rotateleft: KeyCode,
pub key_rotateright: KeyCode,
pub key_reply1: KeyCode, pub key_reply1: KeyCode,
pub key_reply2: KeyCode, pub key_reply2: KeyCode,
pub key_reply3: KeyCode, pub key_reply3: KeyCode,
@ -78,6 +84,12 @@ impl Default for Settings {
key_vehicle: KeyCode::KeyQ, key_vehicle: KeyCode::KeyQ,
key_camera: KeyCode::KeyF, key_camera: KeyCode::KeyF,
key_rotate: KeyCode::KeyR, key_rotate: KeyCode::KeyR,
key_mouseup: KeyCode::KeyI,
key_mousedown: KeyCode::KeyK,
key_mouseleft: KeyCode::KeyJ,
key_mouseright: KeyCode::KeyL,
key_rotateleft: KeyCode::KeyU,
key_rotateright: KeyCode::KeyO,
key_reply1: KeyCode::Digit1, key_reply1: KeyCode::Digit1,
key_reply2: KeyCode::Digit2, key_reply2: KeyCode::Digit2,
key_reply3: KeyCode::Digit3, key_reply3: KeyCode::Digit3,