OVR: Use thumb stick to change orientation and forbid rotating when on the ground
authorAndreas Eversberg <jolly@eversberg.eu>
Sat, 28 Apr 2018 07:24:19 +0000 (09:24 +0200)
committerAndreas Eversberg <jolly@eversberg.eu>
Sat, 28 Apr 2018 07:24:19 +0000 (09:24 +0200)
src/mercenary/main.c
src/mercenary/mercenary.h
src/mercenary/mercenary2.c
src/mercenary/mercenary3.c

index 698368a..8301adb 100644 (file)
@@ -419,6 +419,12 @@ static void handle_vr_poses(void)
                        set_amiga_key(KEYCODE_SPACE, 1);
                        set_amiga_key(KEYCODE_SPACE, 0);
                }
+               if (button_right_thumb && !button_right_thumb_last) {
+                       /* 'change orientation' pressed */
+                       double roll, pitch, yaw;
+                       mercenary_get_orientation(&roll, &pitch, &yaw);
+                       mercenary_set_orientation(yaw + hand_right_yaw);
+               }
                if (button_trigger && !button_trigger_last) {
                        /* trigger pressed */
                        if (!keyboard_on) {
@@ -437,10 +443,10 @@ static void handle_vr_poses(void)
                        }
                }
                /* joystick */
-               if (stick_right_x > STICK_ROTATE_THRESHOLD)
+               if (stick_right_x > STICK_ROTATE_THRESHOLD && !mercenary_get_info_walking())
                        set_joystick(0, 1, -1, -1, -1);
                else
-               if (stick_right_x < -STICK_ROTATE_THRESHOLD)
+               if (stick_right_x < -STICK_ROTATE_THRESHOLD && !mercenary_get_info_walking())
                        set_joystick(1, 0, -1, -1, -1);
                else
                if (stick_right_x_last > STICK_ROTATE_THRESHOLD || stick_right_x_last < -STICK_ROTATE_THRESHOLD)
@@ -1325,6 +1331,8 @@ int main(int argc, char *argv[])
                "\n"
                "Walking / Driving / Flying using Controller:\n"
                "        Use thumb stick on right controller, to move player / craft.\n"
+               "        Point right controller towards the direction to walk to.\n"
+               "        Press thumb stick to change orientation to that direction.\n"
                "        Press `X' button to board, `Y' button to leave.\n"
                "        Move thumb stick on left controller to drive/fly forward or backward.\n"
                "        Press and hold thumb stick on left controller for escape sequence.\n"
index 78674d4..d8bd695 100644 (file)
@@ -84,6 +84,7 @@ uint32_t mercenary_palette_predefined(void);
 uint32_t mercenary_palette_stars(void);
 uint32_t mercenary_object_vertex_register(void);
 void mercenary_get_orientation(double *roll, double *pitch, double *yaw);
+void mercenary_set_orientation(double yaw);
 void mercenary_get_orientation_raw(int16_t *pitch, uint16_t *yaw);
 void mercenary_get_orientation_planet(double *inclination, double *azimuth, int improved);
 void mercenary_get_location(int32_t *east, int32_t *height, int32_t *north);
@@ -96,6 +97,7 @@ int mercenary_background_index(void);
 uint32_t mercenary_planet_scale_index(void);
 uint32_t mercenary_star_table(void);
 void mercenary_vr_move(int override, int32_t *east, int32_t *north, int yaw, int pitch);
+int mercenary_get_info_walking(void);
 extern const char *mercenary_name;
 extern const char *mercenary_gamesavesuffix;
 
index e1246d1..4dc9e2b 100644 (file)
@@ -31,6 +31,8 @@
 #define        INITIAL_STACK   0x7fffa
 #define RESET_VECTOR   0x59484
 
+static int info_walking = 0;
+
 /* VR heading to alter direction we walk to */
 static struct vr_move vr_move;
 
