added minimum turn option, to discretize turns in VR
authorJohn Tsiombikas <nuclear@member.fsf.org>
Tue, 2 Oct 2018 05:43:42 +0000 (08:43 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Tue, 2 Oct 2018 05:43:42 +0000 (08:43 +0300)
src/app.cc
src/opt.cc
src/opt.h
tools/dlldepends

index 4c6559b..eb02663 100644 (file)
@@ -64,7 +64,7 @@ static bool bnstate[8];
 static bool keystate[256];
 static bool gpad_bnstate[64];
 static Vec2 joy_move, joy_look;
-static float joy_deadzone = 0.01;
+static float joy_deadzone = 0.1;
 
 static float framerate;
 
@@ -325,7 +325,18 @@ static void update(float dt)
                jlook_lensq -= jdeadsq;
 
                float mag = len * len;
-               avatar.body_rot += mag * joy_look.x / len * 200.0 * dt;
+
+               if(opt.min_turn > 0.0f) {
+                       static long last_turn;
+                       if(len > 0.5 && time_msec - last_turn > 350) {
+                               float sign = joy_look.x > 0.0f ? 1.0f : -1.0f;
+                               avatar.body_rot += opt.min_turn * sign;
+                               last_turn = time_msec;
+                       }
+               } else {
+                       avatar.body_rot += mag * joy_look.x / len * 200.0 * dt;
+               }
+
                avatar.head_alt += mag * joy_look.y / len * 100.0 * dt;
                if(avatar.head_alt < -90.0f) avatar.head_alt = -90.0f;
                if(avatar.head_alt > 90.0f) avatar.head_alt = 90.0f;
index 7f3d4bb..15c61cc 100644 (file)
@@ -13,7 +13,8 @@ Options def_opt = {
        0,              // scene file
        true,   // music
        true,   // reflections
-       0               // data url
+       0,              // data url
+       0.0f    // minimum turn angle
 };
 
 enum {
@@ -25,6 +26,7 @@ enum {
        OPT_MUSIC,
        OPT_REFLECT,
        OPT_DATAURL,
+       OPT_MIN_TURN,
        OPT_HELP
 };
 
@@ -38,6 +40,7 @@ static optcfg_option options[] = {
        {'m', "music", OPT_MUSIC, "play background audio"},
        {'r', "reflect", OPT_REFLECT, "render reflections"},
        {0, "url", OPT_DATAURL, "data URL"},
+       {0, "minturn", OPT_MIN_TURN, "minimum turn angle"},
        {'h', "help", OPT_HELP, "print usage and exit"},
        OPTCFG_OPTIONS_END
 };
@@ -116,6 +119,19 @@ static int opt_handler(optcfg *oc, int optid, void *cls)
                opt.data_url = strdup(optcfg_next_value(oc));
                break;
 
+       case OPT_MIN_TURN:
+               {
+                       int deg;
+                       char *valstr = optcfg_next_value(oc);
+
+                       if(!valstr || sscanf(valstr, "%d", &deg) != 1) {
+                               fprintf(stderr, "minimum turn must be a number >= 0 in degrees\n");
+                               return -1;
+                       }
+                       opt.min_turn = deg;
+               }
+               break;
+
        case OPT_HELP:
                printf("Usage: demo [options]\nOptions:\n");
                optcfg_print_options(oc);
index 68a87ab..458dba0 100644 (file)
--- a/src/opt.h
+++ b/src/opt.h
@@ -9,6 +9,7 @@ struct Options {
        bool music;
        bool reflect;
        const char *data_url;
+       float min_turn;
 };
 
 extern Options opt, def_opt;
index 0535dcc..b303f77 100755 (executable)
@@ -22,4 +22,9 @@ depends() {
        done
 }
 
-depends demo.exe | sort | uniq
+file=demo.exe
+if [ -n "$1" ]; then
+       file=$1
+fi
+
+depends $file | sort | uniq