nuclear@0: #include "scr_game.h" nuclear@0: #include "object.h" nuclear@0: #include "game.h" nuclear@0: #include "meshgen.h" nuclear@0: #include "opengl.h" nuclear@0: #include "unistate.h" nuclear@0: #include "logger.h" nuclear@0: #include "level.h" nuclear@0: nuclear@0: static int win_width, win_height; nuclear@0: static bool bnstate[32]; nuclear@0: static int prev_x, prev_y; nuclear@1: static float cam_theta, cam_phi = 23, cam_dist = 0; nuclear@0: static Object *floor_obj; nuclear@0: static Level *level; nuclear@1: static unsigned long msec; nuclear@0: nuclear@0: const char *GameScreen::get_name() const nuclear@0: { nuclear@0: return "game"; nuclear@0: } nuclear@0: nuclear@0: bool GameScreen::init() nuclear@0: { nuclear@0: glEnable(GL_LIGHTING); nuclear@0: glEnable(GL_LIGHT0); nuclear@0: nuclear@0: level = new Level; nuclear@0: nuclear@0: return true; nuclear@0: } nuclear@0: nuclear@0: void GameScreen::cleanup() nuclear@0: { nuclear@0: } nuclear@0: nuclear@0: void GameScreen::update(unsigned long tmsec) nuclear@0: { nuclear@1: msec = tmsec; nuclear@0: } nuclear@0: nuclear@0: void GameScreen::display() const nuclear@0: { nuclear@0: Matrix4x4 matrix; nuclear@0: matrix.translate(Vector3(0, 0, -cam_dist)); nuclear@0: matrix.rotate(Vector3(1, 0, 0), DEG_TO_RAD(cam_phi)); nuclear@0: matrix.rotate(Vector3(0, 1, 0), DEG_TO_RAD(cam_theta)); nuclear@1: matrix.translate(Vector3(0, -2, 0)); nuclear@0: set_view_matrix(matrix); nuclear@0: nuclear@0: //glUseProgram(0); nuclear@0: nuclear@0: bind_shader(defsdr); nuclear@1: level->draw(msec); nuclear@0: } nuclear@0: nuclear@0: void GameScreen::reshape(int x, int y) nuclear@0: { nuclear@0: glViewport(0, 0, x, y); nuclear@0: nuclear@0: win_width = x; nuclear@0: win_height = y; nuclear@0: nuclear@0: Matrix4x4 proj; nuclear@0: proj.set_perspective(M_PI / 4.0, (float)x / (float)y, 0.5, 500.0); nuclear@0: set_projection_matrix(proj); nuclear@0: } nuclear@0: nuclear@0: void GameScreen::button(int bn, bool pressed, int x, int y) nuclear@0: { nuclear@0: prev_x = x; nuclear@0: prev_y = y; nuclear@0: bnstate[bn] = pressed; nuclear@0: } nuclear@0: nuclear@0: void GameScreen::motion(int x, int y, bool pressed) nuclear@0: { nuclear@0: int dx = x - prev_x; nuclear@0: int dy = y - prev_y; nuclear@0: prev_x = x; nuclear@0: prev_y = y; nuclear@0: nuclear@0: if(!dx && !dy) return; nuclear@0: nuclear@0: if(bnstate[0]) { nuclear@0: cam_theta += dx * 0.5; nuclear@0: cam_phi += dy * 0.5; nuclear@0: nuclear@0: if(cam_phi > 90) cam_phi = 90; nuclear@0: if(cam_phi < 0) cam_phi = 0; nuclear@0: } nuclear@0: nuclear@0: if(bnstate[2]) { nuclear@0: cam_dist += dy * 0.1; nuclear@0: nuclear@0: if(cam_dist < 0) cam_dist = 0; nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: long GameScreen::redisplay_interval() const nuclear@0: { nuclear@0: return 1; nuclear@0: }