@ -197,33 +197,21 @@ static void compute_orbital_velocity_from_vis_viva(CelestialBody* body,
body - > velocity = vec3_add ( body - > velocity , parent - > velocity ) ;
}
// FIXME: remove this function since we're already looping in calculate_initial_velocities
static void set_child_bodies_velocity ( SimulationState * sim ) {
void calculate_initial_velocities ( SimulationState * sim ) {
for ( int i = 0 ; i < sim - > body_count ; i + + ) {
CelestialBody * body = & sim - > bodies [ i ] ;
if ( body - > parent_index = = - 1 ) {
continue ;
}
if ( body - > parent_index > = 0 & & body - > parent_index < sim - > body_count ) {
body - > velocity = { 0.0 , 0.0 , 0.0 } ;
} else if ( body - > parent_index > = 0 & & body - > parent_index < sim - > body_count ) {
CelestialBody * parent = & sim - > bodies [ body - > parent_index ] ;
compute_orbital_velocity_from_vis_viva ( body , parent ) ;
}
}
}
void calculate_initial_velocities ( SimulationState * sim ) {
for ( int i = 0 ; i < sim - > body_count ; i + + ) {
if ( sim - > bodies [ i ] . parent_index = = - 1 ) {
sim - > bodies [ i ] . velocity = { 0.0 , 0.0 , 0.0 } ;
}
}
set_child_bodies_velocity ( sim ) ;
}
// Calculate SOI radii for all bodies
// r_soi = a * (m/M)^(2/5) where a = semi-major axis, m = body mass, M = parent mass
void calculate_soi_radii ( SimulationState * sim ) {
for ( int i = 0 ; i < sim - > body_count ; i + + ) {
CelestialBody * body = & sim - > bodies [ i ] ;
@ -232,13 +220,12 @@ void calculate_soi_radii(SimulationState* sim) {
body - > soi_radius = 1e15 ;
} else if ( body - > parent_index > = 0 & & body - > parent_index < sim - > body_count ) {
CelestialBody * parent = & sim - > bodies [ body - > parent_index ] ;
update_soi ( body , parent , body - > semi_major_axis ) ;
double mass_ratio = body - > mass / parent - > mass ;
body - > soi_radius = body - > semi_major_axis * pow ( mass_ratio , 0.4 ) ;
}
}
}
// FIXME: actually all the above functions should be called inside this loop
// or the loop should be in config_loader
void initialize_local_coordinates ( SimulationState * sim ) {
for ( int i = 0 ; i < sim - > body_count ; i + + ) {
CelestialBody * body = & sim - > bodies [ i ] ;
@ -261,8 +248,6 @@ void compute_global_coordinates(SimulationState* sim) {
if ( body - > parent_index = = - 1 ) {
body - > position = body - > local_position ;
body - > velocity = body - > local_velocity ;
// FIXME: parent_index > body_count is an error in config file, we
// should either verify that in config_loader, or have an assert here
} else if ( body - > parent_index > = 0 & & body - > parent_index < sim - > body_count ) {
CelestialBody * parent = & sim - > bodies [ body - > parent_index ] ;
body - > position = vec3_add ( body - > local_position , parent - > position ) ;