Browse Source

review and remove the old euler integration code

main
cinnaboot 6 months ago
parent
commit
89f064b41f
  1. 37
      src/bodies.cpp
  2. 11
      src/physics.cpp
  3. 1
      src/physics.h

37
src/bodies.cpp

@ -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];

11
src/physics.cpp

@ -61,17 +61,6 @@ Vec3 calculate_acceleration(Vec3 force, double mass) {
return {0.0, 0.0, 0.0}; return {0.0, 0.0, 0.0};
} }
// [COMMENTED OLD CODE - Euler integration]
// void euler_step(CelestialBody* body, Vec3 acceleration, double dt) {
// body->velocity = vec3_add(body->velocity, vec3_scale(acceleration, dt));
// body->position = vec3_add(body->position, vec3_scale(body->velocity, dt));
// }
void euler_step(CelestialBody* body, Vec3 acceleration, double dt) {
body->velocity = vec3_add(body->velocity, vec3_scale(acceleration, dt));
body->position = vec3_add(body->position, vec3_scale(body->velocity, dt));
}
Vec3 evaluate_acceleration(Vec3 pos, Vec3 vel, AccelerationContext* ctx) { Vec3 evaluate_acceleration(Vec3 pos, Vec3 vel, AccelerationContext* ctx) {
CelestialBody temp_body = *ctx->current_body; CelestialBody temp_body = *ctx->current_body;
temp_body.position = pos; temp_body.position = pos;

1
src/physics.h

@ -23,7 +23,6 @@ Vec3 vec3_normalize(Vec3 v);
// Physics functions // Physics functions
Vec3 calculate_gravity_force(CelestialBody* body, CelestialBody* parent); Vec3 calculate_gravity_force(CelestialBody* body, CelestialBody* parent);
Vec3 calculate_acceleration(Vec3 force, double mass); Vec3 calculate_acceleration(Vec3 force, double mass);
void euler_step(CelestialBody* body, Vec3 acceleration, double dt);
// Forward declaration for RK4 context // Forward declaration for RK4 context
struct SimulationState; struct SimulationState;

Loading…
Cancel
Save