$darkmode
#include "nbody.h"#include "dvec3.h"#include "utils.h"#include <cglm/affine.h>#include <cglm/mat4.h>#include <cglm/vec3.h>#include <math.h>Data Structures | |
| struct | OrbiterDef |
Functions | |
| static void | add_body (NBodySim *sim, const double pos[3], const double vel[3], double mass, float radius, const vec3 albedo, float metallic, float roughness) |
| static double | pair_softening_sq (double radius_i, double radius_j) |
| static double | softened_orbital_vel (double grav, double central_mass, double orbit_r, double star_r, double body_r) |
| void | nbody_init_preset (NBodySim *sim) |
| Initializes the simulation with a preset solar system configuration. More... | |
| float | nbody_total_energy (const NBodySim *sim) |
| Computes the total energy (kinetic + gravitational potential). More... | |
| static void | compute_accelerations (const NBodySim *sim, double accel[][3]) |
| static void | integrate_step (NBodySim *sim, float delta_time) |
| void | nbody_step (NBodySim *sim, float delta_time) |
| Advances the simulation by the given wall-clock delta time. More... | |
| void | nbody_write_instances (const NBodySim *sim, SphereInstance *out) |
| Writes current body positions and materials into a SphereInstance array suitable for the instanced rendering pipeline. More... | |
| int | nbody_get_count (const NBodySim *sim) |
| Returns the number of active bodies. More... | |
| float | nbody_kinetic_energy (const NBodySim *sim) |
| Computes kinetic energy only: Σ ½ m v². More... | |
| float | nbody_energy_drift (const NBodySim *sim) |
| Returns the relative energy drift |E(t) - E₀| / |E₀|. More... | |
| float | nbody_energy_drift_signed (const NBodySim *sim) |
| void | nbody_update_time_scale (NBodySim *sim, float delta_time) |
| Smoothly transitions time_scale toward target_time_scale. More... | |
Variables | |
| static const float | EPSILON = 1e-6F |
| static const double | MIN_DIST = 1e-9 |
| static const double | CENTRAL_STAR_MASS = 100.0 |
| static const float | CENTRAL_STAR_RADIUS = 1.5F |
| static const vec3 | CENTRAL_STAR_ALBEDO = {1.0F, 0.76F, 0.34F} |
| static const float | CENTRAL_STAR_METALLIC = 1.0F |
| static const float | CENTRAL_STAR_ROUGHNESS = 0.2F |
| static const double | HALF = 0.5 |
| static const struct OrbiterDef | ORBITERS [] |
| static const int | ORBITER_COUNT = (int)(sizeof(ORBITERS) / sizeof(ORBITERS[0])) |
|
static |
|
static |
|
static |
| float nbody_energy_drift | ( | const NBodySim * | sim | ) |
Returns the relative energy drift |E(t) - E₀| / |E₀|.
Returns 0 when initial_energy is zero (no reference).
| float nbody_energy_drift_signed | ( | const NBodySim * | sim | ) |
Signed energy drift: negative = energy lost (damping), positive = energy gained (divergence).
| int nbody_get_count | ( | const NBodySim * | sim | ) |
Returns the number of active bodies.
| void nbody_init_preset | ( | NBodySim * | sim | ) |
Initializes the simulation with a preset solar system configuration.
| sim | Pointer to the simulation state. |
| float nbody_kinetic_energy | ( | const NBodySim * | sim | ) |
Computes kinetic energy only: Σ ½ m v².
| void nbody_step | ( | NBodySim * | sim, |
| float | delta_time | ||
| ) |
Advances the simulation by the given wall-clock delta time.
Uses a fixed-timestep accumulator with Velocity Verlet integration.
| sim | Pointer to the simulation state. |
| delta_time | Wall-clock time elapsed since last call (seconds). |
| float nbody_total_energy | ( | const NBodySim * | sim | ) |
Computes the total energy (kinetic + gravitational potential).
Useful for stability diagnostics. With a symplectic integrator, this quantity oscillates with bounded amplitude around E₀.
| void nbody_update_time_scale | ( | NBodySim * | sim, |
| float | delta_time | ||
| ) |
Smoothly transitions time_scale toward target_time_scale.
Called once per frame. Ramps at NBODY_TIME_SCALE_RATE units/s, producing a decelerate → pause → accelerate-in-reverse effect.
| sim | Pointer to the simulation state. |
| delta_time | Wall-clock frame delta (seconds). |
| void nbody_write_instances | ( | const NBodySim * | sim, |
| SphereInstance * | out | ||
| ) |
Writes current body positions and materials into a SphereInstance array suitable for the instanced rendering pipeline.
| sim | Pointer to the simulation state. |
| out | Output array (must have capacity >= sim->body_count). |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Small epsilon to avoid division by zero.
|
static |
|
static |
Minimum distance threshold to avoid division by near-zero.
|
static |