3 * @purpose Declarations for N-Body simulator
14 #include "graphics.h" //TODO: Comment out this line to build the program without any graphics at all
16 #define DIMENSIONS 2 //Number of dimensions to use in the simulation (2 or 3)
19 * Structure to represent a single Body
25 float x[DIMENSIONS]; //Position vector
26 float v[DIMENSIONS]; //Velocity vector
27 float F[DIMENSIONS]; //Net force due to all other bodies in the System
29 // Used for detecting and handling collisions
30 float x_old[DIMENSIONS]; //Position on previous step
31 float v_old[DIMENSIONS]; //Velocity on previous step
33 bool exists; //Used by memory management
34 bool collided; //Used to enforce "one collision per step"
39 * Structure to represent a system of N Bodies
44 //--- Physical parameters ---
46 float G; //Universal Gravitational Constant; used to calculate forces between Bodies
47 float dt; //Time interval
48 float cor; //Coefficient of restitution for objects in the system
50 float x[DIMENSIONS]; //The origin of the system
53 //--- Memory management and simulation parameters ---
55 Body * bodies; //Array of Bodies
56 unsigned nMax; //Size of array; maximum number of Bodies before Array needs to be resized
57 unsigned n; //Number of bodies currently in the system
58 unsigned step; //Number of steps executed by the System
65 * Functions for operating with Body objects
67 extern void Body_Init(Body * body, float m, float x[DIMENSIONS], float v[DIMENSIONS]); //Initialise Body
68 extern void Body_Destroy(Body * body, System * system); //Destroy Body
69 extern void Body_Step(Body * body, System * system); //Step Body
70 extern void Body_Force(Body * A, Body * B, System * system); //Calculate Force between Bodies
72 extern bool Body_CheckCollision(Body * A, Body * B, System * system, float * t); //Check for collision between Bodies
73 extern void Body_HandleCollision(Body * A, Body * B, System * system, float t); //Handle collision between Bodies
76 * Functions for operating with System object
78 extern void System_Init(System * system, float x[DIMENSIONS], float dt, float G, float cor, unsigned nMax); //Initialise System
79 extern void System_Destroy(System * system); //Destroy System
80 extern void System_Step(System * system); //Step all Bodies in System
81 extern Body * System_AddBody(System * system, float m, float x[DIMENSIONS], float v[DIMENSIONS]); //Add Body to System
82 extern void System_RemoveBody(System * system, Body * body); //
83 extern void System_MergeBodies(System * system, Body * A, Body * B);
84 extern void System_WriteData(System * system, FILE * file); //Write System info to a file
88 * Functions to be used when "graphics.h" is included
92 extern void System_Draw(System * system); //Draw a System of Bodies
93 extern void Body_Draw(Body * body, System * system); //Draw an individual Body