Started implementing stepping!
This commit is contained in:
parent
e07bb7c4a1
commit
64bec5af20
@ -9,6 +9,7 @@ authors = ["thomas"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.5.39", features = ["derive"] }
|
clap = { version = "4.5.39", features = ["derive"] }
|
||||||
env_logger = "0.11.8"
|
env_logger = "0.11.8"
|
||||||
|
glam = { version = "0.30.4", features = ["serde"] }
|
||||||
log = "0.4.27"
|
log = "0.4.27"
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
serde_json = "1.0.140"
|
serde_json = "1.0.140"
|
||||||
|
@ -7,6 +7,9 @@ pub struct Body {
|
|||||||
pub mass: types::Mass,
|
pub mass: types::Mass,
|
||||||
pub position: types::Position,
|
pub position: types::Position,
|
||||||
pub velocity: types::Velocity,
|
pub velocity: types::Velocity,
|
||||||
|
|
||||||
|
#[serde(default)]
|
||||||
|
pub acceleration: types::Acceleration,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
@ -4,20 +4,32 @@ use crate::config::Body;
|
|||||||
|
|
||||||
pub struct Simulator {
|
pub struct Simulator {
|
||||||
bodies: Vec<Body>,
|
bodies: Vec<Body>,
|
||||||
step_size: f32,
|
step_size: f64,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Simulator {
|
impl Simulator {
|
||||||
pub fn new(bodies: Vec<Body>, step_size: f32) -> Self{
|
pub fn new(bodies: Vec<Body>, step_size: f64) -> Self{
|
||||||
Self {bodies, step_size}
|
Self {bodies, step_size}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(&mut self, steps: usize){
|
pub fn run(&mut self, steps: usize){
|
||||||
for i in 0..steps {
|
for i in 0..steps {
|
||||||
debug!("Step: {}", i);
|
debug!("Step: {}", i);
|
||||||
|
self.step_bodies();
|
||||||
// for b in &self.bodies {
|
// for b in &self.bodies {
|
||||||
// println!("Body: {}", b.name);
|
// 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
11
src/types.rs
11
src/types.rs
@ -1,5 +1,6 @@
|
|||||||
pub type Hval = f64;
|
use glam::DVec3;
|
||||||
pub type Position = [Hval; 3];
|
|
||||||
pub type Velocity = [Hval; 3];
|
pub type Position = DVec3;
|
||||||
pub type Acceleration = [Hval; 3];
|
pub type Velocity = DVec3;
|
||||||
pub type Mass = Hval;
|
pub type Acceleration = DVec3;
|
||||||
|
pub type Mass = f64;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user