/* * Example game universe * This universe is run after being set as "next_universe" by menu-universe * * It is supposed to contain the main gameplay implementation. * */ #include "game-universe.h" extern mjApplication App; // Global Application control variable void GameUniverse::Init() { /* Initialise objects, illumination, cameras, view and in general the start-up state of the game. */ init_cam_ctl_def(&camera); } void GameUniverse::ProcessEvent(s_event & event) { /* * Here the user input is taken into account. Game variables are altered by * the user's keystrokes, mouse movement, etc. * This method may run more than once, so update of game state * should take place until method ::Update */ if (event.quit){ SetNextUniverse(NULL); return; } switch(event.key_down){ case 'a':{ camera.dsc_ctl.fwd = 1; } break; case 'z':{ camera.dsc_ctl.backwd = 1; } break; case 'q':{ camera.dsc_ctl.spin_CCW = 1; } break; case 'w':{ camera.dsc_ctl.spin_CW = 1; } break; case ARROWUP:{ camera.dsc_ctl.spin_nosedown = 1; } break; case ARROWDOWN:{ camera.dsc_ctl.spin_noseup = 1; } break; case ARROWLEFT:{ camera.dsc_ctl.spin_left = 1; } break; case ARROWRIGHT:{ camera.dsc_ctl.spin_right = 1; } break; } switch(event.key_up){ case 'a':{ camera.dsc_ctl.fwd = 0; } break; case 'z':{ camera.dsc_ctl.backwd = 0; } break; case 'q':{ camera.dsc_ctl.spin_CCW = 0; } break; case 'w':{ camera.dsc_ctl.spin_CW = 0; } break; case ARROWUP:{ camera.dsc_ctl.spin_nosedown = 0; } break; case ARROWDOWN:{ camera.dsc_ctl.spin_noseup = 0; } break; case ARROWLEFT:{ camera.dsc_ctl.spin_left = 0; } break; case ARROWRIGHT:{ camera.dsc_ctl.spin_right = 0; } break; } } void GameUniverse::Update(float t_elapsed) { /* * In this method, the internal game state is updated * taking into account the elapsed time between the last frame * as well as the variables altered during ProcessEvent */ update_cam_auto(&camera); } void GameUniverse::Redraw(void) { /* * In this method, the internal game state is represented * on-screen. * */ glLoadIdentity(); gluLookAt(camera.pos.x, camera.pos.y, camera.pos.z, camera.pos.x+camera.dir.x, camera.pos.y+camera.dir.y, camera.pos.z+camera.dir.z, camera.dirv.x, camera.dirv.y, camera.dirv.z); } void GameUniverse::Cleanup(void) { /* * This method is run when another universe becomes active if * mustCleanup is enabled. * It should be used to free memory alocated during Init() and Update() */ }