~starkingdoms/starkingdoms

e2b03ae7f5711feaedd4f02a966a57ee04a737cf — ghostlyzsh 2 years ago df2ea22 + 4d0f675
Merge branch 'master' of https://gitlab.com/starkingdoms.tk/starkingdoms.tk
3 files changed, 7 insertions(+), 4 deletions(-)

M server/src/orbit/orbit.rs
M server/src/planet.rs
M server/src/timer.rs
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/planet.rs => server/src/planet.rs +1 -1
@@ 46,7 46,7 @@ impl Planets {
    pub fn make_planet(planets: &mut HashMap<String, Planet>, planet_id: &str, planet_type: PlanetType, mass: f64, radius: f64, position: (f64, f64), rigid_body_set: &mut RigidBodySet, collider_set: &mut ColliderSet) {
        let collider = ColliderBuilder::ball(radius / SCALE)
            .build();
        let body = RigidBodyBuilder::fixed()
        let body = RigidBodyBuilder::dynamic()
            .translation(vector![position.0 / SCALE, position.1 / SCALE])
            .additional_mass(0.0);
        let body_handle = rigid_body_set.insert(body);

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);