Started implementing stepping!
This commit is contained in:
parent
e07bb7c4a1
commit
64bec5af20
@ -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"
|
||||
|
@ -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)]
|
||||
|
@ -4,20 +4,32 @@ use crate::config::Body;
|
||||
|
||||
pub struct Simulator {
|
||||
bodies: Vec<Body>,
|
||||
step_size: f32,
|
||||
step_size: f64,
|
||||
|
||||
}
|
||||
|
||||
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}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
11
src/types.rs
11
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user