#define STICK_WALK_THRESHOLD 0.3 /* move the stick until the player moves */
#define STICK_ROTATE_THRESHOLD 0.3 /* move the stick until the player rotates */
-#define STICK_THRUST_THRESHOLD 0.3 /* move the stick until the craft moves */
+#define STICK_THRUST_THRESHOLD 0.1 /* move the stick until the craft moves */
static int config_ctrl_c = 0;
static int config_amiga_speed = 0; /* fast speed */
static double config_monitor_distance = 31.5; /* inch */
#ifdef HAVE_OVR
static double config_keyboard_distance = 28.5; /* inch */
-static double config_keyboard_height = 10.0; /* inch */
+static double config_keyboard_height = 4.0; /* inch */
#endif
static int config_debug_transparent = 0;
static int config_debug_opengl = 0;
}
#ifdef HAVE_OVR
-static int __attribute__((unused)) button_a_last = 0, button_b_last = 0, button_x_last = 0, button_y_last = 0, button_menu_last = 0, button_trigger_last = 0, button_left_thumb_last = 0, button_right_thumb_last = 0;
+static int __attribute__((unused)) button_a_last = 0, button_b_last = 0, button_x_last = 0, button_y_last = 0, button_menu_last = 0, button_left_trigger_last = 0, button_right_trigger_last = 0, button_left_thumb_last = 0, button_right_thumb_last = 0;
static double __attribute__((unused)) stick_left_x_last = 0.0, stick_left_y_last = 0.0, stick_right_x_last = 0.0, stick_right_y_last = 0.0;
-static int thrust_last = KEYCODE_SPACE;
+static int thrust_last = 0;
static int joystick_set_x_last = 0, joystick_set_y_last = 0;
static int keyboard_on = 0;
static enum keycode vr_key_pressed = 0, vr_key = 0;
static void handle_vr_poses(void)
{
- int button_a = 0, button_b = 0, button_x = 0, button_y = 0, button_menu = 0, button_trigger = 0, button_left_thumb = 0, button_right_thumb = 0;
+ int button_a = 0, button_b = 0, button_x = 0, button_y = 0, button_menu = 0, button_left_trigger = 0, button_right_trigger = 0, button_left_thumb = 0, button_right_thumb = 0;
double hand_right_x = 0.0, hand_right_y = 0.0, hand_right_z = 0.0;
double hand_right_yaw = 0.0, hand_right_pitch = 0.0, hand_right_roll = 0.0;
double head_yaw = 0.0, head_pitch = 0.0, head_roll = 0.0;
double stick_left_x = 0.0, stick_left_y = 0.0, stick_right_x = 0.0, stick_right_y = 0.0;
- int thrust = KEYCODE_SPACE;
+ int thrust = 0;
int joystick_set_x = 0, joystick_set_y = 0;
+ static uint32_t current_time, last_time = 0, diff;
+ static double increment, inc_count = 0.0;
- get_poses_ovr(&button_a, &button_b, &button_x, &button_y, &button_menu, &button_trigger, &button_left_thumb, &button_right_thumb, &hand_right_x, &hand_right_y, &hand_right_z, &hand_right_yaw, &hand_right_pitch, &hand_right_roll, &stick_left_x, &stick_left_y, &stick_right_x, &stick_right_y, &head_yaw, &head_pitch, &head_roll);
+ /* handle input */
+ get_poses_ovr(&button_a, &button_b, &button_x, &button_y, &button_menu, &button_left_trigger, &button_right_trigger, &button_left_thumb, &button_right_thumb, &hand_right_x, &hand_right_y, &hand_right_z, &hand_right_yaw, &hand_right_pitch, &hand_right_roll, &stick_left_x, &stick_left_y, &stick_right_x, &stick_right_y, &head_yaw, &head_pitch, &head_roll);
if (button_menu && !button_menu_last) {
/* menu toggle */
if (help_view == help_views)
set_amiga_key(KEYCODE_l, 1);
set_amiga_key(KEYCODE_l, 0);
}
- if (button_left_thumb && !button_left_thumb_last) {
- /* 'escape' pressed */
- set_amiga_key(KEYCODE_ESCAPE, 1);
- set_amiga_key(KEYCODE_ESCAPE, 0);
- }
- if (!button_left_thumb && button_left_thumb_last) {
- /* 'escape' released */
- 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) {
+ if (button_right_trigger && !button_right_trigger_last) {
/* trigger pressed */
if (!keyboard_on) {
set_joystick(-1, -1, -1, -1, 1);
set_amiga_key(vr_key_pressed, 1);
}
}
- if (!button_trigger && button_trigger_last) {
+ if (!button_right_trigger && button_right_trigger_last) {
/* trigger released */
set_joystick(-1, -1, -1, -1, 0);
if (vr_key_pressed) {
set_joystick(-1, -1, 0, 1, -1);
joystick_set_y = 1;
}
- mercenary_vr_move(0, NULL, NULL,
- 256,
- (int)(256.0 * fabs(stick_right_y) - STICK_WALK_THRESHOLD / (1.0 - STICK_WALK_THRESHOLD) + 0.5));
+ if (joystick_set_x || joystick_set_y) {
+ mercenary_vr_move(0, NULL, NULL,
+ 256,
+ (int)(256.0 * fabs(stick_right_y) - STICK_WALK_THRESHOLD / (1.0 - STICK_WALK_THRESHOLD) + 0.5));
+ }
} else {
double roll, pitch, yaw;
double dist, dir, east, north;
/* check if we push the stick */
dist = sqrt(stick_right_x * stick_right_x + stick_right_y * stick_right_y);
-//printf("dist=%.4f\n", dist);
if (dist > STICK_WALK_THRESHOLD) {
/* get stick amplitude (dist) and direction (dir) */
if (dist > 1.0)
if (dir > M_PI / 2.0 || dir < -M_PI / 2.0) {
/* go backwards */
set_joystick(-1, -1, 0, 1, -1);
+ joystick_set_y = 1;
} else {
/* go forward */
set_joystick(-1, -1, 1, 0, -1);
+ joystick_set_y = 1;
}
joystick_set_y = 1;
-printf("dir=%.4f\n", dir);
mercenary_get_orientation(&roll, &pitch, &yaw);
east = sin(yaw - dir + M_PI) * dist;
north = -cos(yaw - dir + M_PI) * dist;
if (joystick_set_y_last && !joystick_set_y)
set_joystick(-1, -1, 0, 0, -1);
/* thrust */
+ thrust = thrust_last;
+ /* button to toggle between stop and escape */
+ if (button_left_thumb && !button_left_thumb_last) {
+ /* 'escape' pressed */
+ if (thrust_last == 0)
+ thrust = -99;
+ else
+ thrust = 0;
+ }
+ /* get stick to increment or decrement thrust */
if (stick_left_y > STICK_THRUST_THRESHOLD)
- thrust = (stick_left_y - STICK_THRUST_THRESHOLD) / (1.0 - STICK_THRUST_THRESHOLD) * 10.5;
+ increment = (stick_left_y - STICK_THRUST_THRESHOLD) / (1.0 - STICK_THRUST_THRESHOLD);
else
if (stick_left_y < -STICK_THRUST_THRESHOLD)
- thrust = (stick_left_y - -STICK_THRUST_THRESHOLD) / (1.0 - -STICK_THRUST_THRESHOLD) * 10.5;
- else
- thrust = 0;
- if (thrust >= 10)
- thrust = KEYCODE_0;
- else
- if (thrust > 0)
- thrust = KEYCODE_1 + thrust - 1;
- else
- if (thrust < 0)
- thrust = KEYCODE_F1 - thrust - 1;
+ increment = (stick_left_y + STICK_THRUST_THRESHOLD) / (1.0 - STICK_THRUST_THRESHOLD);
else
- if (thrust <= -10)
- thrust = KEYCODE_F10;
- else
- thrust = KEYCODE_SPACE;
+ increment = 0;
+ current_time = ticks_sdl();
+ if (increment) {
+ diff = current_time - last_time;
+ inc_count += increment * diff;
+ if (inc_count > 150.0 && thrust >= -10 && thrust < 10) {
+ thrust++;
+ inc_count = 0.0;
+ }
+ if (inc_count < -150.0 && thrust <= 10 && thrust > -10) {
+ thrust--;
+ inc_count = 0.0;
+ }
+ } else {
+ inc_count = 0;
+ }
+ last_time = current_time;
+ /* send thrust change as keycodes */
if (thrust_last != thrust) {
- set_amiga_key(thrust, 1);
- set_amiga_key(thrust, 0);
+ if (thrust >= 10) {
+ set_amiga_key(KEYCODE_0, 1);
+ set_amiga_key(KEYCODE_0, 0);
+ } else
+ if (thrust <= -10 && thrust > -99) {
+ set_amiga_key(KEYCODE_F10, 1);
+ set_amiga_key(KEYCODE_F10, 0);
+ } else
+ if (thrust <= -99) {
+ set_amiga_key(KEYCODE_ESCAPE, 1);
+ set_amiga_key(KEYCODE_ESCAPE, 0);
+ } else
+ if (thrust > 0) {
+ set_amiga_key(KEYCODE_1 + thrust - 1, 1);
+ set_amiga_key(KEYCODE_1 + thrust - 1, 0);
+ } else
+ if (thrust < 0) {
+ set_amiga_key(KEYCODE_F1 - thrust - 1, 1);
+ set_amiga_key(KEYCODE_F1 - thrust - 1, 0);
+ } else {
+ set_amiga_key(KEYCODE_SPACE, 1);
+ set_amiga_key(KEYCODE_SPACE, 0);
+ }
}
}
button_a_last = button_a;
button_x_last = button_x;
button_y_last = button_y;
button_menu_last = button_menu;
- button_trigger_last = button_trigger;
+ button_left_trigger_last = button_left_trigger;
+ button_right_trigger_last = button_right_trigger;
button_left_thumb_last = button_left_thumb;
button_right_thumb_last = button_right_thumb;
stick_left_x_last = stick_left_x;
" Press `CTRL' + `+' or `-' to change field-of-view (OpenGL).\n"
" Press `CTRL' + `I' to skip intro (approaching to Eris).\n"
#ifdef HAVE_OVR
- " Press `CTRL' + `O' (or right trigger) to reset observer position.\n"
+ " Press `CTRL' + `O' (or both triggers) to reset observer position.\n"
#endif
"\n"
"Answer to a Question:\n"
" Press `B' button to emulate keyboard to enter alphanumeric keys.\n"
" Press `A' or `B' button again to dismiss keyboard.\n"
" Point right controller to a key on keyboard. The key will highlight.\n"
- " Press `Trigger' on right controller enter the highlighted key.\n"
+ " Pull `Trigger' on right controller enter the highlighted key.\n"
+ " Pull `Trigger' on both controllers to reset observer position.\n"
"\n"
"Walking / Driving / Flying using Controller:\n"
" Use thumb stick on right controller, to move player / craft.\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"
- " Release thumb stick on left controller stop craft.\n"
- " Press `Trigger' on right controller to fire.\n"
+ " Press thumb stick on left controller stop craft.\n"
+ " Press thumb stick on left controller for escape sequence, after stop.\n"
+ " Pull `Trigger' on right controller to fire.\n"
"\n"
"For all other game function, use the emulated keyboards!\n"
,HELP_ALPHA, 1, 2, 5, 0);