From 2b73b0ddcef2517cf08f0d5f7fd3237804b6ecb1 Mon Sep 17 00:00:00 2001 From: Verox001 Date: Wed, 7 May 2025 13:40:48 +0200 Subject: [PATCH] Implemented radius for Bodies and added Vector3 Rendering position --- simulator/src/main.rs | 18 ++++++------------ solar_engine/src/body.rs | 4 +++- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/simulator/src/main.rs b/simulator/src/main.rs index ca22bbe..5a45838 100644 --- a/simulator/src/main.rs +++ b/simulator/src/main.rs @@ -12,12 +12,14 @@ pub async fn run() { position: Vector3::new(0.0, 0.0, 0.0), velocity: Vector3::new(0.0, 0.0, 0.0), mass: 1.989e30, + radius: 6.963e8, }); sim.add_body(Body { name: "Earth".into(), position: Vector3::new(1.496e11, 0.0, 0.0), velocity: Vector3::new(0.0, 29780.0, 0.0), mass: 5.972e24, + radius: 6.371e6, }); } @@ -47,17 +49,13 @@ pub async fn run() { let sim = simulator_clone.read().unwrap(); let bodies = &sim.bodies; - let sun_pos = Vector3::new( - (bodies[0].position[0] / 1.496e11) as f32, - (bodies[0].position[1] / 1.496e11) as f32, - 0.0, - ); + let sun_pos = (bodies[0].position / 1.496e11); - let light_offset = Vector3::new(0.0, 0.0, 0.1); + // let light_offset = Vector3::new(0.0, 0.0, 0.1); state.light_manager.clear(); state.light_manager.add_light(Light { - position: sun_pos + light_offset, + position: sun_pos.cast::().unwrap(), direction: Vector3::new(0.0, 0.0, 0.0), color: Vector3::from([1.0, 1.0, 0.8]), intensity: 5.0, @@ -72,11 +70,7 @@ pub async fn run() { .enumerate() .map(|(i, b)| { solar_engine::RenderInstance { - position: Vector3::new( - ((b.position[0] / 1.496e11) as f32) - sun_pos.x, - ((b.position[1] / 1.496e11) as f32) - sun_pos.y, - 0.0, - ), + position: ((b.position / 1.496e11) - sun_pos).cast::().unwrap(), rotation: cgmath::Quaternion::from_angle_z(cgmath::Deg(0.0)), color: match i { 0 => [1.0, 1.0, 0.0], // Sun diff --git a/solar_engine/src/body.rs b/solar_engine/src/body.rs index 5d1c23c..4c1ce9b 100644 --- a/solar_engine/src/body.rs +++ b/solar_engine/src/body.rs @@ -6,15 +6,17 @@ pub struct Body { pub mass: f64, pub position: Vector3, pub velocity: Vector3, + pub radius: f64, } impl Body { - pub fn new(name: &str, mass: f64, position: Vector3, velocity: Vector3) -> Self { + pub fn new(name: &str, mass: f64, position: Vector3, velocity: Vector3, radius: f64) -> Self { Self { name: name.to_string(), mass, position, velocity, + radius, } } } \ No newline at end of file