playable with a gamepad
[vrtris] / src / game.c
index 00f81cc..68f6a23 100644 (file)
@@ -7,13 +7,15 @@
 #include "osd.h"
 #include "opt.h"
 
+#define DEFSCR "game"
+
 static void calc_framerate(void);
 static void print_framerate(void);
 
-static float view_matrix[16], proj_matrix[16];
 static int should_swap;
 static unsigned long framerate;
 
+
 int game_init(int argc, char **argv)
 {
        if(init_opengl() == -1) {
@@ -33,10 +35,17 @@ int game_init(int argc, char **argv)
                        return -1;
                }
                goatvr_set_origin_mode(GOATVR_HEAD);
+               goatvr_set_units_scale(10.0f);
 
                goatvr_startvr();
                should_swap = goatvr_should_swap();
        }
+
+       glEnable(GL_DEPTH_TEST);
+       glEnable(GL_CULL_FACE);
+       glEnable(GL_LIGHTING);
+       glEnable(GL_LIGHT0);
+
        return 0;
 }
 
@@ -50,14 +59,6 @@ void game_cleanup()
 
 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);
 }
 
@@ -101,7 +102,7 @@ void game_display(void)
                /* 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);
+               cgm_mperspective(proj_matrix, cgm_deg_to_rad(40.0), win_aspect, 0.5, 500.0);
                glMatrixMode(GL_PROJECTION);
                glLoadMatrixf(proj_matrix);
 
@@ -147,6 +148,12 @@ void game_keyboard(int key, int pressed)
                        }
                        break;
 
+               case KEY_HOME:
+                       if(opt.flags & OPT_VR) {
+                               goatvr_recenter();
+                       }
+                       break;
+
                default:
                        break;
                }
@@ -173,10 +180,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)