diff --git a/Cargo.toml b/Cargo.toml index c85be0c..69ab763 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ authors = ["thomas"] [dependencies] clap = { version = "4.5.39", features = ["derive"] } env_logger = "0.11.8" +glam = { version = "0.30.4", features = ["serde"] } log = "0.4.27" serde = { version = "1.0.219", features = ["derive"] } serde_json = "1.0.140" diff --git a/src/config.rs b/src/config.rs index 92c784d..e5d43f0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,6 +7,9 @@ pub struct Body { pub mass: types::Mass, pub position: types::Position, pub velocity: types::Velocity, + + #[serde(default)] + pub acceleration: types::Acceleration, } #[derive(Debug, Deserialize)] diff --git a/src/simulator.rs b/src/simulator.rs index 276b5fa..d7e1b71 100644 --- a/src/simulator.rs +++ b/src/simulator.rs @@ -4,20 +4,32 @@ use crate::config::Body; pub struct Simulator { bodies: Vec, - step_size: f32, + step_size: f64, + } impl Simulator { - pub fn new(bodies: Vec, step_size: f32) -> Self{ + pub fn new(bodies: Vec, step_size: f64) -> Self{ Self {bodies, step_size} } pub fn run(&mut self, steps: usize){ for i in 0..steps { debug!("Step: {}", i); + self.step_bodies(); // for b in &self.bodies { // println!("Body: {}", b.name); // } } } + + fn step_bodies(&mut self) { + for body in &mut self.bodies { + //do for each of three (x,y,z) dimensions + body.position += self.step_size*body.velocity; + body.velocity += self.step_size*body.acceleration; + trace!("{} now at {:?}", body.name, body.position); + + } + } } \ No newline at end of file diff --git a/src/types.rs b/src/types.rs index e7e4868..86df870 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,5 +1,6 @@ -pub type Hval = f64; -pub type Position = [Hval; 3]; -pub type Velocity = [Hval; 3]; -pub type Acceleration = [Hval; 3]; -pub type Mass = Hval; +use glam::DVec3; + +pub type Position = DVec3; +pub type Velocity = DVec3; +pub type Acceleration = DVec3; +pub type Mass = f64;