From ec218c635152549e484bc6e9b9185b1265f7f980 Mon Sep 17 00:00:00 2001 From: yuni Date: Thu, 3 Oct 2024 01:50:57 +0200 Subject: [PATCH] fix tidal locking rotation for galileian moons --- src/cmd.rs | 44 ++++++++++++++++++++++++-------------------- src/data/defs.txt | 21 ++++++++++++++------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/cmd.rs b/src/cmd.rs index 057fff0..4e5aa7e 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -839,29 +839,23 @@ fn spawn_entities( } else { state.pos }; - if let Some(r) = state.orbit_distance { - let mass: Option = if let Some(id) = &state.orbit_object_id { - match id.as_str() { - "jupiter" => Some(nature::JUPITER_MASS), - "sol" => Some(nature::JUPITER_MASS), - _ => { - error!("Found no mass for object `{id}`"); - continue; - } - } - } else { - None - }; - absolute_pos += nature::pos_offset_for_orbiting_body(r, mass, state.orbit_phase); - if state.is_tidally_locked { - if let Some(mass) = mass { - rotation = - Quat::from_rotation_y(nature::rotation_for_orbiting_body(r, mass) as f32); - } else { - error!("Attempted to use 'tidally locked' without specifying mass via 'orbitaround'"); + let orbited_mass: Option = if let Some(id) = &state.orbit_object_id { + match id.as_str() { + "jupiter" => Some(nature::JUPITER_MASS), + "sol" => Some(nature::JUPITER_MASS), + _ => { + error!("Found no mass for object `{id}`"); + continue; } } + } else { + None + }; + + if let Some(r) = state.orbit_distance { + absolute_pos += + nature::pos_offset_for_orbiting_body(r, orbited_mass, state.orbit_phase); } else if state.is_tidally_locked { error!("Attempted to use 'tidally locked' without specifying orbital distance via 'orbitaround'"); } @@ -931,6 +925,16 @@ fn spawn_entities( }); load_asset(model.as_str(), &mut actor, &*asset_server); } + if state.is_tidally_locked { + if let (Some(r), Some(mass)) = (state.orbit_distance, orbited_mass) { + rotation = Quat::from_rotation_y(nature::rotation_for_orbiting_body(r, mass) as f32) + * rotation; + } else { + error!( + "Attempted to use 'tidally locked' without specifying mass via 'orbitaround'" + ); + } + } actor.insert(Rotation::from(rotation)); // Physics Parameters diff --git a/src/data/defs.txt b/src/data/defs.txt index 2769dba..7ad931d 100644 --- a/src/data/defs.txt +++ b/src/data/defs.txt @@ -85,9 +85,10 @@ actor 0 0 0 relativeto jupiter id metis orbitaround jupiter 128000e3 + tidally locked scale 21.5e3 moon yes - angularmomentum 0 0.025 0 + angularmomentum 0 0 0 actor 0 0 0 orbitring relativeto jupiter scale 128000e3 @@ -99,9 +100,10 @@ actor 0 0 0 relativeto jupiter id adrastea orbitaround jupiter 129000e3 + tidally locked scale 8.2e3 moon yes - angularmomentum 0 0.025 0 + angularmomentum 0 0 0 actor 0 0 0 orbitring relativeto jupiter scale 129000e3 @@ -113,9 +115,10 @@ actor 0 0 0 relativeto jupiter id amalthea orbitaround jupiter 181365.84e3 + tidally locked scale 83.5e3 moon yes - angularmomentum 0 0.025 0 + angularmomentum 0 0 0 actor 0 0 0 orbitring relativeto jupiter scale 181365.84e3 @@ -143,8 +146,9 @@ actor 0 0 0 id io relativeto jupiter orbitaround jupiter 421700e3 + tidally locked scale 1822e3 - angularmomentum 0 0.0001 0 + angularmomentum 0 0 0 sphere yes moon yes physics off @@ -159,8 +163,9 @@ actor 0 0 0 id europa relativeto jupiter orbitaround jupiter 670900e3 + tidally locked scale 1561e3 - angularmomentum 0 0.0001 0 + angularmomentum 0 0 0 sphere yes moon yes physics off @@ -175,8 +180,9 @@ actor 0 0 0 id ganymede relativeto jupiter orbitaround jupiter 1070400e3 + tidally locked scale 2634e3 - angularmomentum 0 0.0001 0 + angularmomentum 0 0 0 sphere yes moon yes physics off @@ -191,8 +197,9 @@ actor 0 0 0 id callisto relativeto jupiter orbitaround jupiter 1882700e3 + tidally locked scale 2410e3 - angularmomentum 0 0.0001 0 + angularmomentum 0 0 0 sphere yes moon yes physics off