summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs
index 12150ca..e0aa007 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -14,9 +14,25 @@ fn main() {
.add_systems(Update, update_gravitational_forces)
.run();
}
+#[derive(Component)]
+struct LunarOrbitalData {
+ period: f32,
+}
fn hello_system() {
println!("hello");
}
+fn lunar_period_to_vec(angular_pos: f32, radius: f32) -> Vec2 {
+ let x = radius * f32::cos(angular_pos);
+ let y = radius * f32::sin(angular_pos);
+ Vec2 { x, y }
+}
+fn handle_lunar_orbit(
+ time: Res<Time>,
+ mut lunar_query: Query<(&DestPlanet, &mut LunarOrbitalData, &mut Transform, &RigidBody), With<DestPlanet>>,
+) {
+ let (moon_planet, mut lod, mut moon_transform, moon_body) = lunar_query.single_mut();
+ let dt = time.delta_secs();
+}
#[derive(Component)]
struct Starship {
name: String,
@@ -61,14 +77,16 @@ fn setup_stellar_body(mut cmd: Commands) {
planet_mass_kg: 50.0,
radius: 5.0,
};
+ let lunar_radius = 900;
let r = (&objective_planet).radius;
let m = (&objective_planet).planet_mass_kg;
+ let initial_transform = lunar_period_to_vec(0., 100.);
cmd.spawn((
objective_planet,
+ LunarOrbitalData { period: 0. },
RigidBody::Dynamic,
- Transform::from_xyz(250.0, 0.0, 0.0),
+ Transform::from_xyz(initial_transform.x, initial_transform.y, 0.0),
Sprite::from_color(Color::BLACK, Vec2 { x: 30., y: 30. }),
- ExternalForce::new(Vec2 {x: 4000., y: -4000.}).with_persistence(false),
Collider::circle(30.),
Mass(m),
));
@@ -79,12 +97,13 @@ fn calculate_force_vector(
pos_actor: Vec2,
pos_incident: Vec2,
) -> Vec2 {
- let GRAV_CONST = 2.0;
+ let GRAV_CONST = 100.0;
(GRAV_CONST * mass_actor * mass_incident / (pos_actor.distance_squared(pos_incident)))
- * Vec2 {
- x: pos_actor.x - pos_incident.x,
- y: pos_actor.y - pos_incident.y,
- }
+ * Vec2 {
+ x: pos_actor.x - pos_incident.x,
+ y: pos_actor.y - pos_incident.y,
+ }
+ .normalize()
/*Vec2 {
x: pos_actor.x - pos_incident.x,
y: pos_actor.y - pos_incident.y,
@@ -108,7 +127,7 @@ fn update_gravitational_forces<'b>(
fn setup_starting_planet(mut cmd: Commands) {
let start_planet = StartPlanet {
display_name: String::from("Earth 2"),
- planet_mass_kg: 5000.0,
+ planet_mass_kg: 15000.0,
radius: 10.0,
};
let collider_radius = (&start_planet).radius;