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; 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"] => { ["sphere", "yes"] => {
state.is_sphere = true; state.is_sphere = true;
} }
@ -519,9 +534,11 @@ fn spawn_entities(
state.pos state.pos
}; };
if let Some(r) = state.orbit_distance { if let Some(r) = state.orbit_distance {
let phase_radians: f64 = if let Some(phase_radians) = state.orbit_phase { let mut phase_radians = 0.0f64;
phase_radians if let Some(phase) = state.orbit_phase {
} else if let Some(id) = &state.orbit_object_id { phase_radians += phase;
}
if let Some(id) = &state.orbit_object_id {
let mass = match id.as_str() { let mass = match id.as_str() {
"jupiter" => nature::JUPITER_MASS, "jupiter" => nature::JUPITER_MASS,
_ => { _ => {
@ -530,16 +547,13 @@ fn spawn_entities(
} }
}; };
let orbital_period = nature::simple_orbital_period(mass, r); 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 PI64 * 2.0 * (epoch.as_secs_f64() % orbital_period) / orbital_period
} else { } else {
error!("Can't determine current time `{id}`"); error!("Can't determine current time `{id}`");
0.0 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); absolute_pos += nature::phase_dist_to_coords(phase_radians, r);
} }
let scale = Vec3::splat(if state.is_sun { let scale = Vec3::splat(if state.is_sun {

View file

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