~starkingdoms/starkingdoms

6e23340819969670c3897611192b04cd7c479168 — c0repwn3r 2 years ago 63a231d
orbits
3 files changed, 3 insertions(+), 6 deletions(-)

M server/src/orbit/constants.rs
M server/src/planet.rs
M server/src/timer.rs
M server/src/orbit/constants.rs => server/src/orbit/constants.rs +1 -1
@@ 24,4 24,4 @@ pub const MOON_MASS: f64 = MOON_MASS_RL * GAME_SCALE_MASS * MOON_MASS_BIAS;
pub const MOON_PERIAPSIS: f64 = 363228900.0 * GAME_SCALE_DISTANCE * MOON_PERIAPSIS_BIAS;
pub const MOON_APOAPSIS: f64 = 405400000.0  * GAME_SCALE_DISTANCE * MOON_APOAPSIS_BIAS;
pub const MOON_ORBIT_TIME_RL: f64 = 2332800.0;
pub const MOON_ORBIT_TIME: f64 = 1.0; //MOON_ORBIT_TIME_RL * GAME_SCALE_TIME * MOON_ORBIT_TIME_BIAS;
\ No newline at end of file
pub const MOON_ORBIT_TIME: f64 = MOON_ORBIT_TIME_RL * GAME_SCALE_TIME * MOON_ORBIT_TIME_BIAS;
\ No newline at end of file

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::dynamic()
        let body = RigidBodyBuilder::kinematic_position_based()
            .translation(vector![position.0 / SCALE, position.1 / SCALE])
            .dominance_group(127)
            .additional_mass(0.0);

M server/src/timer.rs => server/src/timer.rs +1 -4
@@ 36,10 36,7 @@ pub async fn timer_main(mgr: ClientManager, physics_data: Arc<RwLock<PhysicsData
            // update moon
            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, moon_body.translation().x, moon_body.translation().y, new_earth_position[0], new_earth_position[1],MOON_MASS, 1f64 / 20f64);
            moon_body.reset_forces(true);
            moon_body.add_force(moon_force, true);
            //moon_body.set_linvel(moon_force, true);
            moon_body.set_next_kinematic_position(new_moon_position.into());
            planets.get_planet_mut("moon").unwrap().position = (moon_body.translation()[0] / SCALE, moon_body.translation()[1] / SCALE);
        }