proper gamepad control
authorJohn Tsiombikas <nuclear@mutantstargoat.com>
Thu, 17 Nov 2016 04:44:08 +0000 (06:44 +0200)
committerJohn Tsiombikas <nuclear@mutantstargoat.com>
Thu, 17 Nov 2016 04:44:08 +0000 (06:44 +0200)
src/app.cc
src/main.cc
src/opt.cc
src/opt.h

index 59c8f07..e9a4781 100644 (file)
@@ -43,7 +43,7 @@ static int prev_mx, prev_my;
 static bool bnstate[8];
 static bool keystate[256];
 static Vec2 joy_move, joy_look;
 static bool bnstate[8];
 static bool keystate[256];
 static Vec2 joy_move, joy_look;
-static float joy_deadzone = 0.1;
+static float joy_deadzone = 0.01;
 
 static Mat4 view_matrix, mouse_view_matrix, proj_matrix;
 static TextureSet texman;
 
 static Mat4 view_matrix, mouse_view_matrix, proj_matrix;
 static TextureSet texman;
@@ -96,7 +96,7 @@ bool app_init(int argc, char **argv)
        glClearColor(0.2, 0.2, 0.2, 1.0);
 
        scn = new Scene(&texman);
        glClearColor(0.2, 0.2, 0.2, 1.0);
 
        scn = new Scene(&texman);
-       if(!load_scene(scn, "data/museum.scene")) {
+       if(!load_scene(scn, opt.scenefile ? opt.scenefile : "data/museum.scene")) {
                return false;
        }
 
                return false;
        }
 
@@ -177,15 +177,17 @@ static void update(float dt)
                float len = sqrt(jmove_lensq);
                jmove_lensq -= jdeadsq;
 
                float len = sqrt(jmove_lensq);
                jmove_lensq -= jdeadsq;
 
-               dir.x += joy_move.x / len * speed;
-               dir.z += joy_move.y / len * speed;
+               float mag = len * len;
+               dir.x += mag * joy_move.x / len * 2.0 * speed;
+               dir.z += mag * joy_move.y / len * 2.0 * speed;
        }
        if(jlook_lensq > jdeadsq) {
                float len = sqrt(jlook_lensq);
                jlook_lensq -= jdeadsq;
 
        }
        if(jlook_lensq > jdeadsq) {
                float len = sqrt(jlook_lensq);
                jlook_lensq -= jdeadsq;
 
-               cam_theta += joy_look.x / len * mouse_speed * 2.0;
-               cam_phi += joy_look.y / len * mouse_speed * 1.0;
+               float mag = len * len;
+               cam_theta += mag * joy_look.x / len * 200.0 * dt;
+               cam_phi += mag * joy_look.y / len * 100.0 * dt;
                if(cam_phi < -90.0f) cam_phi = -90.0f;
                if(cam_phi > 90.0f) cam_phi = 90.0f;
        }
                if(cam_phi < -90.0f) cam_phi = -90.0f;
                if(cam_phi > 90.0f) cam_phi = 90.0f;
        }
index 58e01de..e2e969a 100644 (file)
@@ -201,7 +201,7 @@ static void process_event(SDL_Event *ev)
                break;
 
        case SDL_CONTROLLERAXISMOTION:
                break;
 
        case SDL_CONTROLLERAXISMOTION:
-               app_gamepad_axis(ev->caxis.axis, ev->caxis.value / 65535.0f);
+               app_gamepad_axis(ev->caxis.axis, ev->caxis.value / 32768.0f);
                break;
        }
 }
                break;
        }
 }
index 9226785..18d73f2 100644 (file)
@@ -9,15 +9,16 @@ Options opt;
 Options def_opt = {
        1280, 800,
        false,  // vr
 Options def_opt = {
        1280, 800,
        false,  // vr
-       false   // fullscreen
+       false,  // fullscreen
+       0               // scene file
 };
 
 enum {
        OPT_SIZE,
        OPT_VR,
 };
 
 enum {
        OPT_SIZE,
        OPT_VR,
-       OPT_SRGB,
        OPT_FULLSCREEN,
        OPT_WINDOWED,
        OPT_FULLSCREEN,
        OPT_WINDOWED,
+       OPT_SCENEFILE,
        OPT_HELP
 };
 
        OPT_HELP
 };
 
@@ -27,6 +28,7 @@ static optcfg_option options[] = {
        {0, "vr", OPT_VR, "enable VR mode"},
        {'f', "fullscreen", OPT_FULLSCREEN, "run in fullscreen mode"},
        {'w', "windowed", OPT_WINDOWED, "run in windowed mode"},
        {0, "vr", OPT_VR, "enable VR mode"},
        {'f', "fullscreen", OPT_FULLSCREEN, "run in fullscreen mode"},
        {'w', "windowed", OPT_WINDOWED, "run in windowed mode"},
+       {0, "scene", OPT_SCENEFILE, "scene file to open"},
        {'h', "help", OPT_HELP, "print usage and exit"},
        OPTCFG_OPTIONS_END
 };
        {'h', "help", OPT_HELP, "print usage and exit"},
        OPTCFG_OPTIONS_END
 };
@@ -89,6 +91,10 @@ static int opt_handler(optcfg *oc, int optid, void *cls)
                opt.fullscreen = !is_enabled(oc);
                break;
 
                opt.fullscreen = !is_enabled(oc);
                break;
 
+       case OPT_SCENEFILE:
+               opt.scenefile = strdup(optcfg_next_value(oc));
+               break;
+
        case OPT_HELP:
                printf("Usage: vrfileman [options]\nOptions:\n");
                optcfg_print_options(oc);
        case OPT_HELP:
                printf("Usage: vrfileman [options]\nOptions:\n");
                optcfg_print_options(oc);
@@ -99,6 +105,10 @@ static int opt_handler(optcfg *oc, int optid, void *cls)
 
 static int arg_handler(optcfg *oc, const char *arg, void *cls)
 {
 
 static int arg_handler(optcfg *oc, const char *arg, void *cls)
 {
-       fprintf(stderr, "unexpected argument: %s\n", arg);
-       return -1;
+       if(opt.scenefile) {
+               fprintf(stderr, "unexpected argument: %s\n", arg);
+               return -1;
+       }
+       opt.scenefile = arg;
+       return 0;
 }
 }
index 176dd61..e173545 100644 (file)
--- a/src/opt.h
+++ b/src/opt.h
@@ -5,6 +5,7 @@ struct Options {
        int width, height;
        bool vr;
        bool fullscreen;
        int width, height;
        bool vr;
        bool fullscreen;
+       const char *scenefile;
 };
 
 extern Options opt, def_opt;
 };
 
 extern Options opt, def_opt;