Merge branch 'master' of git.ucc.asn.au:/matches/honours
[matches/honours.git] / course / semester2 / pprog / assignment0 / nbody.h
index 775699f..6064584 100644 (file)
@@ -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
 
 

UCC git Repository :: git.ucc.asn.au