summaryrefslogtreecommitdiffstats
path: root/src/solar_system/fleet.rs
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2026-05-07 08:50:05 -0400
committerJon Santmyer <jon@jonsantmyer.com>2026-05-07 08:50:05 -0400
commitc1adf64c1aaecd5a2b9d532d707ef35971f1aa18 (patch)
treefc1050becd0576d75a8d6afb8be09fae80c91541 /src/solar_system/fleet.rs
parent9788d9037ad7199701b1710c28559cb96bce5aec (diff)
downloadsystemic4x-c1adf64c1aaecd5a2b9d532d707ef35971f1aa18.tar.gz
systemic4x-c1adf64c1aaecd5a2b9d532d707ef35971f1aa18.tar.bz2
systemic4x-c1adf64c1aaecd5a2b9d532d707ef35971f1aa18.zip
begin work on body info window
Diffstat (limited to 'src/solar_system/fleet.rs')
-rw-r--r--src/solar_system/fleet.rs60
1 files changed, 60 insertions, 0 deletions
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 => {}
+ }
+ }
+}