From: John Tsiombikas Date: Thu, 17 Nov 2016 04:44:08 +0000 (+0200) Subject: proper gamepad control X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=laserbrain_demo;a=commitdiff_plain;h=9802d969be55668e4dcc10fe427b0dcdeb6302be proper gamepad control --- diff --git a/src/app.cc b/src/app.cc index 59c8f07..e9a4781 100644 --- a/src/app.cc +++ b/src/app.cc @@ -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 float joy_deadzone = 0.1; +static float joy_deadzone = 0.01; 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); - if(!load_scene(scn, "data/museum.scene")) { + if(!load_scene(scn, opt.scenefile ? opt.scenefile : "data/museum.scene")) { return false; } @@ -177,15 +177,17 @@ static void update(float dt) 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; - 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; } diff --git a/src/main.cc b/src/main.cc index 58e01de..e2e969a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -201,7 +201,7 @@ static void process_event(SDL_Event *ev) 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; } } diff --git a/src/opt.cc b/src/opt.cc index 9226785..18d73f2 100644 --- a/src/opt.cc +++ b/src/opt.cc @@ -9,15 +9,16 @@ Options opt; Options def_opt = { 1280, 800, false, // vr - false // fullscreen + false, // fullscreen + 0 // scene file }; enum { OPT_SIZE, OPT_VR, - OPT_SRGB, OPT_FULLSCREEN, OPT_WINDOWED, + OPT_SCENEFILE, 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, "scene", OPT_SCENEFILE, "scene file to open"}, {'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; + case OPT_SCENEFILE: + opt.scenefile = strdup(optcfg_next_value(oc)); + break; + 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) { - 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; } diff --git a/src/opt.h b/src/opt.h index 176dd61..e173545 100644 --- a/src/opt.h +++ b/src/opt.h @@ -5,6 +5,7 @@ struct Options { int width, height; bool vr; bool fullscreen; + const char *scenefile; }; extern Options opt, def_opt;