diff options
| author | Jon Santmyer <jon@jonsantmyer.com> | 2026-05-24 13:04:10 -0400 |
|---|---|---|
| committer | Jon Santmyer <jon@jonsantmyer.com> | 2026-05-24 13:04:10 -0400 |
| commit | 0b428d94e751dc4a5fbe19418bfb5994cebfa54c (patch) | |
| tree | be9c338ec6b5e40ddb96d2d8ecb498b362851a2f /src/solar_system | |
| parent | 14ca7b5fc15eb2618b46bde0cac85e37ebc9ebd9 (diff) | |
| download | systemic4x-0b428d94e751dc4a5fbe19418bfb5994cebfa54c.tar.gz systemic4x-0b428d94e751dc4a5fbe19418bfb5994cebfa54c.tar.bz2 systemic4x-0b428d94e751dc4a5fbe19418bfb5994cebfa54c.zip | |
Diffstat (limited to 'src/solar_system')
| -rw-r--r-- | src/solar_system/body.rs | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/solar_system/body.rs b/src/solar_system/body.rs index f3aef8c..5bf41b5 100644 --- a/src/solar_system/body.rs +++ b/src/solar_system/body.rs @@ -1,4 +1,4 @@ -use crate::timeman; +use crate::{timeman}; use super::*; @@ -17,7 +17,6 @@ pub struct OrbitalBody sgp: f64, orbit: Option<StaticOrbit>, - rel_pos: Option<(i64, cgmath::Vector3<Kilometers>)> } impl StaticOrbiter for OrbitalBody { @@ -58,8 +57,7 @@ impl OrbitalBody record.semi_major_axis )), None => None - }, - rel_pos: None + } } } @@ -70,7 +68,20 @@ impl OrbitalBody pub fn mass(&self) -> Kilograms { self.mass } pub fn sgp(&self) -> f64 { self.sgp } - pub fn relative_position( + pub fn origin_position( + &self, + star_system: &SolarSystem, + time: Second) + -> cgmath::Vector3<Kilometers> + { + if let Some(orbit) = &self.orbit { + star_system.body(orbit.parent()).absolute_position(star_system, time) + }else{ + cgmath::vec3(0.0, 0.0, 0.0) + } + } + + pub fn offset_position( &self, time: Second) -> cgmath::Vector3<f64> @@ -81,17 +92,11 @@ impl OrbitalBody pub fn absolute_position( &self, - solar_system: &SolarSystem, + star_system: &SolarSystem, time: Second) -> cgmath::Vector3<Kilometers> { - match &self.orbit { - Some(orbit) => { - let parent_pos = solar_system.bodies()[orbit.parent()].absolute_position(solar_system, time); - parent_pos + self.relative_position(time) - }, - None => self.relative_position(time) - } + self.origin_position(star_system, time) + self.offset_position(time) } pub fn get_orbit(&self) -> &Option<StaticOrbit> { &self.orbit } |
