|
|
|
|
@ -166,16 +166,23 @@ bool compare_vec3(Vec3 a, Vec3 b, double tolerance) {
|
|
|
|
|
fabs(a.z - b.z) <= tolerance; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void dump_simulation_state(SimulationState* sim, const char* label) { |
|
|
|
|
printf("\n=== %s (t=%.0f s) ===\n", label, sim->time); |
|
|
|
|
int dump_simulation_state(SimulationState* sim, const char* label, |
|
|
|
|
char* buffer, int buffer_size) { |
|
|
|
|
int offset = 0; |
|
|
|
|
|
|
|
|
|
printf("Bodies (%d):\n", sim->body_count); |
|
|
|
|
offset += snprintf(buffer + offset, buffer_size - offset, |
|
|
|
|
"\n=== %s (t=%.0f s) ===\n", label, sim->time); |
|
|
|
|
|
|
|
|
|
offset += snprintf(buffer + offset, buffer_size - offset, |
|
|
|
|
"Bodies (%d):\n", sim->body_count); |
|
|
|
|
for (int i = 0; i < sim->body_count; i++) { |
|
|
|
|
printf(" [%d] %s: mass=%.2e kg\n", |
|
|
|
|
offset += snprintf(buffer + offset, buffer_size - offset, |
|
|
|
|
" [%d] %s: mass=%.2e kg\n", |
|
|
|
|
i, sim->bodies[i].name, sim->bodies[i].mass); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printf("Spacecraft (%d):\n", sim->craft_count); |
|
|
|
|
offset += snprintf(buffer + offset, buffer_size - offset, |
|
|
|
|
"Spacecraft (%d):\n", sim->craft_count); |
|
|
|
|
for (int i = 0; i < sim->craft_count; i++) { |
|
|
|
|
Spacecraft* s = &sim->spacecraft[i]; |
|
|
|
|
double r = sqrt(s->local_position.x*s->local_position.x + |
|
|
|
|
@ -184,19 +191,28 @@ void dump_simulation_state(SimulationState* sim, const char* label) {
|
|
|
|
|
double v = sqrt(s->local_velocity.x*s->local_velocity.x + |
|
|
|
|
s->local_velocity.y*s->local_velocity.y + |
|
|
|
|
s->local_velocity.z*s->local_velocity.z); |
|
|
|
|
printf(" [%d] %s: r=%.1f v=%.1f nu=%.5f a=%.1f e=%.6f\n", |
|
|
|
|
offset += snprintf(buffer + offset, buffer_size - offset, |
|
|
|
|
" [%d] %s: r=%.1f v=%.1f nu=%.5f a=%.1f e=%.6f, omega=%.6f\n", |
|
|
|
|
i, s->name, r, v, |
|
|
|
|
s->orbit.true_anomaly, s->orbit.semi_major_axis, s->orbit.eccentricity); |
|
|
|
|
printf(" pos=(%.1f, %.1f, %.1f) vel=(%.1f, %.1f, %.1f)\n", |
|
|
|
|
s->orbit.true_anomaly, |
|
|
|
|
s->orbit.semi_major_axis, |
|
|
|
|
s->orbit.eccentricity, |
|
|
|
|
s->orbit.argument_of_periapsis); |
|
|
|
|
offset += snprintf(buffer + offset, buffer_size - offset, |
|
|
|
|
" pos=(%.1f, %.1f, %.1f) vel=(%.1f, %.1f, %.1f)\n", |
|
|
|
|
s->local_position.x, s->local_position.y, s->local_position.z, |
|
|
|
|
s->local_velocity.x, s->local_velocity.y, s->local_velocity.z); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printf("Maneuvers (%d):\n", sim->maneuver_count); |
|
|
|
|
offset += snprintf(buffer + offset, buffer_size - offset, |
|
|
|
|
"Maneuvers (%d):\n", sim->maneuver_count); |
|
|
|
|
for (int i = 0; i < sim->maneuver_count; i++) { |
|
|
|
|
Maneuver* m = &sim->maneuvers[i]; |
|
|
|
|
printf(" [%d] %s: craft=%d dir=%d dv=%.4f trigger=%d val=%.2f exec=%d\n", |
|
|
|
|
offset += snprintf(buffer + offset, buffer_size - offset, |
|
|
|
|
" [%d] %s: craft=%d dir=%d dv=%.4f trigger=%d val=%.2f exec=%d\n", |
|
|
|
|
i, m->name, m->craft_index, m->direction, m->delta_v, |
|
|
|
|
m->trigger_type, m->trigger_value, m->executed); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return offset; |
|
|
|
|
} |
|
|
|
|
|