Auto-close HMD weapon selector if triggered by thumbstick axis

This commit is contained in:
Petr Bartos 2022-03-13 14:24:46 +01:00
parent b451a6f7d2
commit e49ae98fd3
3 changed files with 67 additions and 53 deletions

View file

@ -2355,6 +2355,18 @@ void CG_DrawWeaponSelector( void )
{
cg.weaponSelectorSelection = WP_NONE;
}
// In case HMD weapon selector was invoked by thumbstick axis, thumbstick
// is centered select weapon (if any selected) and close the selector
if (selectorMode == WS_HMD && vr->weapon_select_autoclose && frac > 0.25f) {
if (x > -0.1f && x < 0.1f && y > -0.1f && y < 0.1f) {
if (selected) {
cg.weaponSelect = cg.weaponSelectorSelection;
}
vr->weapon_select = qfalse;
vr->weapon_select_autoclose = qfalse;
}
}
}
/*

View file

@ -18,6 +18,7 @@ typedef struct {
qboolean local_server; // used in bg_pmove.c
vrFollowMode_t follow_mode;
qboolean weapon_select;
qboolean weapon_select_autoclose;
qboolean smooth_turning;
int realign; // used to realign the fake 6DoF playspace in a multiplayer game

View file

@ -243,7 +243,7 @@ static void VR_processHaptics() {
}
}
static void IN_SendButtonAction(const char* action, qboolean pressed)
static void IN_SendButtonAction(const char* action, qboolean pressed, qboolean isThumbstickAxis)
{
if (action)
{
@ -265,6 +265,7 @@ static void IN_SendButtonAction(const char* action, qboolean pressed)
else if (strcmp(action, "+weapon_select") == 0)
{
vr.weapon_select = pressed;
vr.weapon_select_autoclose = isThumbstickAxis;
if (!pressed)
{
Cbuf_AddText("weapon_select");
@ -526,11 +527,11 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
// stop left & right
vr.smooth_turning = false;
if ((controller->axisButtons & VR_TOUCH_AXIS_LEFT) && IN_GetButtonAction("RTHUMBLEFT", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_LEFT;
if ((controller->axisButtons & VR_TOUCH_AXIS_RIGHT) && IN_GetButtonAction("RTHUMBRIGHT", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_RIGHT;
@ -538,19 +539,19 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
if (joystickX < -releasedThreshold) {
// stop up
if ((controller->axisButtons & VR_TOUCH_AXIS_UP) && IN_GetButtonAction("RTHUMBFORWARD", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_UP;
// stop up-right
if ((controller->axisButtons & VR_TOUCH_AXIS_UPRIGHT) && IN_GetButtonAction("RTHUMBFORWARDRIGHT", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_UPRIGHT;
// start up-left
if (!(controller->axisButtons & VR_TOUCH_AXIS_UPLEFT)) {
controller->axisButtons |= VR_TOUCH_AXIS_UPLEFT;
if (IN_GetButtonAction("RTHUMBFORWARDLEFT", action)) {
IN_SendButtonAction(action, qtrue);
IN_SendButtonAction(action, qtrue, qtrue);
}
}
@ -558,19 +559,19 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
} else if (joystickX > releasedThreshold) {
// stop up
if ((controller->axisButtons & VR_TOUCH_AXIS_UP) && IN_GetButtonAction("RTHUMBFORWARD", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_UP;
// stop up-left
if ((controller->axisButtons & VR_TOUCH_AXIS_UPLEFT) && IN_GetButtonAction("RTHUMBFORWARDLEFT", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_UPLEFT;
// start up-right
if (!(controller->axisButtons & VR_TOUCH_AXIS_UPRIGHT)) {
controller->axisButtons |= VR_TOUCH_AXIS_UPRIGHT;
if (IN_GetButtonAction("RTHUMBFORWARDRIGHT", action)) {
IN_SendButtonAction(action, qtrue);
IN_SendButtonAction(action, qtrue, qtrue);
}
}
@ -578,19 +579,19 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
} else {
// stop up-left
if ((controller->axisButtons & VR_TOUCH_AXIS_UPLEFT) && IN_GetButtonAction("RTHUMBFORWARDLEFT", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_UPLEFT;
// stop up-right
if ((controller->axisButtons & VR_TOUCH_AXIS_UPRIGHT) && IN_GetButtonAction("RTHUMBFORWARDRIGHT", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_UPRIGHT;
// start up
if (!(controller->axisButtons & VR_TOUCH_AXIS_UP) && joystickY > pressedThreshold) {
controller->axisButtons |= VR_TOUCH_AXIS_UP;
if (IN_GetButtonAction("RTHUMBFORWARD", action)) {
IN_SendButtonAction(action, qtrue);
IN_SendButtonAction(action, qtrue, qtrue);
}
}
}
@ -601,11 +602,11 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
// stop left & right
vr.smooth_turning = false;
if ((controller->axisButtons & VR_TOUCH_AXIS_LEFT) && IN_GetButtonAction("RTHUMBLEFT", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_LEFT;
if ((controller->axisButtons & VR_TOUCH_AXIS_RIGHT) && IN_GetButtonAction("RTHUMBRIGHT", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_RIGHT;
@ -613,19 +614,19 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
if (joystickX < -releasedThreshold) {
// stop down
if ((controller->axisButtons & VR_TOUCH_AXIS_DOWN) && IN_GetButtonAction("RTHUMBBACK", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_DOWN;
// stop down-right
if ((controller->axisButtons & VR_TOUCH_AXIS_DOWNRIGHT) && IN_GetButtonAction("RTHUMBBACKRIGHT", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_DOWNRIGHT;
// start down-left
if (!(controller->axisButtons & VR_TOUCH_AXIS_DOWNLEFT)) {
controller->axisButtons |= VR_TOUCH_AXIS_DOWNLEFT;
if (IN_GetButtonAction("RTHUMBBACKLEFT", action)) {
IN_SendButtonAction(action, qtrue);
IN_SendButtonAction(action, qtrue, qtrue);
}
}
@ -633,19 +634,19 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
} else if (joystickX > releasedThreshold) {
// stop down
if ((controller->axisButtons & VR_TOUCH_AXIS_DOWN) && IN_GetButtonAction("RTHUMBBACK", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_DOWN;
// stop down-left
if ((controller->axisButtons & VR_TOUCH_AXIS_DOWNLEFT) && IN_GetButtonAction("RTHUMBBACKLEFT", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_DOWNLEFT;
// start down-right
if (!(controller->axisButtons & VR_TOUCH_AXIS_DOWNRIGHT)) {
controller->axisButtons |= VR_TOUCH_AXIS_DOWNRIGHT;
if (IN_GetButtonAction("RTHUMBBACKRIGHT", action)) {
IN_SendButtonAction(action, qtrue);
IN_SendButtonAction(action, qtrue, qtrue);
}
}
@ -653,19 +654,19 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
} else {
// stop down-left
if ((controller->axisButtons & VR_TOUCH_AXIS_DOWNLEFT) && IN_GetButtonAction("RTHUMBBACKLEFT", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_DOWNLEFT;
// stop down-right
if ((controller->axisButtons & VR_TOUCH_AXIS_DOWNRIGHT) && IN_GetButtonAction("RTHUMBBACKRIGHT", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_DOWNRIGHT;
// start down
if (!(controller->axisButtons & VR_TOUCH_AXIS_DOWN) && joystickY < -pressedThreshold) {
controller->axisButtons |= VR_TOUCH_AXIS_DOWN;
if (IN_GetButtonAction("RTHUMBBACK", action)) {
IN_SendButtonAction(action, qtrue);
IN_SendButtonAction(action, qtrue, qtrue);
}
}
}
@ -675,32 +676,32 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
// stop up-left
if ((controller->axisButtons & VR_TOUCH_AXIS_UPLEFT) && IN_GetButtonAction("RTHUMBFORWARDLEFT", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_UPLEFT;
// stop up
if ((controller->axisButtons & VR_TOUCH_AXIS_UP) && IN_GetButtonAction("RTHUMBFORWARD", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_UP;
// stop up-right
if ((controller->axisButtons & VR_TOUCH_AXIS_UPRIGHT) && IN_GetButtonAction("RTHUMBFORWARDRIGHT", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_UPRIGHT;
// stop down-left
if ((controller->axisButtons & VR_TOUCH_AXIS_DOWNLEFT) && IN_GetButtonAction("RTHUMBBACKLEFT", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_DOWNLEFT;
// stop down
if ((controller->axisButtons & VR_TOUCH_AXIS_DOWN) && IN_GetButtonAction("RTHUMBBACK", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_DOWN;
// stop down-right
if ((controller->axisButtons & VR_TOUCH_AXIS_DOWNRIGHT) && IN_GetButtonAction("RTHUMBBACKRIGHT", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_DOWNRIGHT;
@ -711,7 +712,7 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
if (IN_GetButtonAction("RTHUMBLEFT", action)) {
vr.smooth_turning = false;
if (!(controller->axisButtons & VR_TOUCH_AXIS_LEFT)) {
IN_SendButtonAction(action, qtrue);
IN_SendButtonAction(action, qtrue, qtrue);
}
controller->axisButtons |= VR_TOUCH_AXIS_LEFT;
@ -740,7 +741,7 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
vr.smooth_turning = false;
}
if ((controller->axisButtons & VR_TOUCH_AXIS_LEFT) && IN_GetButtonAction("RTHUMBLEFT", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_LEFT;
}
@ -752,7 +753,7 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
if (IN_GetButtonAction("RTHUMBRIGHT", action)) {
vr.smooth_turning = false;
if (!(controller->axisButtons & VR_TOUCH_AXIS_RIGHT)) {
IN_SendButtonAction(action, qtrue);
IN_SendButtonAction(action, qtrue, qtrue);
}
controller->axisButtons |= VR_TOUCH_AXIS_RIGHT;
@ -781,7 +782,7 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo
vr.smooth_turning = false;
}
if ((controller->axisButtons & VR_TOUCH_AXIS_RIGHT) && IN_GetButtonAction("RTHUMBRIGHT", action)) {
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qtrue);
}
controller->axisButtons &= ~VR_TOUCH_AXIS_RIGHT;
}
@ -828,7 +829,7 @@ static void IN_VRTriggers( qboolean isRightController, float index ) {
controller->axisButtons |= VR_TOUCH_AXIS_TRIGGER_INDEX;
if (IN_GetButtonAction("PRIMARYTRIGGER", action))
{
IN_SendButtonAction(action, qtrue);
IN_SendButtonAction(action, qtrue, qfalse);
}
}
else if ((controller->axisButtons & VR_TOUCH_AXIS_TRIGGER_INDEX) &&
@ -837,7 +838,7 @@ static void IN_VRTriggers( qboolean isRightController, float index ) {
controller->axisButtons &= ~VR_TOUCH_AXIS_TRIGGER_INDEX;
if (IN_GetButtonAction("PRIMARYTRIGGER", action))
{
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qfalse);
}
}
}
@ -851,7 +852,7 @@ static void IN_VRTriggers( qboolean isRightController, float index ) {
controller->axisButtons |= VR_TOUCH_AXIS_TRIGGER_INDEX;
if (IN_GetButtonAction("SECONDARYTRIGGER", action))
{
IN_SendButtonAction(action, qtrue);
IN_SendButtonAction(action, qtrue, qfalse);
}
}
else if ((controller->axisButtons & VR_TOUCH_AXIS_TRIGGER_INDEX) &&
@ -860,7 +861,7 @@ static void IN_VRTriggers( qboolean isRightController, float index ) {
controller->axisButtons &= ~VR_TOUCH_AXIS_TRIGGER_INDEX;
if (IN_GetButtonAction("SECONDARYTRIGGER", action))
{
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qfalse);
}
}
}
@ -887,7 +888,7 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
{
if (IN_GetButtonAction("SECONDARYGRIP", action))
{
IN_SendButtonAction(action, qtrue);
IN_SendButtonAction(action, qtrue, qfalse);
}
}
else if (!(buttons & ovrButton_GripTrigger) &&
@ -895,7 +896,7 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
{
if (IN_GetButtonAction("SECONDARYGRIP", action))
{
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qfalse);
}
}
}
@ -905,7 +906,7 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
{
if (IN_GetButtonAction("PRIMARYGRIP", action))
{
IN_SendButtonAction(action, qtrue);
IN_SendButtonAction(action, qtrue, qfalse);
}
}
else if (!(buttons & ovrButton_GripTrigger) &&
@ -913,7 +914,7 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
{
if (IN_GetButtonAction("PRIMARYGRIP", action))
{
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qfalse);
}
}
}
@ -924,14 +925,14 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
if ((buttons & ovrButton_LThumb) && !(controller->buttons & ovrButton_LThumb)) {
if (IN_GetButtonAction("SECONDARYTHUMBSTICK", action))
{
IN_SendButtonAction(action, qtrue);
IN_SendButtonAction(action, qtrue, qfalse);
}
vr.realign = 3;
} else if (!(buttons & ovrButton_LThumb) && (controller->buttons & ovrButton_LThumb)) {
if (IN_GetButtonAction("SECONDARYTHUMBSTICK", action))
{
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qfalse);
}
}
}
@ -940,12 +941,12 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
if ((buttons & ovrButton_RThumb) && !(controller->buttons & ovrButton_RThumb)) {
if (IN_GetButtonAction("PRIMARYTHUMBSTICK", action))
{
IN_SendButtonAction(action, qtrue);
IN_SendButtonAction(action, qtrue, qfalse);
}
} else if (!(buttons & ovrButton_RThumb) && (controller->buttons & ovrButton_RThumb)) {
if (IN_GetButtonAction("PRIMARYTHUMBSTICK", action))
{
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qfalse);
}
}
}
@ -961,7 +962,7 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
{
if (IN_GetButtonAction("A", action))
{
IN_SendButtonAction(action, qtrue);
IN_SendButtonAction(action, qtrue, qfalse);
}
}
}
@ -969,7 +970,7 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
{
if (IN_GetButtonAction("A", action) && !(cl.snap.ps.pm_flags & PMF_FOLLOW))
{
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qfalse);
}
}
@ -977,12 +978,12 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
if ((buttons & ovrButton_B) && !(controller->buttons & ovrButton_B)) {
if (IN_GetButtonAction("B", action))
{
IN_SendButtonAction(action, qtrue);
IN_SendButtonAction(action, qtrue, qfalse);
}
} else if (!(buttons & ovrButton_B) && (controller->buttons & ovrButton_B)) {
if (IN_GetButtonAction("B", action))
{
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qfalse);
}
}
@ -998,7 +999,7 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
{
if (IN_GetButtonAction("X", action))
{
IN_SendButtonAction(action, qtrue);
IN_SendButtonAction(action, qtrue, qfalse);
}
}
}
@ -1006,7 +1007,7 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
{
if (IN_GetButtonAction("X", action) && !(cl.snap.ps.pm_flags & PMF_FOLLOW))
{
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qfalse);
}
}
@ -1014,12 +1015,12 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons )
if ((buttons & ovrButton_Y) && !(controller->buttons & ovrButton_Y)) {
if (IN_GetButtonAction("Y", action))
{
IN_SendButtonAction(action, qtrue);
IN_SendButtonAction(action, qtrue, qfalse);
}
} else if (!(buttons & ovrButton_Y) && (controller->buttons & ovrButton_Y)) {
if (IN_GetButtonAction("Y", action))
{
IN_SendButtonAction(action, qfalse);
IN_SendButtonAction(action, qfalse, qfalse);
}
}