diff options
| author | Jon Santmyer <jon@jonsantmyer.com> | 2026-05-07 08:50:05 -0400 |
|---|---|---|
| committer | Jon Santmyer <jon@jonsantmyer.com> | 2026-05-07 08:50:05 -0400 |
| commit | c1adf64c1aaecd5a2b9d532d707ef35971f1aa18 (patch) | |
| tree | fc1050becd0576d75a8d6afb8be09fae80c91541 /src/solar_system | |
| parent | 9788d9037ad7199701b1710c28559cb96bce5aec (diff) | |
| download | systemic4x-c1adf64c1aaecd5a2b9d532d707ef35971f1aa18.tar.gz systemic4x-c1adf64c1aaecd5a2b9d532d707ef35971f1aa18.tar.bz2 systemic4x-c1adf64c1aaecd5a2b9d532d707ef35971f1aa18.zip | |
begin work on body info window
Diffstat (limited to 'src/solar_system')
| -rw-r--r-- | src/solar_system/body.rs | 4 | ||||
| -rw-r--r-- | src/solar_system/fleet.rs | 60 | ||||
| -rw-r--r-- | src/solar_system/orbit.rs | 4 | ||||
| -rw-r--r-- | src/solar_system/ship.rs | 36 |
4 files changed, 64 insertions, 40 deletions
diff --git a/src/solar_system/body.rs b/src/solar_system/body.rs index 55d3d4a..7618a95 100644 --- a/src/solar_system/body.rs +++ b/src/solar_system/body.rs @@ -81,12 +81,12 @@ impl OrbitalBody -> cgmath::Vector3<Kilometers> { match &self.orbit { - Some(orbit) => orbit.calculate_position_at(self, time), + Some(orbit) => orbit.calculate_position_at(self.sgp(), time), None => cgmath::vec3(0.0, 0.0, 0.0) } } - pub fn update( + pub fn tick( &mut self, time: Second) { diff --git a/src/solar_system/fleet.rs b/src/solar_system/fleet.rs new file mode 100644 index 0000000..c331cd7 --- /dev/null +++ b/src/solar_system/fleet.rs @@ -0,0 +1,60 @@ +use crate::solar_system::{GRAVITATIONAL_CONSTANT, Kilometers, SolarSystem, body::OrbitalBody, orbit::StaticOrbit}; +use crate::timeman::Second; + +pub type FleetId = usize; + +pub struct Fleet +{ + id: FleetId, + name: String, + + position: cgmath::Vector3<Kilometers>, + velocity: cgmath::Vector3<f32>, + acceleration: cgmath::Vector3<f32>, + + baked_orbit: Option<(f64, StaticOrbit)>, +} + +impl Fleet +{ + pub fn new( + id: FleetId, + name: String) + -> Self + { + Self { + id, + name, + position: cgmath::vec3(0.0, 0.0, 0.0), + velocity: cgmath::vec3(0.0, 0.0, 0.0), + acceleration: cgmath::vec3(0.0, 0.0, 0.0), + baked_orbit: None, + } + } + + pub fn id(&self) -> FleetId { self.id } + pub fn name(&self) -> &String { &self.name } + + pub fn make_orbit( + &mut self, + body: &OrbitalBody, + radius: Kilometers) + { + let sgp = body.mass() * GRAVITATIONAL_CONSTANT; + self.baked_orbit = Some((sgp, StaticOrbit::new_circular(body, radius))); + } + + pub fn tick( + &mut self, + time: Second) + { + match &self.baked_orbit { + Some(orbit_info) => { + let sgp = orbit_info.0; + let orbit = &orbit_info.1; + self.position = orbit.calculate_position_at(sgp, time); + }, + None => {} + } + } +} diff --git a/src/solar_system/orbit.rs b/src/solar_system/orbit.rs index 461de7b..1800127 100644 --- a/src/solar_system/orbit.rs +++ b/src/solar_system/orbit.rs @@ -65,7 +65,7 @@ impl StaticOrbit pub fn calculate_position_at( &self, - this_body: &OrbitalBody, + sgp: f64, time: Second) -> cgmath::Vector3<f64> { @@ -75,7 +75,7 @@ impl StaticOrbit let arg_periaps = self.long_periapsis - long_asc_node; let sma_cubed = self.semi_major_axis.powf(3.0); - let mean_motion = (this_body.sgp() / sma_cubed).sqrt(); + let mean_motion = (sgp / sma_cubed).sqrt(); let mean_anomaly_epoch = self.mean_long - self.long_periapsis; let mean_anomaly = mean_anomaly_epoch + (mean_motion * time as f64); diff --git a/src/solar_system/ship.rs b/src/solar_system/ship.rs deleted file mode 100644 index 57c0184..0000000 --- a/src/solar_system/ship.rs +++ /dev/null @@ -1,36 +0,0 @@ -use crate::solar_system::{Kilograms, Kilometers, SolarSystem, body::BodyId, orbit::StaticOrbit}; - -pub type ShipId = usize; - -pub struct Ship -{ - name: String, - mass: Kilograms, - - position: cgmath::Vector3<Kilometers>, - velocity: cgmath::Vector3<f32>, - acceleration: cgmath::Vector3<f32>, - - baked_orbit: Option<StaticOrbit> -} - -impl Ship -{ - pub fn new( - name: String, - mass: Kilograms, - system: &SolarSystem, - orbiting: BodyId, - orbit_sma: Kilometers) - -> Self - { - Self { - name, - mass, - position: cgmath::vec3(0.0, 0.0, 0.0), - velocity: cgmath::vec3(0.0, 0.0, 0.0), - acceleration: cgmath::vec3(0.0, 0.0, 0.0), - baked_orbit: None - } - } -} |
