1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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 => {}
}
}
}
|