From c1adf64c1aaecd5a2b9d532d707ef35971f1aa18 Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Thu, 7 May 2026 08:50:05 -0400 Subject: begin work on body info window --- src/solar_system/fleet.rs | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/solar_system/fleet.rs (limited to 'src/solar_system/fleet.rs') 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, + velocity: cgmath::Vector3, + acceleration: cgmath::Vector3, + + 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 => {} + } + } +} -- cgit v1.2.3