X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fgame.c;h=2df0e3f9d4e2afc280059499abcd8b5f4b59a0d7;hb=e785b2f83fd3aba82cb07ca5dd8d590d817d376c;hp=a729996e88130bf624e7bbafd4c63d62e714f995;hpb=e09f58ce22aa16e6fc68347b70c2be6a864f25b3;p=vrtris diff --git a/src/game.c b/src/game.c index a729996..2df0e3f 100644 --- a/src/game.c +++ b/src/game.c @@ -1,5 +1,7 @@ #include +#ifdef BUILD_VR #include +#endif #include #include "opengl.h" #include "game.h" @@ -12,10 +14,12 @@ static void calc_framerate(void); static void print_framerate(void); -float view_matrix[16], proj_matrix[16]; +#ifdef BUILD_VR static int should_swap; +#endif static unsigned long framerate; + int game_init(int argc, char **argv) { if(init_opengl() == -1) { @@ -30,6 +34,7 @@ int game_init(int argc, char **argv) return -1; } +#ifdef BUILD_VR if(opt.flags & OPT_VR) { if(goatvr_init() == -1) { return -1; @@ -39,44 +44,46 @@ int game_init(int argc, char **argv) goatvr_startvr(); should_swap = goatvr_should_swap(); } +#endif /* BUILD_VR */ + + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + screen->start(); return 0; } void game_cleanup() { +#ifdef BUILD_VR if(opt.flags & OPT_VR) { goatvr_shutdown(); } +#endif cleanup_screens(); } static void update(float dt) { - int num_vr_sticks; - - if((num_vr_sticks = goatvr_num_sticks()) > 0) { - float p[2]; - goatvr_stick_pos(0, p); - /* TODO */ - } - screen->update(dt); } void game_display(void) { static long prev_msec; - int i; float dt = (float)(time_msec - prev_msec) / 1000.0f; prev_msec = time_msec; - update(dt); - +#ifdef BUILD_VR if(opt.flags & OPT_VR) { + int i; goatvr_draw_start(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + update(dt); + for(i=0; i<2; i++) { /* for each eye */ goatvr_draw_eye(i); @@ -100,11 +107,15 @@ void game_display(void) game_swap_buffers(); } - } else { + } else +#endif /* BUILD_VR */ + { /* non-VR mode */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - cgm_mperspective(proj_matrix, cgm_deg_to_rad(50.0), win_aspect, 0.5, 500.0); + update(dt); + + cgm_mperspective(proj_matrix, cgm_deg_to_rad(40.0), win_aspect, 0.5, 500.0); glMatrixMode(GL_PROJECTION); glLoadMatrixf(proj_matrix); @@ -127,7 +138,9 @@ void game_display(void) void game_reshape(int x, int y) { glViewport(0, 0, x, y); +#ifdef BUILD_VR goatvr_set_fb_size(x, y, 1.0f); +#endif reshape_screens(x, y); } @@ -150,6 +163,14 @@ void game_keyboard(int key, int pressed) } break; + case KEY_HOME: +#ifdef BUILD_VR + if(opt.flags & OPT_VR) { + goatvr_recenter(); + } +#endif + break; + default: break; } @@ -176,10 +197,16 @@ void game_mouse_wheel(int dir) void game_gamepad_axis(int axis, float val) { + joy_axis[axis] = val; } void game_gamepad_button(int bn, int pressed) { + if(pressed) { + joy_bnstate |= (1 << bn); + } else { + joy_bnstate &= ~(1 << bn); + } } static void calc_framerate(void)