implement special relativity (for speed cheats only, so far)

This commit is contained in:
yuni 2024-05-13 06:10:34 +02:00
parent dd2e596f5c
commit 3814aa4155
2 changed files with 10 additions and 8 deletions

View file

@ -136,13 +136,15 @@ fn handle_cheats(
gforce.ignore_gforce_seconds = 1.0;
v.0 = DVec3::ZERO;
}
if key_input.pressed(settings.key_cheat_speed) {
if key_input.pressed(settings.key_cheat_speed) || key_input.pressed(settings.key_cheat_speed_backward) {
gforce.ignore_gforce_seconds = 1.0;
v.0 += DVec3::from(trans.rotation * Vec3::new(0.0, 0.0, boost));
}
if key_input.pressed(settings.key_cheat_speed_backward) {
gforce.ignore_gforce_seconds = 1.0;
v.0 += DVec3::from(trans.rotation * Vec3::new(0.0, 0.0, -boost));
let sign = if key_input.pressed(settings.key_cheat_speed) { 1.0 } else { -1.0 };
let dv = DVec3::from(trans.rotation * Vec3::new(0.0, 0.0, sign * boost));
let current_speed = v.0.length();
let next_speed = (v.0 + dv).length();
let avg_speed = (current_speed + next_speed) / 2.0;
let inv_lorentz = nature::inverse_lorentz_factor(avg_speed.clamp(0.0, nature::C));
v.0 = v.0 + inv_lorentz * dv;
}
if key_input.just_pressed(settings.key_cheat_teleport) {
if let Ok((transform, target_pos, target_v)) = q_target.get_single() {

View file

@ -147,11 +147,11 @@ pub fn lorentz_factor_custom_c(speed: f64, c: f64) -> f64 {
}
pub fn inverse_lorentz_factor(speed: f64) -> f64 {
(1.0 - (speed.powf(2.0) / C.powf(2.0))).powf(0.5)
(1.0 - (speed.powf(2.0) / C.powf(2.0))).sqrt()
}
pub fn inverse_lorentz_factor_custom_c(speed: f64, c: f64) -> f64 {
(1.0 - (speed.powf(2.0) / c.powf(2.0))).powf(0.5)
(1.0 - (speed.powf(2.0) / c.powf(2.0))).sqrt()
}
pub fn simple_orbital_period(mass: f64, distance: f64) -> f64 {