Fix
[matches/honours.git] / course / semester2 / pprog / assignment0 / main.c
1 /**
2  * @file main.c
3  * @purpose Main program for N-Body simulator (single threaded)
4  * @author Sam Moore
5  * @date August 2012
6  */
7
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <stdbool.h>
11 #include <assert.h>
12 #include <time.h>
13
14 #include "nbody.h"
15
16 int main(int argc, char ** argv)
17 {
18         srand(time(NULL));
19         System system;
20         System_Init(&system, (float[3]){320,240,0}, 1.0, 1.0, 0.4,1);
21         #ifdef _GRAPHICS_H
22                 Graphics_Init("N-Body", 640, 480);
23         #endif //_GRAPHICS_H
24
25         for (unsigned a = 0; a < 2; ++a)
26         {
27                 float m = ((float)(rand() % 100))/1000.0;
28                 float x[DIMENSIONS];
29                 float v[DIMENSIONS];
30                 for (unsigned i = 0; i < DIMENSIONS; ++i)
31                 {
32                         x[i] = (float)(rand() % 640 - 320);
33                         v[i] = (float)(rand() % 100 - 50) / 100;
34                 }
35                 System_AddBody(&system, m, x, v);
36         }
37         System_AddBody(&system, 1.0, (float[2]){0,0}, (float[2]){0,0});
38
39         while (true)
40         {
41
42                 System_Step(&system);
43                 //System_WriteData(&system, stdout);
44                 #ifdef _GRAPHICS_H
45                         Graphics_Clear(1, 1, 1); //Clear screen
46                         System_Draw(&system); //Draw system
47                         Graphics_Update(); //Update screen
48                         Process_Events(); //Process SDL events
49                 #endif //_GRAPHICS_H
50
51         }
52         System_Destroy(&system);
53         return 0;
54 }
55

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