X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=course%2Fsemester2%2Fpprog%2Fassignment1%2Fsingle-thread%2Fgraphics.c;h=e275eb5705079a57f41262aa37a7fdffa7230552;hb=f2970e1b67ccd1adff8cd04a176efdc9682adf06;hp=c3d55f524a4330445dfaa7876fdecd18856e0158;hpb=20979b1c07eda73b7f86b2fe8cb66eb58d959e04;p=matches%2Fhonours.git diff --git a/course/semester2/pprog/assignment1/single-thread/graphics.c b/course/semester2/pprog/assignment1/single-thread/graphics.c index c3d55f52..e275eb57 100644 --- 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) { + 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)"); + #elif defined BARNES_HUT + glutCreateWindow("N-Body : Barnes Hut Algorithm"); #else glutCreateWindow("N-Body"); #endif @@ -109,8 +112,13 @@ void Graphics_Run(int argc, char ** argv) //This option must be set, or when glut leaves the main loop. the exit(3) function is called... annoying glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION); - glutMainLoop(); - + + #ifndef OMP_THREADED + #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 } /** @@ -132,6 +140,7 @@ void Graphics_Display() //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; } @@ -166,12 +175,12 @@ void Graphics_Display() 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 - + glFlush(); } /** @@ -184,48 +193,51 @@ void Graphics_Keyboard(unsigned char theKey, int mouseX, int mouseY) { if (theKey == 'x' || theKey == 'X') { + QuitProgram(false); + glutLeaveMainLoop(); return; } #ifdef FLYING_CAMERA + float s = 10; 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) - 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) - 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) - 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) - 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) - eye.p[i] -= eye.z[i]; + eye.p[i] -= s * eye.z[i]; break; // Rotate camera direction "down"