X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=course%2Fsemester2%2Fpprog%2Fassignment0%2Fgraphics.c;fp=course%2Fsemester2%2Fpprog%2Fassignment0%2Fgraphics.c;h=cf2bf12ff6ef371689250951e7fa32ed54cf0379;hb=c37245b967333688ad4c2bd842e7ab5ff4d0b8ec;hp=747e39914f0011782d2c15c261cb8ae9ff5e7a5c;hpb=d4f132d40be6b93d54edca1e9af4051ec6c2d0b8;p=matches%2Fhonours.git diff --git a/course/semester2/pprog/assignment0/graphics.c b/course/semester2/pprog/assignment0/graphics.c index 747e3991..cf2bf12f 100644 --- a/course/semester2/pprog/assignment0/graphics.c +++ b/course/semester2/pprog/assignment0/graphics.c @@ -11,6 +11,9 @@ #include //For trig functions +static int screen_width = 0; +static int screen_height = 0; + /** * @function Graphics_Init * @purpose Initialise the SDL/OpenGL graphics system @@ -47,6 +50,9 @@ void Graphics_Init(const char * caption, int w, int h) glDisable(GL_DEPTH_TEST); SDL_WM_SetCaption(caption, NULL); + + screen_width = w; screen_height = h; + atexit(Graphics_Destroy); } @@ -168,3 +174,100 @@ void Graphics_Update() //SDL_Flip(screen); } +/** + * @function Process_Events + * @purpose Handle any SDL events recieved. + */ +void Process_Events() +{ + static float view_v[3] = {0,0,0}; + static float view_speed = 5.0; + static float view_scale = 1; + SDL_Event event; + + + + + while (SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_KEYDOWN: + switch (event.key.keysym.sym) + { + case SDLK_LEFT: + view_v[0] += view_speed; + break; + case SDLK_RIGHT: + view_v[0] -= view_speed; + break; + case SDLK_UP: + view_v[1] += view_speed; + break; + case SDLK_DOWN: + view_v[1] -= view_speed; + break; + case SDLK_i: + view_v[0] = 0; view_v[1] = 0; view_v[2] = 0; + view_scale = 1; + glLoadIdentity(); + break; + default: + break; + } + break; + case SDL_KEYUP: + switch (event.key.keysym.sym) + { + case SDLK_LEFT: + case SDLK_RIGHT: + view_v[0] = 0; + break; + case SDLK_UP: + case SDLK_DOWN: + view_v[1] = 0; + default: + break; + } + break; + + case SDL_MOUSEBUTTONDOWN: + { + int mouse[2]; + SDL_GetMouseState(mouse, mouse+1); + + switch (event.button.button) + { + case SDL_BUTTON_WHEELUP: + + view_scale = 1.05; + glTranslatef(screen_width/2.0, screen_height/2.0,0.0); + glScaled(view_scale, view_scale, 1); + glTranslatef(-screen_width/2.0, -screen_height/2.0, 0.0); + break; + case SDL_BUTTON_WHEELDOWN: + view_scale = 0.95; + glTranslatef(screen_width/2.0, screen_height/2.0,0.0); + glScaled(view_scale, view_scale, 1); + glTranslatef(-screen_width/2.0, -screen_height/2.0, 0.0); + break; + default: + break; + + } + + break; + } + case SDL_MOUSEBUTTONUP: + break; + case SDL_QUIT: + exit(EXIT_SUCCESS); + break; + } + } + + + glTranslatef(view_v[0], view_v[1], view_v[2]); + //SDL_Delay(1); +} +