vibe coding an orbital mechanics simulation to try out claude code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

78 lines
2.3 KiB

#ifndef BODIES_H
#define BODIES_H
#include "physics.h"
#include "orbital_mechanics.h"
struct Spacecraft;
struct Maneuver;
// Celestial body structure
struct CelestialBody {
char name[64];
double mass; // kg
double radius; // meters
int parent_index; // index of gravitational parent (-1 for root body like Sun)
float color[3]; // RGB color for rendering
// Orbital elements from config (Keplerian elements)
OrbitalElements orbit;
// Global frame (from origin)
Vec3 global_position; // meters from origin
Vec3 global_velocity; // m/s
// Local frame (relative to parent)
Vec3 local_position; // meters from parent
Vec3 local_velocity; // m/s relative to parent
double soi_radius; // sphere of influence radius (meters)
};
// Simulation state
struct SimulationState {
CelestialBody* bodies;
int body_count;
int max_bodies;
Spacecraft* spacecraft;
int craft_count;
int max_craft;
Maneuver* maneuvers;
int maneuver_count;
int max_maneuvers;
double time;
double dt;
char config_name[256];
};
// Simulation management functions
SimulationState* create_simulation(int max_bodies, int max_craft, int max_maneuvers, double time_step);
void destroy_simulation(SimulationState* sim);
// Dynamic body management
int add_body_to_simulation(SimulationState* sim, CelestialBody* body);
int add_spacecraft(SimulationState* sim, Spacecraft* craft);
// SOI and simulation update functions
int find_dominant_body(SimulationState* sim, int body_index);
void update_soi(CelestialBody* body, CelestialBody* parent, double semi_major_axis);
void update_simulation(SimulationState* sim);
double calculate_soi_radius(CelestialBody* body, CelestialBody* parent);
void compute_global_coordinates(SimulationState* sim);
// FIXME: don't need to be interface functions
// Simulation update helper functions
void update_bodies_physics(SimulationState* sim);
void update_spacecraft_physics(SimulationState* sim);
void execute_pending_maneuvers(SimulationState* sim);
void compute_spacecraft_globals(SimulationState* sim);
// Initialize orbital objects from orbital elements
// Converts orbital elements to local position/velocity and computes global coordinates
void initialize_orbital_objects(SimulationState* sim);
#endif