Parallel Programming - Make single threaded version
[matches/honours.git] / course / semester2 / pprog / assignment1 / graphics.c
1 /**
2  * @file graphics.c
3  * @author Sam Moore (20503628) 2012 - adapted from template program provided by UWA
4  * @pur
5
6 /*
7  * Initialization of graphics
8  */
9 void Init(void) {
10     
11         glClearColor(1.0,1.0,1.0,0.0);
12         glColor3f(0.0f, 0.0f, 0.0f);
13         glPointSize(POINT_SIZE);
14         glMatrixMode(GL_PROJECTION);
15         glLoadIdentity();
16
17         /*init lighting */
18
19         GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
20         GLfloat mat_shininess[] = { 50.0 };
21         GLfloat light_position[] = { 1.0, 1.0, 0.0, 0.0 };
22         glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
23         glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
24         glLightfv(GL_LIGHT0, GL_POSITION, light_position);
25
26     glColorMaterial(GL_FRONT,GL_DIFFUSE);                // Set Color Capability
27     
28         glEnable(GL_LIGHTING);
29         glEnable(GL_LIGHT0);
30         glEnable(GL_DEPTH_TEST);
31     
32     glEnable(GL_COLOR_MATERIAL);                       // Enable color
33
34         double displayRatio = 1.0 * WIDTH / HEIGHT;
35         windowWidth = WIDTH;
36         windowHeight = HEIGHT;
37         previousTime = clock();
38         eyeTheta = 0;
39     eyePhi = 0.5 * M_PI;
40     eyeRho = RHO;
41     upY = 1;
42         look[0] = 0;
43         look[1] = 0;
44         look[2] = 0;
45     gluPerspective(VIEW_ANGLE, displayRatio, WORLD_NEAR, WORLD_FAR);  
46 }
47
48 /*
49  * This function redraws the screen after the positions of particles 
50  * have been updated
51  */
52 void Display(void) {
53         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
54         glMatrixMode(GL_MODELVIEW);
55     glLoadIdentity();
56     gluLookAt(eyeRho * sin(eyePhi) * sin(eyeTheta), eyeRho * cos(eyePhi),
57                     eyeRho * sin(eyePhi) * cos(eyeTheta),
58                                         look[0], look[1], look[2], 0, upY, 0);
59
60         for (int i = 0; i < N; i++) {
61         //glClearColor(1.0,1.0,1.0,0.0);
62                 glColor3f(0.0f, body[i].mass/1e11*100, 0.0f);
63         //glColor3f(1.0f, 0.0f, 0.0f);
64                 glPushMatrix(); // to save the current matrix
65                 glTranslated(SCALE*body[i].X, SCALE*body[i].Y, SCALE*body[i].Z);
66                 glutSolidSphere (BALL_SIZE, 10, 10);
67                 glPopMatrix(); // restore the previous matrix
68         }
69         glFlush();
70 }

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