|
|
|
@ -99,43 +99,6 @@ void update_soi(CelestialBody* body, CelestialBody* parent, double semi_major_ax |
|
|
|
body->soi_radius = semi_major_axis * pow(mass_ratio, 0.4); // 2/5 = 0.4
|
|
|
|
body->soi_radius = semi_major_axis * pow(mass_ratio, 0.4); // 2/5 = 0.4
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// [COMMENTED OLD CODE - Two-phase Euler update]
|
|
|
|
|
|
|
|
// void update_simulation(SimulationState* sim) {
|
|
|
|
|
|
|
|
// for (int i = 0; i < sim->body_count; i++) {
|
|
|
|
|
|
|
|
// CelestialBody* body = &sim->bodies[i];
|
|
|
|
|
|
|
|
// if (body->parent_index == -1) {
|
|
|
|
|
|
|
|
// Vec3 total_force = {0.0, 0.0, 0.0};
|
|
|
|
|
|
|
|
// for (int j = 0; j < sim->body_count; j++) {
|
|
|
|
|
|
|
|
// if (i == j) continue;
|
|
|
|
|
|
|
|
// CelestialBody* other = &sim->bodies[j];
|
|
|
|
|
|
|
|
// if (other->parent_index == -1) {
|
|
|
|
|
|
|
|
// Vec3 force = calculate_gravity_force(body, other);
|
|
|
|
|
|
|
|
// total_force = vec3_add(total_force, force);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// Vec3 acceleration = calculate_acceleration(total_force, body->mass);
|
|
|
|
|
|
|
|
// euler_step(body, acceleration, sim->dt);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// for (int i = 0; i < sim->body_count; i++) {
|
|
|
|
|
|
|
|
// CelestialBody* body = &sim->bodies[i];
|
|
|
|
|
|
|
|
// if (body->parent_index == -1) {
|
|
|
|
|
|
|
|
// continue;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// int new_parent = find_dominant_body(sim, i);
|
|
|
|
|
|
|
|
// if (new_parent != body->parent_index && new_parent != -1) {
|
|
|
|
|
|
|
|
// body->parent_index = new_parent;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (body->parent_index >= 0 && body->parent_index < sim->body_count) {
|
|
|
|
|
|
|
|
// CelestialBody* parent = &sim->bodies[body->parent_index];
|
|
|
|
|
|
|
|
// Vec3 force = calculate_gravity_force(body, parent);
|
|
|
|
|
|
|
|
// Vec3 acceleration = calculate_acceleration(force, body->mass);
|
|
|
|
|
|
|
|
// euler_step(body, acceleration, sim->dt);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// sim->time += sim->dt;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void update_simulation(SimulationState* sim) { |
|
|
|
void update_simulation(SimulationState* sim) { |
|
|
|
for (int i = 0; i < sim->body_count; i++) { |
|
|
|
for (int i = 0; i < sim->body_count; i++) { |
|
|
|
CelestialBody* body = &sim->bodies[i]; |
|
|
|
CelestialBody* body = &sim->bodies[i]; |
|
|
|
|