atmosphere: implement correct altitude gauge

This commit is contained in:
yuni 2024-11-28 01:53:56 +01:00
parent 74cb35d3ac
commit 777358e8ae
2 changed files with 8 additions and 7 deletions

View file

@ -1167,7 +1167,7 @@ fn handle_atmosphere(
if player.is_some() { if player.is_some() {
settings.atmo_pressure = Some(pressure); settings.atmo_pressure = Some(pressure);
settings.atmo_altitude = Some(height); settings.atmo_altitude = Some(distance - nature::JUPITER_RADIUS);
reset_player_gauges = false; reset_player_gauges = false;
} }

View file

@ -156,15 +156,16 @@ pub fn readable_speed(speed: f64) -> String {
} }
pub fn readable_si(value: f64) -> String { pub fn readable_si(value: f64) -> String {
if value > 1e10 { let abs = value.abs();
if abs > 1e10 {
return format!("{:.1} G", value / 1e9); return format!("{:.1} G", value / 1e9);
} else if value > 1e7 { } else if abs > 1e7 {
return format!("{:.1} M", value / 1e6); return format!("{:.1} M", value / 1e6);
} else if value > 1e4 { } else if abs > 1e4 {
return format!("{:.1} k", value / 1e3); return format!("{:.1} k", value / 1e3);
} else if value < 1e-2 { } else if abs < 1e-2 {
return format!("{:.1} m", value * 1e3); return format!("{:.1} m", value * 1e3);
} else if value < 1e-5 { } else if abs < 1e-5 {
return format!("{:.1} µ", value * 1e3); return format!("{:.1} µ", value * 1e3);
} }
return format!("{:.1} ", value); return format!("{:.1} ", value);
@ -299,5 +300,5 @@ pub fn jupiter_altitude_to_pressure(altitude: f64) -> f64 {
} else if x >= 0.0 { } else if x >= 0.0 {
return (-0.0020248515 - 0.0000454102 * x).exp(); return (-0.0020248515 - 0.0000454102 * x).exp();
} }
return -(1.45773e-16) * x.powf(3.0) + 1; return -(1.45773e-16) * x.powf(3.0) + 1.0;
} }