@@ -112,6 +114,10 @@ const struct cpu_stop mercenary_stop_at[] = {
        { 0x528C4,      STOP_AT_PATCH_RENDER },                 /* patch away planet check (behind observer) */
        { 0x45806,      STOP_AT_PATCH_RENDER },                 /* patch away planet rendering (would crash without check above) */
        { 0x53276,      STOP_AT_PATCH_RENDER },                 /* patch away beacon check (not visible on screen) */
+       { 0x59622,      STOP_AT_PATCH_VR },                     /* we are walking/taxi */
+       { 0x597CA,      STOP_AT_PATCH_VR },                     /* we are on a craft */
+       { 0x597F2,      STOP_AT_PATCH_VR },                     /* we are ??? */
+       { 0x59944,      STOP_AT_PATCH_VR },                     /* we are in space */
        { 0x58EA8,      STOP_AT_PATCH_VR },                     /* step that moves player on surface */
        { 0x58060,      STOP_AT_PATCH_VR },                     /* soft pitch over planet */
        { 0x58918,      STOP_AT_PATCH_VR },                     /* soft pitch in space */
@@ -196,6 +202,18 @@ void mercenary_patch_render(void)
 void mercenary_patch_vr(void)
 {
        switch (REG_PC) {
+       case 0x59622: /* we are walking/taxi */
+               info_walking = 1;
+               break;
+       case 0x597CA: /* we are on a craft */
+               info_walking = 0;
+               break;
+       case 0x597F2: /* we are ??? */
+               info_walking = 0;
+               break;
+       case 0x59944: /* we are in space */
+               info_walking = 0;
+               break;
        case 0x58EA8: /* at this point we process one step of the player walking on the ground */
                if (vr_move.override && vr_move.index < 4) {
                        REG_D[2] = vr_move.east[vr_move.index];
@@ -244,6 +262,15 @@ void mercenary_get_orientation(double *roll, double *pitch, double *yaw)
        *yaw = -(double)r / 1024.0 * 2 * M_PI;
 }
 
+void mercenary_set_orientation(double yaw)
+{
+       int16_t r;
+
+       /* set the oberver */
+       r = (int16_t)fmod(-yaw * 1024.0 / 2.0 / M_PI, 1024.0);
+       m68k_write_memory_16(0x007AC2, (r - 0x200) & 0x3ff);
+}
+
 void mercenary_get_orientation_raw(int16_t *pitch, uint16_t *yaw)
 {
        *pitch = m68k_read_memory_16(0x007AA0);
@@ -343,6 +370,11 @@ void mercenary_vr_move(int override, int32_t *east, int32_t *north, int yaw, int
        vr_move.index = 0;
 }
 
+int mercenary_get_info_walking(void)
+{
+       return info_walking;
+}
+
 const char *mercenary_name = "Mercenary II - Damocles";
 const char *mercenary_gamesavesuffix = ".m2save";
 
index 9532597..341036a 100644 (file)
@@ -37,6 +37,8 @@
 #define RESET_VECTOR   0x5a16c
 // #define RESET_VECTOR        0x5a1a4 /* strange reset vector that causes the player to fly around */
 
+static int info_walking = 0;
+
 /* VR heading to alter direction we walk to */
 static struct vr_move vr_move;
 
@@ -118,6 +120,10 @@ const struct cpu_stop mercenary_stop_at[] = {
        { 0x537B0,      STOP_AT_PATCH_RENDER },                 /* patch away planet check (behind observer) */
        { 0x45806,      STOP_AT_PATCH_RENDER },                 /* patch away planet rendering (would crash without check above) */
        { 0x5406E,      STOP_AT_PATCH_RENDER },                 /* patch away beacon check (not visible on screen) */
+       { 0x5A3BA,      STOP_AT_PATCH_VR },                     /* we are walking/taxi */
+       { 0x5A576,      STOP_AT_PATCH_VR },                     /* we are on a craft */
+       { 0x5A5A4,      STOP_AT_PATCH_VR },                     /* we are ??? */
+       { 0x5A71A,      STOP_AT_PATCH_VR },                     /* we are in space */
        { 0x59A00,      STOP_AT_PATCH_VR },                     /* step that moves player on surface */
        { 0x58F44,      STOP_AT_PATCH_VR },                     /* soft pitch over planet */
        { 0x5946E,      STOP_AT_PATCH_VR },                     /* soft pitch in space */
@@ -232,6 +238,18 @@ void mercenary_patch_render(void)
 void mercenary_patch_vr(void)
 {
        switch (REG_PC) {
+       case 0x5A3BA: /* we are walking/taxi */
+               info_walking = 1;
+               break;
+       case 0x5A576: /* we are on a craft */
+               info_walking = 0;
+               break;
+       case 0x5A5A4: /* we are ??? */
+               info_walking = 0;
+               break;
+       case 0x5A71A: /* we are in space */
+               info_walking = 0;
+               break;
        case 0x59A00: /* at this point we process one step of the player walking on the ground */
                if (vr_move.override && vr_move.index < 4) {
                        REG_D[2] = vr_move.east[vr_move.index];
@@ -290,6 +308,15 @@ void mercenary_get_orientation(double *roll, double *pitch, double *yaw)
        *yaw = -(double)r / 1024.0 * 2 * M_PI;
 }
 
+void mercenary_set_orientation(double yaw)
+{
+       int16_t r;
+
+       /* set the oberver */
+       r = (int16_t)fmod(-yaw * 1024.0 / 2.0 / M_PI, 1024.0);
+       m68k_write_memory_16(DS_0+0x1E4a, (r - 0x200) & 0x3ff);
+}
+
 void mercenary_get_orientation_raw(int16_t *pitch, uint16_t *yaw)
 {
        *pitch = m68k_read_memory_16(DS_0+0x1E28);
@@ -390,6 +417,11 @@ void mercenary_vr_move(int override, int32_t *east, int32_t *north, int yaw, int
        vr_move.index = 0;
 }
 
+int mercenary_get_info_walking(void)
+{
+       return info_walking;
+}
+
 const char *mercenary_name = "Mercenary III - The Dion Crisis";
 const char *mercenary_gamesavesuffix = ".m3save";