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 bool exists; //Used by memory management
33 * Structure to represent a system of N Bodies
37 Body * bodies; //Array of Bodies
38 unsigned nMax; //Size of array; maximum number of Bodies before Array needs to be resized
39 unsigned n; //Number of bodies currently in the system
40 float G; //Universal Gravitational Constant; used to calculate forces between Bodies
42 float dt; //Time interval
43 unsigned step; //Number of steps executed by the System
45 float x[DIMENSIONS]; //The origin of the system
50 * Functions for operating with Body objects
52 extern void Body_Init(Body * body, float m, float x[DIMENSIONS], float v[DIMENSIONS]); //Initialise Body
53 extern void Body_Destroy(Body * body); //Destroy Body
54 extern void Body_Step(Body * body, System * system); //Step Body
55 extern void Body_Force(Body * A, Body * B, System * system); //Calculate Force between Bodies
59 * Functions for operating with System object
61 extern void System_Init(System * system, float x[DIMENSIONS], float dt, float G, unsigned nMax); //Initialise System
62 extern void System_Destroy(System * system); //Destroy System
63 extern void System_Step(System * system); //Step all Bodies in System
64 extern Body * System_AddBody(System * system, float m, float x[DIMENSIONS], float v[DIMENSIONS]); //Add Body to System
65 extern void System_RemoveBody(System * system, Body * body); //
66 extern void System_MergeBodies(System * system, Body * A, Body * B);
67 extern void System_WriteData(System * system, FILE * file); //Write System info to a file
71 * Functions to be used when "graphics.h" is included
75 extern void System_Draw(System * system); //Draw a System of Bodies
76 extern void Body_Draw(Body * body, System * system); //Draw an individual Body
78 extern void Process_Events(); //Handle any events from the SDL system