fix distance display, and autoconvert large numbers to other units
This commit is contained in:
parent
1c9bcd7208
commit
b72a596559
15
src/hud.rs
15
src/hud.rs
|
@ -522,17 +522,14 @@ fn update_hud(
|
||||||
text.sections[17].value = format!("{integrity:.0}%");
|
text.sections[17].value = format!("{integrity:.0}%");
|
||||||
let speed = cam_v.length();
|
let speed = cam_v.length();
|
||||||
let kmh = speed * 60.0 * 60.0 / 1000.0;
|
let kmh = speed * 60.0 * 60.0 / 1000.0;
|
||||||
text.sections[19].value = format!("{speed:.0}m/s | {kmh:.0}km/h");
|
let speed_readable = nature::readable_distance(speed);
|
||||||
|
text.sections[19].value = format!("{speed_readable}/s | {kmh:.0}km/h");
|
||||||
|
|
||||||
// Target display
|
// Target display
|
||||||
let (x, y, z, dist_scalar) : (f64, f64, f64, f64);
|
let (x, y, z, dist_scalar) : (f64, f64, f64, f64);
|
||||||
if let Ok((_, IsClickable { distance: Some(dist), .. })) = q_target.get_single() {
|
if let Ok((_, IsClickable { distance: Some(dist), .. })) = q_target.get_single() {
|
||||||
if *dist >= 100000.0 {
|
|
||||||
dist_scalar = f64::NAN;
|
|
||||||
} else {
|
|
||||||
dist_scalar = *dist;
|
|
||||||
}
|
|
||||||
(x, y, z) = (0.0, 0.0, 0.0);
|
(x, y, z) = (0.0, 0.0, 0.0);
|
||||||
|
dist_scalar = *dist;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let target: Option<DVec3>;
|
let target: Option<DVec3>;
|
||||||
|
@ -560,7 +557,11 @@ fn update_hud(
|
||||||
text.sections[7].value = format!("distance: UNKNOWN");
|
text.sections[7].value = format!("distance: UNKNOWN");
|
||||||
}
|
}
|
||||||
else if dist_scalar != 0.0 {
|
else if dist_scalar != 0.0 {
|
||||||
text.sections[7].value = format!("{x:.0}m / {z:.0}m / {y:.0}m / distance: {dist_scalar:.0}m");
|
let x_readable = nature::readable_distance(x);
|
||||||
|
let y_readable = nature::readable_distance(y);
|
||||||
|
let z_readable = nature::readable_distance(z);
|
||||||
|
let distance_readable = nature::readable_distance(dist_scalar);
|
||||||
|
text.sections[7].value = format!("{x_readable} / {z_readable} / {y_readable} / distance: {distance_readable}");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
text.sections[7].value = format!("TARGET ERROR");
|
text.sections[7].value = format!("TARGET ERROR");
|
||||||
|
|
|
@ -7,6 +7,7 @@ pub const OXY_S: f32 = OXYGEN_USE_KG_PER_S;
|
||||||
pub const OXY_M: f32 = OXYGEN_USE_KG_PER_S * 60.0;
|
pub const OXY_M: f32 = OXYGEN_USE_KG_PER_S * 60.0;
|
||||||
pub const OXY_H: f32 = OXYGEN_USE_KG_PER_S * 60.0 * 60.0;
|
pub const OXY_H: f32 = OXYGEN_USE_KG_PER_S * 60.0 * 60.0;
|
||||||
pub const OXY_D: f32 = OXYGEN_USE_KG_PER_S * 60.0 * 60.0 * 24.0;
|
pub const OXY_D: f32 = OXYGEN_USE_KG_PER_S * 60.0 * 60.0 * 24.0;
|
||||||
|
pub const LIGHTYEAR2METER: f64 = 9_460_730_472_580_800.0;
|
||||||
pub const PARSEC2METER: f64 = 3.0857e16;
|
pub const PARSEC2METER: f64 = 3.0857e16;
|
||||||
pub const DIST_JUPTER_SUN: f64 = 778479.0e6;
|
pub const DIST_JUPTER_SUN: f64 = 778479.0e6;
|
||||||
pub const EARTH_GRAVITY: f32 = 9.81;
|
pub const EARTH_GRAVITY: f32 = 9.81;
|
||||||
|
@ -81,3 +82,23 @@ pub fn ring_density(radius: f32) -> f32 {
|
||||||
|
|
||||||
return density;
|
return density;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn readable_distance(distance: f64) -> String {
|
||||||
|
if distance > LIGHTYEAR2METER * 0.001 {
|
||||||
|
let lightyears = distance / LIGHTYEAR2METER;
|
||||||
|
return format!("{lightyears:.3}ly");
|
||||||
|
}
|
||||||
|
if distance >= 1.0e10 {
|
||||||
|
let gigameters = distance * 1.0e-9;
|
||||||
|
return format!("{gigameters:.1}Gm");
|
||||||
|
}
|
||||||
|
if distance >= 1.0e7 {
|
||||||
|
let megameters = distance * 1.0e-6;
|
||||||
|
return format!("{megameters:.1}Mm");
|
||||||
|
}
|
||||||
|
if distance >= 1.0e4 {
|
||||||
|
let kilometers = distance * 1.0e-3;
|
||||||
|
return format!("{kilometers:.1}km");
|
||||||
|
}
|
||||||
|
return format!("{distance:.1}m");
|
||||||
|
}
|
||||||
|
|
|
@ -151,9 +151,11 @@ pub fn setup(
|
||||||
});
|
});
|
||||||
let mesh_distance = 1e9;
|
let mesh_distance = 1e9;
|
||||||
let starchart_distance = if is_sun {
|
let starchart_distance = if is_sun {
|
||||||
nature::DIST_JUPTER_SUN
|
Some(nature::DIST_JUPTER_SUN)
|
||||||
|
} else if star.5 >= 100000.0 {
|
||||||
|
None
|
||||||
} else {
|
} else {
|
||||||
nature::PARSEC2METER * star.5 as f64
|
Some(nature::PARSEC2METER * star.5 as f64)
|
||||||
};
|
};
|
||||||
let name = if star.6.is_empty() {
|
let name = if star.6.is_empty() {
|
||||||
"Uncharted Star".to_string()
|
"Uncharted Star".to_string()
|
||||||
|
@ -164,7 +166,7 @@ pub fn setup(
|
||||||
Star,
|
Star,
|
||||||
hud::IsClickable {
|
hud::IsClickable {
|
||||||
name: Some(name),
|
name: Some(name),
|
||||||
distance: Some(starchart_distance),
|
distance: starchart_distance,
|
||||||
},
|
},
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: sphere_handle.clone(),
|
mesh: sphere_handle.clone(),
|
||||||
|
|
Loading…
Reference in a new issue