From 15bd02f6f8d0ee00996efd6fe14fd08d206db0cb Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 30 Apr 2024 00:56:41 +0200 Subject: [PATCH] implement "orbit_phase_offset" command --- src/commands.rs | 32 +++++++++++++++++++++++--------- src/data/defs.txt | 3 ++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index fff7723..e8a540e 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -254,6 +254,21 @@ pub fn load_defs( continue; } } + ["orbit_phase_offset", value] => { + if let Ok(value_float) = value.parse::() { + 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 { diff --git a/src/data/defs.txt b/src/data/defs.txt index 23a8900..d98afbc 100644 --- a/src/data/defs.txt +++ b/src/data/defs.txt @@ -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