Implemented radius for Bodies and added Vector3 Rendering position

This commit is contained in:
Verox001 2025-05-07 13:40:48 +02:00
parent 6d9bdae160
commit 2b73b0ddce
2 changed files with 9 additions and 13 deletions

View File

@ -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::<f32>().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::<f32>().unwrap(),
rotation: cgmath::Quaternion::from_angle_z(cgmath::Deg(0.0)),
color: match i {
0 => [1.0, 1.0, 0.0], // Sun

View File

@ -6,15 +6,17 @@ pub struct Body {
pub mass: f64,
pub position: Vector3<f64>,
pub velocity: Vector3<f64>,
pub radius: f64,
}
impl Body {
pub fn new(name: &str, mass: f64, position: Vector3<f64>, velocity: Vector3<f64>) -> Self {
pub fn new(name: &str, mass: f64, position: Vector3<f64>, velocity: Vector3<f64>, radius: f64) -> Self {
Self {
name: name.to_string(),
mass,
position,
velocity,
radius,
}
}
}