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=e960ffe6e44b449b16eee724c01828ffff738f83;hpb=bb7fa31ea517a1fba064e723b37d5b8d8bd7dd72;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 e960ffe6..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 @@ -111,7 +114,10 @@ void Graphics_Run(int argc, char ** argv) #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 } @@ -134,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; } @@ -168,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(); } /** @@ -193,43 +200,44 @@ void Graphics_Keyboard(unsigned char theKey, int mouseX, int mouseY) } #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"