M server/src/orbit/orbit.rs => server/src/orbit/orbit.rs +3 -1
@@ 1,6 1,7 @@
// Mostly stolen from SebLague's plane game
// thanks
+use log::debug;
use nalgebra::{vector, Vector2};
use crate::orbit::newtonian::solve_kepler_with_newtonian;
use crate::orbit::vis_viva::vis_viva;
@@ 19,8 20,9 @@ pub fn calculate_vector_of_orbit(periapsis: f64, apoapsis: f64, t: f64, mass_of_
let velocity = vis_viva(distance, semi_major_length, GRAVITY, mass_of_bigger);
let ellipse_center_x = -linear_eccentricity;
+ let ellipse_center_y = apoapsis - semi_major_length;
- let theta = (ellipse_center_x / velocity).acos() - std::f64::consts::PI / 2.0;
+ let theta = (ellipse_center_x / ellipse_center_y).atan() - std::f64::consts::PI / 2.0;
let x_vel = velocity * theta.sin();
let y_vel = velocity * theta.cos();
M server/src/timer.rs => server/src/timer.rs +3 -2
@@ 37,8 37,9 @@ pub async fn timer_main(mgr: ClientManager, physics_data: Arc<RwLock<PhysicsData
let new_moon_position = calculate_world_position_of_orbit(calculate_point_on_orbit(MOON_PERIAPSIS, MOON_APOAPSIS, time / MOON_ORBIT_TIME), new_earth_position);
let moon_body = physics_data.rigid_body_set.get_mut(planets.get_planet_mut("moon").unwrap().body_handle).unwrap();
let moon_force = calculate_vector_of_orbit(MOON_PERIAPSIS, MOON_APOAPSIS, time / MOON_ORBIT_TIME, EARTH_MASS, moon_body.linvel().x, moon_body.linvel().y, 1f64/20f64, MOON_MASS);
- moon_body.apply_impulse(moon_force, true);
- planets.get_planet_mut("moon").unwrap().position = (new_moon_position[0] / SCALE, new_moon_position[1] / SCALE);
+ moon_body.reset_forces(true);
+ moon_body.add_force(moon_force, true);
+ planets.get_planet_mut("moon").unwrap().position = (moon_body.translation()[0] / SCALE, moon_body.translation()[1] / SCALE);
}
physics_data.tick(&mut pipeline);