M assets/dist/spritesheet-125.json => assets/dist/spritesheet-125.json +4 -4
@@ 27,7 27,7 @@
"pivot": { "x": 32, "y": 32 },
"9slicedFrame": { "x": 0, "y": 0, "w": 64, "h": 64 }
},
- "autoplr_error.png": {
+ "hearty.png": {
"frame": { "x": 0, "y": 576, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
@@ 36,7 36,7 @@
"pivot": { "x": 32, "y": 32 },
"9slicedFrame": { "x": 0, "y": 0, "w": 64, "h": 64 }
},
- "hearty.png": {
+ "autoplr_error.png": {
"frame": { "x": 0, "y": 640, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
@@ 108,7 108,7 @@
"pivot": { "x": 32, "y": 32 },
"9slicedFrame": { "x": 0, "y": 0, "w": 64, "h": 64 }
},
- "autoplr_on.png": {
+ "powerhub_on.png": {
"frame": { "x": 0, "y": 1152, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
@@ 117,7 117,7 @@
"pivot": { "x": 32, "y": 32 },
"9slicedFrame": { "x": 0, "y": 0, "w": 64, "h": 64 }
},
- "powerhub_on.png": {
+ "autoplr_on.png": {
"frame": { "x": 0, "y": 1216, "w": 64, "h": 64 },
"rotated": false,
"trimmed": false,
M assets/dist/spritesheet-125.png => assets/dist/spritesheet-125.png +0 -0
M assets/dist/spritesheet-375.json => assets/dist/spritesheet-375.json +4 -4
@@ 27,7 27,7 @@
"pivot": { "x": 96, "y": 96 },
"9slicedFrame": { "x": 0, "y": 0, "w": 192, "h": 192 }
},
- "autoplr_error.png": {
+ "hearty.png": {
"frame": { "x": 0, "y": 1728, "w": 192, "h": 192 },
"rotated": false,
"trimmed": false,
@@ 36,7 36,7 @@
"pivot": { "x": 96, "y": 96 },
"9slicedFrame": { "x": 0, "y": 0, "w": 192, "h": 192 }
},
- "hearty.png": {
+ "autoplr_error.png": {
"frame": { "x": 0, "y": 1920, "w": 192, "h": 192 },
"rotated": false,
"trimmed": false,
@@ 108,7 108,7 @@
"pivot": { "x": 96, "y": 96 },
"9slicedFrame": { "x": 0, "y": 0, "w": 192, "h": 192 }
},
- "autoplr_on.png": {
+ "powerhub_on.png": {
"frame": { "x": 0, "y": 3456, "w": 192, "h": 192 },
"rotated": false,
"trimmed": false,
@@ 117,7 117,7 @@
"pivot": { "x": 96, "y": 96 },
"9slicedFrame": { "x": 0, "y": 0, "w": 192, "h": 192 }
},
- "powerhub_on.png": {
+ "autoplr_on.png": {
"frame": { "x": 0, "y": 3648, "w": 192, "h": 192 },
"rotated": false,
"trimmed": false,
M assets/dist/spritesheet-375.png => assets/dist/spritesheet-375.png +0 -0
M assets/dist/spritesheet-full.json => assets/dist/spritesheet-full.json +5 -5
@@ 27,7 27,7 @@
"pivot": { "x": 256, "y": 256 },
"9slicedFrame": { "x": 0, "y": 0, "w": 512, "h": 512 }
},
- "autoplr_error.png": {
+ "hearty.png": {
"frame": { "x": 2560, "y": 0, "w": 512, "h": 512 },
"rotated": false,
"trimmed": false,
@@ 36,7 36,7 @@
"pivot": { "x": 256, "y": 256 },
"9slicedFrame": { "x": 0, "y": 0, "w": 512, "h": 512 }
},
- "hearty.png": {
+ "autoplr_error.png": {
"frame": { "x": 3072, "y": 0, "w": 512, "h": 512 },
"rotated": false,
"trimmed": false,
@@ 99,7 99,7 @@
"pivot": { "x": 256, "y": 256 },
"9slicedFrame": { "x": 0, "y": 0, "w": 512, "h": 512 }
},
- "hub_on.png": {
+ "powerhub_on.png": {
"frame": { "x": 2560, "y": 1024, "w": 512, "h": 512 },
"rotated": false,
"trimmed": false,
@@ 108,7 108,7 @@
"pivot": { "x": 256, "y": 256 },
"9slicedFrame": { "x": 0, "y": 0, "w": 512, "h": 512 }
},
- "autoplr_on.png": {
+ "hub_on.png": {
"frame": { "x": 3072, "y": 1024, "w": 512, "h": 512 },
"rotated": false,
"trimmed": false,
@@ 117,7 117,7 @@
"pivot": { "x": 256, "y": 256 },
"9slicedFrame": { "x": 0, "y": 0, "w": 512, "h": 512 }
},
- "powerhub_on.png": {
+ "autoplr_on.png": {
"frame": { "x": 3584, "y": 1024, "w": 512, "h": 512 },
"rotated": false,
"trimmed": false,
M assets/dist/spritesheet-full.png => assets/dist/spritesheet-full.png +0 -0
M server/src/orbit/orbit.rs => server/src/orbit/orbit.rs +14 -3
@@ 6,10 6,9 @@ use crate::orbit::newtonian::solve_kepler_with_newtonian;
use crate::orbit::vis_viva::vis_viva;
use crate::planet::GRAVITY;
-pub fn calculate_vector_of_orbit(periapsis: f64, apoapsis: f64, t: f64, mass_of_bigger: f64) -> Vector2<f64> {
+pub fn calculate_vector_of_orbit(periapsis: f64, apoapsis: f64, t: f64, mass_of_bigger: f64, current_x_vel: f64, current_y_vel: f64, delta_t: f64, mass_of_orbiter: f64) -> Vector2<f64> {
let semi_major_length = (apoapsis + periapsis) / 2.0;
let linear_eccentricity = semi_major_length - periapsis; // distance between center and focus
- let eccentricity = linear_eccentricity / semi_major_length; // 0: circle. 1: parabola. in between: ellipse
let distances = calculate_point_on_orbit(periapsis, apoapsis, t);
let distance_x = distances[0];
@@ 20,7 19,19 @@ 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 x_vel = velocity * theta.sin();
+ let y_vel = velocity * theta.cos();
+
+ let x_accel = current_x_vel - x_vel / delta_t;
+ let y_accel = current_y_vel - y_vel / delta_t;
+
+ let x_force = mass_of_orbiter * x_accel;
+ let y_force = mass_of_orbiter * y_accel;
+
+ vector![x_force, y_force]
}
pub fn calculate_point_on_orbit(periapsis: f64, apoapsis: f64, t: f64) -> Vector2<f64> {
M server/src/timer.rs => server/src/timer.rs +5 -3
@@ 6,8 6,8 @@ use async_std::sync::RwLock;
use async_std::task::sleep;
use starkingdoms_protocol::player::Player;
use crate::{manager::{ClientHandlerMessage, ClientManager, PhysicsData}, SCALE, planet::Planets};
-use crate::orbit::constants::{GAME_ORBITS_ENABLED, MOON_APOAPSIS, MOON_ORBIT_TIME, MOON_PERIAPSIS};
-use crate::orbit::orbit::{calculate_point_on_orbit, calculate_world_position_of_orbit};
+use crate::orbit::constants::{EARTH_MASS, GAME_ORBITS_ENABLED, MOON_APOAPSIS, MOON_MASS, MOON_ORBIT_TIME, MOON_PERIAPSIS};
+use crate::orbit::orbit::{calculate_point_on_orbit, calculate_vector_of_orbit, calculate_world_position_of_orbit};
pub const ROTATIONAL_FORCE: f64 = 100.0;
pub const LATERAL_FORCE: f64 = 100.0;
@@ 35,8 35,10 @@ 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, 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);
- physics_data.rigid_body_set.get_mut(planets.get_planet_mut("moon").unwrap().body_handle).unwrap().set_position(new_moon_position.into(), true);
}
physics_data.tick(&mut pipeline);