Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
Loading...
Searching...
No Matches
nbody.h File Reference

N-body gravitational simulation (Velocity Verlet + Plummer softening). More...

#include "nbody_types.h"
#include "sphere_types.h"
Include dependency graph for nbody.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void nbody_init_preset (NBodySim *sim)
 Initializes the simulation with a preset solar system configuration.
 
void nbody_step (NBodySim *sim, float delta_time)
 Advances the simulation by the given wall-clock delta time.
 
void nbody_update_time_scale (NBodySim *sim, float delta_time)
 Smoothly transitions time_scale toward target_time_scale.
 
void nbody_write_instances (const NBodySim *sim, SphereInstance *out)
 Writes current body positions and materials into a SphereInstance array.
 
int nbody_get_count (const NBodySim *sim)
 Returns the number of active bodies.
 
float nbody_total_energy (const NBodySim *sim)
 Computes the total energy (kinetic + gravitational potential).
 
float nbody_kinetic_energy (const NBodySim *sim)
 Computes kinetic energy only: Σ ½ m v².
 
float nbody_energy_drift (const NBodySim *sim)
 Returns the relative energy drift |E(t) - E₀| / |E₀|.
 
float nbody_energy_drift_signed (const NBodySim *sim)
 Signed energy drift.
 

Detailed Description

N-body gravitational simulation (Velocity Verlet + Plummer softening).

Manages a set of gravitational bodies with position, velocity, and mass. Uses a symplectic Velocity Verlet integrator with per-pair Plummer softening to guarantee long-term energy conservation without ad-hoc damping. Produces SphereInstance data for the instanced renderer.

See also
docs/nbody_physics.md for the full physics reference.

Function Documentation

◆ nbody_energy_drift()

float nbody_energy_drift ( const NBodySim *  sim)

Returns the relative energy drift |E(t) - E₀| / |E₀|.

◆ nbody_energy_drift_signed()

float nbody_energy_drift_signed ( const NBodySim *  sim)

Signed energy drift.

◆ nbody_get_count()

int nbody_get_count ( const NBodySim *  sim)

Returns the number of active bodies.

◆ nbody_init_preset()

void nbody_init_preset ( NBodySim *  sim)

Initializes the simulation with a preset solar system configuration.

◆ nbody_kinetic_energy()

float nbody_kinetic_energy ( const NBodySim *  sim)

Computes kinetic energy only: Σ ½ m v².

◆ nbody_step()

void nbody_step ( NBodySim *  sim,
float  delta_time 
)

Advances the simulation by the given wall-clock delta time.

◆ nbody_total_energy()

float nbody_total_energy ( const NBodySim *  sim)

Computes the total energy (kinetic + gravitational potential).

◆ nbody_update_time_scale()

void nbody_update_time_scale ( NBodySim *  sim,
float  delta_time 
)

Smoothly transitions time_scale toward target_time_scale.

◆ nbody_write_instances()

void nbody_write_instances ( const NBodySim *  sim,
SphereInstance *  out 
)

Writes current body positions and materials into a SphereInstance array.