X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=course%2Fsemester2%2Fpprog%2Fassignment0%2Fnbody.h;h=6064584f3a9e88342eac3fce2e6b42cb38faa1bd;hb=ad9dfbfed9dcc10a3fc2671aca4ec7757d6c9023;hp=775699f0353cab22c81bb58696e4792011fd1a2b;hpb=4dad0bdf3c5058c6cc9f712f458310de74d91417;p=matches%2Fhonours.git diff --git a/course/semester2/pprog/assignment0/nbody.h b/course/semester2/pprog/assignment0/nbody.h index 775699f0..6064584f 100644 --- a/course/semester2/pprog/assignment0/nbody.h +++ b/course/semester2/pprog/assignment0/nbody.h @@ -26,7 +26,13 @@ typedef struct float v[DIMENSIONS]; //Velocity vector float F[DIMENSIONS]; //Net force due to all other bodies in the System + // Used for detecting and handling collisions + float x_old[DIMENSIONS]; //Position on previous step + float v_old[DIMENSIONS]; //Velocity on previous step + bool exists; //Used by memory management + bool collided; //Used to enforce "one collision per step" + } Body; /** @@ -34,15 +40,24 @@ typedef struct */ typedef struct { + + //--- Physical parameters --- + + float G; //Universal Gravitational Constant; used to calculate forces between Bodies + float dt; //Time interval + float cor; //Coefficient of restitution for objects in the system + + float x[DIMENSIONS]; //The origin of the system + + + //--- Memory management and simulation parameters --- + Body * bodies; //Array of Bodies unsigned nMax; //Size of array; maximum number of Bodies before Array needs to be resized unsigned n; //Number of bodies currently in the system - float G; //Universal Gravitational Constant; used to calculate forces between Bodies - - float dt; //Time interval unsigned step; //Number of steps executed by the System - float x[DIMENSIONS]; //The origin of the system + } System; @@ -50,15 +65,17 @@ typedef struct * Functions for operating with Body objects */ extern void Body_Init(Body * body, float m, float x[DIMENSIONS], float v[DIMENSIONS]); //Initialise Body -extern void Body_Destroy(Body * body); //Destroy Body +extern void Body_Destroy(Body * body, System * system); //Destroy Body extern void Body_Step(Body * body, System * system); //Step Body extern void Body_Force(Body * A, Body * B, System * system); //Calculate Force between Bodies +extern bool Body_CheckCollision(Body * A, Body * B, System * system, float * t); //Check for collision between Bodies +extern void Body_HandleCollision(Body * A, Body * B, System * system, float t); //Handle collision between Bodies /** * Functions for operating with System object */ -extern void System_Init(System * system, float x[DIMENSIONS], float dt, float G, unsigned nMax); //Initialise System +extern void System_Init(System * system, float x[DIMENSIONS], float dt, float G, float cor, unsigned nMax); //Initialise System extern void System_Destroy(System * system); //Destroy System extern void System_Step(System * system); //Step all Bodies in System extern Body * System_AddBody(System * system, float m, float x[DIMENSIONS], float v[DIMENSIONS]); //Add Body to System @@ -74,8 +91,6 @@ extern void System_WriteData(System * system, FILE * file); //Write System info #ifdef _GRAPHICS_H extern void System_Draw(System * system); //Draw a System of Bodies extern void Body_Draw(Body * body, System * system); //Draw an individual Body - - extern void Process_Events(); //Handle any events from the SDL system #endif //_GRAPHICS_H