|
|
|
|
@ -77,6 +77,7 @@ Vec3 evaluate_acceleration(Vec3 pos, Vec3 vel, AccelerationContext* ctx) {
|
|
|
|
|
|
|
|
|
|
Vec3 total_force = {0.0, 0.0, 0.0}; |
|
|
|
|
|
|
|
|
|
// FIXME: we shouldn't be simulating root bodies anymore
|
|
|
|
|
if (temp_body.parent_index == -1) { |
|
|
|
|
for (int j = 0; j < ctx->sim->body_count; j++) { |
|
|
|
|
if (j == ctx->body_index) continue; |
|
|
|
|
@ -89,12 +90,12 @@ Vec3 evaluate_acceleration(Vec3 pos, Vec3 vel, AccelerationContext* ctx) {
|
|
|
|
|
} else { |
|
|
|
|
if (temp_body.parent_index >= 0 && temp_body.parent_index < ctx->sim->body_count) { |
|
|
|
|
CelestialBody* parent = &ctx->sim->bodies[temp_body.parent_index]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double distance = vec3_magnitude(pos); |
|
|
|
|
if (distance < 1.0) { |
|
|
|
|
distance = 1.0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double force_magnitude = G * temp_body.mass * parent->mass / (distance * distance); |
|
|
|
|
Vec3 direction = vec3_normalize(vec3_scale(pos, -1.0)); |
|
|
|
|
total_force = vec3_scale(direction, force_magnitude); |
|
|
|
|
|