implement "orbit_phase_offset" command

This commit is contained in:
yuni 2024-04-30 00:56:41 +02:00
parent 7f5894f9f7
commit 15bd02f6f8
2 changed files with 25 additions and 10 deletions

View file

@ -254,6 +254,21 @@ pub fn load_defs(
continue;
}
}
["orbit_phase_offset", value] => {
if let Ok(value_float) = value.parse::<f64>() {
let offset_radians = 2.0 * PI64 * value_float;
if let Some(phase_radians) = state.orbit_phase {
state.orbit_phase = Some(phase_radians + offset_radians);
}
else {
state.orbit_phase = Some(offset_radians);
}
}
else {
error!("Can't parse float: {line}");
continue;
}
}
["sphere", "yes"] => {
state.is_sphere = true;
}
@ -519,9 +534,11 @@ fn spawn_entities(
state.pos
};
if let Some(r) = state.orbit_distance {
let phase_radians: f64 = if let Some(phase_radians) = state.orbit_phase {
phase_radians
} else if let Some(id) = &state.orbit_object_id {
let mut phase_radians = 0.0f64;
if let Some(phase) = state.orbit_phase {
phase_radians += phase;
}
if let Some(id) = &state.orbit_object_id {
let mass = match id.as_str() {
"jupiter" => nature::JUPITER_MASS,
_ => {
@ -530,16 +547,13 @@ fn spawn_entities(
}
};
let orbital_period = nature::simple_orbital_period(mass, r);
if let Ok(epoch) = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
phase_radians += if let Ok(epoch) = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
PI64 * 2.0 * (epoch.as_secs_f64() % orbital_period) / orbital_period
} else {
error!("Can't determine current time `{id}`");
0.0
}
} else {
error!("if state.orbit_distance is set, then either state.orbit_object_id or state.orbit_phase must be set as well.");
continue;
};
}
absolute_pos += nature::phase_dist_to_coords(phase_radians, r);
}
let scale = Vec3::splat(if state.is_sun {

View file

@ -122,7 +122,8 @@ actor 0 0 0 jupiter
actor 0 593051 0 suitv2
relativeto jupiter
orbit 224000e3 0.66
orbitaround jupiter 221900e3
orbit_phase_offset 0.003
player yes
id player
scale 2