Advanced orbit calculations
This commit is contained in:
parent
0618b81763
commit
5cd61b6086
@ -316,10 +316,11 @@ impl<'a> State<'a> {
|
||||
|
||||
let instances = {
|
||||
let sim = simulator.read().unwrap();
|
||||
let sun_pos = sim.bodies[0].position;
|
||||
sim.bodies.iter().enumerate().map(|(i, b)| RenderInstance {
|
||||
position: cgmath::Vector3::new(
|
||||
(b.position[0] / 1.496e11) as f32,
|
||||
(b.position[1] / 1.496e11) as f32,
|
||||
((b.position[0] - sun_pos[0]) / 1.496e11) as f32,
|
||||
((b.position[1] - sun_pos[1]) / 1.496e11) as f32,
|
||||
0.0,
|
||||
),
|
||||
rotation: cgmath::Quaternion::from_angle_z(cgmath::Deg(0.0)),
|
||||
@ -474,7 +475,7 @@ impl<'a> State<'a> {
|
||||
format: surface_format,
|
||||
width: size.width,
|
||||
height: size.height,
|
||||
present_mode: PresentMode::AutoNoVsync,
|
||||
present_mode: PresentMode::AutoVsync,
|
||||
alpha_mode: capabilities.alpha_modes[0],
|
||||
view_formats: vec![],
|
||||
desired_maximum_frame_latency: 2,
|
||||
|
||||
@ -87,8 +87,7 @@ impl Simulator {
|
||||
.map(|mutex| mutex.into_inner().unwrap())
|
||||
.collect()
|
||||
}
|
||||
|
||||
// RK4 Stufen
|
||||
|
||||
let k1_pos = original_states.iter().map(|s| s.velocity).collect::<Vec<_>>();
|
||||
let k1_vel = compute_accelerations(&original_states, &masses);
|
||||
|
||||
@ -130,10 +129,8 @@ impl Simulator {
|
||||
let k4_pos = temp_states.iter().map(|s| s.velocity).collect::<Vec<_>>();
|
||||
let k4_vel = compute_accelerations(&temp_states, &masses);
|
||||
|
||||
// Finale Updates
|
||||
for i in 0..n {
|
||||
let body = &mut self.bodies[i];
|
||||
let old_position = body.position;
|
||||
|
||||
body.position[0] += (dt / 6.0)
|
||||
* (k1_pos[i][0] + 2.0 * k2_pos[i][0] + 2.0 * k3_pos[i][0] + k4_pos[i][0]);
|
||||
@ -144,15 +141,6 @@ impl Simulator {
|
||||
* (k1_vel[i][0] + 2.0 * k2_vel[i][0] + 2.0 * k3_vel[i][0] + k4_vel[i][0]);
|
||||
body.velocity[1] += (dt / 6.0)
|
||||
* (k1_vel[i][1] + 2.0 * k2_vel[i][1] + 2.0 * k3_vel[i][1] + k4_vel[i][1]);
|
||||
|
||||
// Bewegung loggen
|
||||
let dx = body.position[0] - old_position[0];
|
||||
let dy = body.position[1] - old_position[1];
|
||||
let movement = (dx * dx + dy * dy).sqrt();
|
||||
|
||||
if i == 1 {
|
||||
println!("Earth moved {:.6} meters", movement);
|
||||
}
|
||||
}
|
||||
|
||||
self.time += dt;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user