git.ucc.asn.au
/
matches
/
honours.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Parallel Programming - Final version
[matches/honours.git]
/
course
/
semester2
/
pprog
/
assignment1
/
single-thread
/
graphics.c
diff --git
a/course/semester2/pprog/assignment1/single-thread/graphics.c
b/course/semester2/pprog/assignment1/single-thread/graphics.c
index
e960ffe
..
e275eb5
100644
(file)
--- a/
course/semester2/pprog/assignment1/single-thread/graphics.c
+++ b/
course/semester2/pprog/assignment1/single-thread/graphics.c
@@
-34,6
+34,7
@@
Camera eye;
*/
void Graphics_Run(int argc, char ** argv)
{
*/
void Graphics_Run(int argc, char ** argv)
{
+
if (options.draw_graphics == false)
{
// This message is left here for when I inevitably accidentally call the function
if (options.draw_graphics == false)
{
// This message is left here for when I inevitably accidentally call the function
@@
-53,6
+54,8
@@
void Graphics_Run(int argc, char ** argv)
glutCreateWindow("N-Body : Multi-Threaded (pthread)");
#elif defined OMP_THREADED
glutCreateWindow("N-Body : Multi-Threaded (OpenMP)");
glutCreateWindow("N-Body : Multi-Threaded (pthread)");
#elif defined OMP_THREADED
glutCreateWindow("N-Body : Multi-Threaded (OpenMP)");
+ #elif defined BARNES_HUT
+ glutCreateWindow("N-Body : Barnes Hut Algorithm");
#else
glutCreateWindow("N-Body");
#endif
#else
glutCreateWindow("N-Body");
#endif
@@
-111,7
+114,10
@@
void Graphics_Run(int argc, char ** argv)
#ifndef OMP_THREADED
#ifndef OMP_THREADED
- glutMainLoop();
+ #ifndef BARNES_HUT
+ glutMainLoop(); // the mthread and single-thread versions can just start the loop here
+ // In OpenMP, because barriers have to be within the #pragma, need glutMainLoopEvent in the #pragma
+ #endif //BARNS_HUT
#endif //OMP_THREADED
}
#endif //OMP_THREADED
}
@@
-134,6
+140,7
@@
void Graphics_Display()
//Check whether the graphics thread should exit for any reason
if (ExitCondition())
{
//Check whether the graphics thread should exit for any reason
if (ExitCondition())
{
+ QuitProgram(false);
glutLeaveMainLoop(); // original glut does not have this, which makes "nicely" exiting a bit annoying
return;
}
glutLeaveMainLoop(); // original glut does not have this, which makes "nicely" exiting a bit annoying
return;
}
@@
-168,12
+175,12
@@
void Graphics_Display()
glutSolidSphere (BALL_SIZE, 10, 10);
glPopMatrix(); // restore the previous matrix
}
glutSolidSphere (BALL_SIZE, 10, 10);
glPopMatrix(); // restore the previous matrix
}
- glFlush();
+
AfterDraw(); // Stuff to do after graphics is done drawing
// Single-thread - Nothing at all
// Multiple threads - signal threads it is safe to change position variables
AfterDraw(); // Stuff to do after graphics is done drawing
// Single-thread - Nothing at all
// Multiple threads - signal threads it is safe to change position variables
-
+ glFlush();
}
/**
}
/**
@@
-193,43
+200,44
@@
void Graphics_Keyboard(unsigned char theKey, int mouseX, int mouseY)
}
#ifdef FLYING_CAMERA
}
#ifdef FLYING_CAMERA
+ float s = 10;
switch (theKey)
{
// Translate in direction of camera
case 'W':
case 'w':
for (unsigned i = 0; i < DIMENSIONS; ++i)
switch (theKey)
{
// Translate in direction of camera
case 'W':
case 'w':
for (unsigned i = 0; i < DIMENSIONS; ++i)
- eye.p[i] += eye.x[i];
+ eye.p[i] +=
s *
eye.x[i];
break;
// Translate backwards from camera direction
case 'S':
case 's':
for (unsigned i = 0; i < DIMENSIONS; ++i)
break;
// Translate backwards from camera direction
case 'S':
case 's':
for (unsigned i = 0; i < DIMENSIONS; ++i)
- eye.p[i] -= eye.x[i];
+ eye.p[i] -=
s *
eye.x[i];
break;
// Translate left from camera direction
case 'A':
case 'a':
for (unsigned i = 0; i < DIMENSIONS; ++i)
break;
// Translate left from camera direction
case 'A':
case 'a':
for (unsigned i = 0; i < DIMENSIONS; ++i)
- eye.p[i] -= eye.y[i];
+ eye.p[i] -=
s *
eye.y[i];
break;
// Translate right from camera direction
case 'D':
case 'd':
for (unsigned i = 0; i < DIMENSIONS; ++i)
break;
// Translate right from camera direction
case 'D':
case 'd':
for (unsigned i = 0; i < DIMENSIONS; ++i)
- eye.p[i] += eye.y[i];
+ eye.p[i] +=
s *
eye.y[i];
break;
// Translate up from camera direction
case 'Q':
case 'q':
for (unsigned i = 0; i < DIMENSIONS; ++i)
break;
// Translate up from camera direction
case 'Q':
case 'q':
for (unsigned i = 0; i < DIMENSIONS; ++i)
- eye.p[i] += eye.z[i];
+ eye.p[i] +=
s *
eye.z[i];
break;
// Translate down from camera direction
case 'E':
case 'e':
for (unsigned i = 0; i < DIMENSIONS; ++i)
break;
// Translate down from camera direction
case 'E':
case 'e':
for (unsigned i = 0; i < DIMENSIONS; ++i)
- eye.p[i] -= eye.z[i];
+ eye.p[i] -=
s *
eye.z[i];
break;
// Rotate camera direction "down"
break;
// Rotate camera direction "down"
UCC
git Repository :: git.ucc.asn.au