2022-09-18 15:37:21 +00:00
/************************************************************************************
Filename : VrInputDefault . c
Content : Handles default controller input
Created : August 2019
Authors : Simon Brown
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <android/keycodes.h>
# include "VrInput.h"
# include "VrCvars.h"
2022-10-03 21:19:00 +00:00
# include "qcommon/q_shared.h"
2022-09-19 21:46:47 +00:00
# include <qcommon/qcommon.h>
# include <client/client.h>
2022-11-08 21:43:12 +00:00
# include <statindex.h>
2022-10-03 21:19:00 +00:00
# include "android/sys_local.h"
2023-04-04 21:37:41 +00:00
# include "VrTBDC.h"
2023-03-22 21:43:59 +00:00
2023-03-22 20:34:12 +00:00
# ifdef JK2_MODE
2023-03-22 21:43:59 +00:00
# include "../OpenJK/codeJK2/game/weapons.h"
2023-03-22 20:34:12 +00:00
# else
# include "../OpenJK/code/game/weapons.h"
# endif
2022-09-18 15:37:21 +00:00
void SV_Trace ( trace_t * results , const vec3_t start , const vec3_t mins , const vec3_t maxs , const vec3_t end , int passEntityNum , int contentmask , int capsule ) ;
static inline float AngleBetweenVectors ( const vec3_t a , const vec3_t b )
{
2022-12-19 21:23:28 +00:00
return RAD2DEG ( acosf ( DotProduct ( a , b ) / ( VectorLength ( a ) * VectorLength ( b ) ) ) ) ;
2022-09-18 15:37:21 +00:00
}
2022-12-04 11:46:32 +00:00
void HandleInput_Default ( ovrInputStateTrackedRemote * pDominantTrackedRemoteNew , ovrInputStateTrackedRemote * pDominantTrackedRemoteOld , ovrTrackedController * pDominantTracking ,
ovrInputStateTrackedRemote * pOffTrackedRemoteNew , ovrInputStateTrackedRemote * pOffTrackedRemoteOld , ovrTrackedController * pOffTracking ,
2022-09-18 15:37:21 +00:00
int domButton1 , int domButton2 , int offButton1 , int offButton2 )
{
//Ensure handedness is set correctly
vr . right_handed = vr_control_scheme - > value < 10 | |
vr_control_scheme - > value = = 99 ; // Always right-handed for weapon calibration
2022-09-19 21:46:47 +00:00
static bool dominantGripPushed = false ;
2022-09-18 15:37:21 +00:00
static bool canUseBackpack = false ;
static bool canUseQuickSave = false ;
//Need this for the touch screen
2022-12-04 11:46:32 +00:00
ovrTrackedController * pWeapon = pDominantTracking ;
ovrTrackedController * pOff = pOffTracking ;
2022-09-18 15:37:21 +00:00
//All this to allow stick and button switching!
2022-12-04 11:46:32 +00:00
XrVector2f * pPrimaryJoystick ;
XrVector2f * pSecondaryJoystick ;
2022-09-18 15:37:21 +00:00
uint32_t primaryButtonsNew ;
uint32_t primaryButtonsOld ;
uint32_t secondaryButtonsNew ;
uint32_t secondaryButtonsOld ;
int primaryButton1 ;
int primaryButton2 ;
int secondaryButton1 ;
int secondaryButton2 ;
2023-03-31 12:52:40 +00:00
int primaryThumb ;
int secondaryThumb ;
if ( vr_control_scheme - > integer = = LEFT_HANDED_DEFAULT & & vr_switch_sticks - > integer )
{
primaryThumb = xrButton_RThumb ;
secondaryThumb = xrButton_LThumb ;
}
else if ( vr_control_scheme - > integer = = LEFT_HANDED_DEFAULT | | vr_switch_sticks - > integer )
{
primaryThumb = xrButton_LThumb ;
secondaryThumb = xrButton_RThumb ;
}
else
{
primaryThumb = xrButton_RThumb ;
secondaryThumb = xrButton_LThumb ;
}
2022-09-18 15:37:21 +00:00
if ( vr_switch_sticks - > integer )
{
//
// This will switch the joystick and A/B/X/Y button functions only
// Move, Strafe, Turn, Jump, Crouch, Notepad, HUD mode, Weapon Switch
pSecondaryJoystick = & pDominantTrackedRemoteNew - > Joystick ;
pPrimaryJoystick = & pOffTrackedRemoteNew - > Joystick ;
secondaryButtonsNew = pDominantTrackedRemoteNew - > Buttons ;
secondaryButtonsOld = pDominantTrackedRemoteOld - > Buttons ;
primaryButtonsNew = pOffTrackedRemoteNew - > Buttons ;
primaryButtonsOld = pOffTrackedRemoteOld - > Buttons ;
primaryButton1 = offButton1 ;
primaryButton2 = offButton2 ;
secondaryButton1 = domButton1 ;
secondaryButton2 = domButton2 ;
}
else
{
pPrimaryJoystick = & pDominantTrackedRemoteNew - > Joystick ;
pSecondaryJoystick = & pOffTrackedRemoteNew - > Joystick ;
primaryButtonsNew = pDominantTrackedRemoteNew - > Buttons ;
primaryButtonsOld = pDominantTrackedRemoteOld - > Buttons ;
secondaryButtonsNew = pOffTrackedRemoteNew - > Buttons ;
secondaryButtonsOld = pOffTrackedRemoteOld - > Buttons ;
primaryButton1 = domButton1 ;
primaryButton2 = domButton2 ;
secondaryButton1 = offButton1 ;
secondaryButton2 = offButton2 ;
}
2023-03-22 21:43:59 +00:00
//Allow weapon alignment mode toggle on x
if ( vr_align_weapons - > value )
2023-03-20 21:33:54 +00:00
{
bool offhandX = ( pOffTrackedRemoteNew - > Buttons & xrButton_X ) ;
if ( ( offhandX ! = ( pOffTrackedRemoteOld - > Buttons & xrButton_X ) ) & &
offhandX )
2023-03-22 21:43:59 +00:00
Cvar_Set ( " vr_control_scheme " , " 99 " ) ;
2023-03-20 21:33:54 +00:00
}
2023-02-26 09:45:41 +00:00
//Set controller angles - We need to calculate all those we might need (including adjustments) for the client to then take its pick
2022-09-18 15:37:21 +00:00
{
vec3_t rotation = { 0 } ;
2023-02-26 09:45:41 +00:00
QuatToYawPitchRoll ( pWeapon - > Pose . orientation , rotation , vr . weaponangles [ ANGLES_DEFAULT ] ) ;
QuatToYawPitchRoll ( pOff - > Pose . orientation , rotation , vr . offhandangles [ ANGLES_DEFAULT ] ) ;
2022-11-11 23:43:50 +00:00
2023-04-04 21:37:41 +00:00
rotation [ PITCH ] = 45 ;
//If we are in a saberBlockDebounce thing then add on an angle
//Lerped upon how far from the start of the saber move
if ( vr . saberBlockDebounce > cl . serverTime ) {
float lerp = 0.0f ;
//Where are we in the lerp
// 0 = vr.saberBlockDebounce - TBDC_SABER_BOUNCETIME
// 1 = vr.saberBlockDebounce - TBDC_SABER_BOUNCETIME / 2
// 0 (again) = vr.saberBlockDebounce
if ( cl . serverTime < vr . saberBlockDebounce - TBDC_SABER_BOUNCETIME / 2 )
{
//Somewhere between 0 and 1
lerp = float ( cl . serverTime - ( vr . saberBlockDebounce - TBDC_SABER_BOUNCETIME ) ) / float ( ( vr . saberBlockDebounce - TBDC_SABER_BOUNCETIME / 2 ) - ( vr . saberBlockDebounce - TBDC_SABER_BOUNCETIME ) ) ;
}
else
{
//Somewhere between 1 and 0
lerp = 1 - float ( cl . serverTime - ( vr . saberBlockDebounce - TBDC_SABER_BOUNCETIME / 2 ) ) / float ( vr . saberBlockDebounce - ( vr . saberBlockDebounce - TBDC_SABER_BOUNCETIME / 2 ) ) ;
}
switch ( vr . saberBounceMove ) {
case VRLS_B1_BR :
rotation [ PITCH ] + = lerp * TBDC_SABER_BOUNCEANGLE ;
rotation [ YAW ] - = lerp * TBDC_SABER_BOUNCEANGLE ;
break ;
case VRLS_B1__R :
rotation [ YAW ] - = lerp * TBDC_SABER_BOUNCEANGLE ;
break ;
case VRLS_B1_TR :
rotation [ PITCH ] - = lerp * TBDC_SABER_BOUNCEANGLE ;
rotation [ YAW ] - = lerp * TBDC_SABER_BOUNCEANGLE ;
break ;
case VRLS_B1_T_ :
rotation [ PITCH ] - = lerp * TBDC_SABER_BOUNCEANGLE ;
break ;
case VRLS_B1_TL :
rotation [ PITCH ] - = lerp * TBDC_SABER_BOUNCEANGLE ;
rotation [ YAW ] + = lerp * TBDC_SABER_BOUNCEANGLE ;
break ;
case VRLS_B1__L :
rotation [ YAW ] + = lerp * TBDC_SABER_BOUNCEANGLE ;
break ;
case VRLS_B1_BL :
rotation [ PITCH ] + = lerp * TBDC_SABER_BOUNCEANGLE ;
rotation [ YAW ] + = lerp * TBDC_SABER_BOUNCEANGLE ;
break ;
2023-04-05 19:57:07 +00:00
default :
rotation [ PITCH ] - = lerp * TBDC_SABER_BOUNCEANGLE ;
rotation [ YAW ] + = lerp * ( TBDC_SABER_BOUNCEANGLE / 2 ) ;
break ;
2023-04-04 21:37:41 +00:00
}
2022-11-11 23:43:50 +00:00
}
2023-04-04 21:37:41 +00:00
/*else if(cl.serverTime > vr.saberBlockDebounce + 3000)
{
if ( vr . saberBounceMove < 82 )
{
vr . saberBounceMove = 82 ;
}
vr . saberBlockDebounce = cl . serverTime + TBDC_SABER_BOUNCETIME ;
} */
QuatToYawPitchRoll ( pWeapon - > Pose . orientation , rotation , vr . weaponangles [ ANGLES_SABER ] ) ;
QuatToYawPitchRoll ( pOff - > Pose . orientation , rotation , vr . offhandangles [ ANGLES_SABER ] ) ;
2022-09-18 15:37:21 +00:00
2023-02-26 09:45:41 +00:00
rotation [ PITCH ] = vr_weapon_pitchadjust - > value ;
QuatToYawPitchRoll ( pWeapon - > Pose . orientation , rotation , vr . weaponangles [ ANGLES_ADJUSTED ] ) ;
QuatToYawPitchRoll ( pOff - > Pose . orientation , rotation , vr . offhandangles [ ANGLES_ADJUSTED ] ) ;
2022-09-18 15:37:21 +00:00
2023-02-26 09:45:41 +00:00
for ( int anglesIndex = 0 ; anglesIndex < = ANGLES_SABER ; + + anglesIndex )
{
VectorSubtract ( vr . weaponangles_last [ anglesIndex ] , vr . weaponangles [ anglesIndex ] , vr . weaponangles_delta [ anglesIndex ] ) ;
VectorCopy ( vr . weaponangles [ anglesIndex ] , vr . weaponangles_last [ anglesIndex ] ) ;
2022-09-18 15:37:21 +00:00
2023-02-26 09:45:41 +00:00
VectorSubtract ( vr . offhandangles_last [ anglesIndex ] , vr . offhandangles [ anglesIndex ] , vr . offhandangles_delta [ anglesIndex ] ) ;
VectorCopy ( vr . offhandangles [ anglesIndex ] , vr . offhandangles_last [ anglesIndex ] ) ;
}
2022-09-18 15:37:21 +00:00
}
//Menu button
2022-12-04 11:46:32 +00:00
handleTrackedControllerButton ( & leftTrackedRemoteState_new , & leftTrackedRemoteState_old , xrButton_Enter , A_ESCAPE ) ;
2023-03-17 21:58:55 +00:00
handleTrackedControllerButton ( & rightTrackedRemoteState_new , & rightTrackedRemoteState_old , xrButton_Enter , A_ESCAPE ) ;
2022-09-18 15:37:21 +00:00
2023-03-21 20:10:40 +00:00
static float menuYaw = 0 ;
2023-03-31 13:40:54 +00:00
if ( VR_UseScreenLayer ( ) & & ! vr . misc_camera & & ! vr . cin_camera /*bit of a fiddle, but if we are in a misc camera or cin camera, we are in the game and shouldn't be in here*/ )
2022-09-18 15:37:21 +00:00
{
2023-03-21 20:10:40 +00:00
bool controlsLeftHanded = vr_control_scheme - > integer > = 10 ;
2023-04-01 10:07:13 +00:00
if ( controlsLeftHanded = = vr . menu_right_handed ) {
2023-03-21 20:10:40 +00:00
interactWithTouchScreen ( menuYaw , vr . offhandangles [ ANGLES_DEFAULT ] ) ;
handleTrackedControllerButton ( pOffTrackedRemoteNew , pOffTrackedRemoteOld , offButton1 , A_MOUSE1 ) ;
handleTrackedControllerButton ( pOffTrackedRemoteNew , pOffTrackedRemoteOld , xrButton_Trigger , A_MOUSE1 ) ;
handleTrackedControllerButton ( pOffTrackedRemoteNew , pOffTrackedRemoteOld , offButton2 , A_ESCAPE ) ;
if ( ( pDominantTrackedRemoteNew - > Buttons & xrButton_Trigger ) ! = ( pDominantTrackedRemoteOld - > Buttons & xrButton_Trigger ) & & ( pDominantTrackedRemoteNew - > Buttons & xrButton_Trigger ) ) {
2023-04-01 10:07:13 +00:00
vr . menu_right_handed = ! vr . menu_right_handed ;
2023-03-21 20:10:40 +00:00
}
} else {
interactWithTouchScreen ( menuYaw , vr . weaponangles [ ANGLES_DEFAULT ] ) ;
handleTrackedControllerButton ( pDominantTrackedRemoteNew , pDominantTrackedRemoteOld , domButton1 , A_MOUSE1 ) ;
handleTrackedControllerButton ( pDominantTrackedRemoteNew , pDominantTrackedRemoteOld , xrButton_Trigger , A_MOUSE1 ) ;
handleTrackedControllerButton ( pDominantTrackedRemoteNew , pDominantTrackedRemoteOld , domButton2 , A_ESCAPE ) ;
if ( ( pOffTrackedRemoteNew - > Buttons & xrButton_Trigger ) ! = ( pOffTrackedRemoteOld - > Buttons & xrButton_Trigger ) & & ( pOffTrackedRemoteNew - > Buttons & xrButton_Trigger ) ) {
2023-04-01 10:07:13 +00:00
vr . menu_right_handed = ! vr . menu_right_handed ;
2023-03-21 20:10:40 +00:00
}
}
2023-04-04 21:59:12 +00:00
2023-04-04 22:30:35 +00:00
//Close the datapad
2023-04-04 21:59:12 +00:00
if ( ( ( secondaryButtonsNew & secondaryButton2 ) ! =
( secondaryButtonsOld & secondaryButton2 ) ) & &
( secondaryButtonsNew & secondaryButton2 ) ) {
Sys_QueEvent ( 0 , SE_KEY , A_TAB , true , 0 , NULL ) ;
}
2022-09-18 15:37:21 +00:00
}
else
{
2023-03-21 20:10:40 +00:00
menuYaw = vr . hmdorientation [ YAW ] ;
2022-09-18 15:37:21 +00:00
2022-12-04 11:46:32 +00:00
float distance = sqrtf ( powf ( pOff - > Pose . position . x - pWeapon - > Pose . position . x , 2 ) +
powf ( pOff - > Pose . position . y - pWeapon - > Pose . position . y , 2 ) +
powf ( pOff - > Pose . position . z - pWeapon - > Pose . position . z , 2 ) ) ;
2022-09-18 15:37:21 +00:00
2022-12-04 11:46:32 +00:00
float distanceToHMD = sqrtf ( powf ( vr . hmdposition [ 0 ] - pWeapon - > Pose . position . x , 2 ) +
powf ( vr . hmdposition [ 1 ] - pWeapon - > Pose . position . y , 2 ) +
powf ( vr . hmdposition [ 2 ] - pWeapon - > Pose . position . z , 2 ) ) ;
2022-09-18 15:37:21 +00:00
2022-12-04 11:46:32 +00:00
float distanceToHMDOff = sqrtf ( powf ( vr . hmdposition [ 0 ] - pOff - > Pose . position . x , 2 ) +
powf ( vr . hmdposition [ 1 ] - pOff - > Pose . position . y , 2 ) +
powf ( vr . hmdposition [ 2 ] - pOff - > Pose . position . z , 2 ) ) ;
2022-09-18 15:37:21 +00:00
2022-12-14 14:45:51 +00:00
2022-09-18 15:37:21 +00:00
float controllerYawHeading = 0.0f ;
//Turn on weapon stabilisation?
2022-12-04 11:46:32 +00:00
bool offhandGripPushed = ( pOffTrackedRemoteNew - > Buttons & xrButton_GripTrigger ) ;
2022-10-16 15:50:32 +00:00
if ( offhandGripPushed )
2022-09-18 15:37:21 +00:00
{
2022-11-08 21:43:12 +00:00
if ( ! vr . weapon_stabilised & & vr . item_selector = = 0 & &
2022-11-11 19:48:35 +00:00
! vr . misc_camera & & ! vr . cgzoommode )
2022-10-16 15:50:32 +00:00
{
2022-10-20 16:47:12 +00:00
if ( distance < STABILISATION_DISTANCE & &
2022-10-29 08:44:25 +00:00
vr_two_handed_weapons - > integer & &
2022-11-08 21:43:12 +00:00
cl . frame . ps . weapon > = WP_SABER ) {
2022-10-16 15:50:32 +00:00
vr . weapon_stabilised = true ;
} else {
vr . item_selector = 2 ;
}
}
}
else if ( vr . item_selector = = 2 )
2022-10-12 22:03:17 +00:00
{
2022-10-16 15:50:32 +00:00
sendButtonActionSimple ( " itemselectorselect " ) ;
vr . item_selector = 0 ;
2022-10-12 22:03:17 +00:00
}
2022-10-16 15:50:32 +00:00
else
{
vr . weapon_stabilised = false ;
}
2022-10-12 17:00:26 +00:00
dominantGripPushed = ( pDominantTrackedRemoteNew - > Buttons &
2022-12-04 11:46:32 +00:00
xrButton_GripTrigger ) ! = 0 ;
2022-10-12 17:00:26 +00:00
//Do this early so we can suppress other button actions when item selector is up
2022-10-16 15:50:32 +00:00
if ( dominantGripPushed ) {
2022-11-11 19:48:35 +00:00
if ( ! vr . weapon_stabilised & & vr . item_selector = = 0
& & ! vr . misc_camera & & ! vr . cgzoommode ) {
2022-10-16 15:50:32 +00:00
vr . item_selector = 1 ;
2022-09-18 15:37:21 +00:00
}
}
2022-10-16 15:50:32 +00:00
else if ( vr . item_selector = = 1 )
{
sendButtonActionSimple ( " itemselectorselect " ) ;
vr . item_selector = 0 ;
}
2022-09-18 15:37:21 +00:00
2022-10-12 17:00:26 +00:00
# define JOYX_SAMPLE_COUNT 4
static float joyx [ JOYX_SAMPLE_COUNT ] = { 0 } ;
for ( int j = JOYX_SAMPLE_COUNT - 1 ; j > 0 ; - - j )
joyx [ j ] = joyx [ j - 1 ] ;
joyx [ 0 ] = pPrimaryJoystick - > x ;
float sum = 0.0f ;
for ( int j = 0 ; j < JOYX_SAMPLE_COUNT ; + + j )
sum + = joyx [ j ] ;
float primaryJoystickX = sum / 4.0f ;
2022-10-02 22:17:51 +00:00
2022-10-12 17:00:26 +00:00
//Left/right to switch between which selector we are using
if ( vr . item_selector ) {
static bool itemSwitched = false ;
if ( between ( - 0.2f , pPrimaryJoystick - > y , 0.2f ) & &
2022-12-13 00:02:46 +00:00
( primaryJoystickX > 0.8f | | primaryJoystickX < - 0.8f ) ) {
2022-10-12 17:00:26 +00:00
if ( ! itemSwitched ) {
2022-12-13 00:02:46 +00:00
if ( primaryJoystickX > 0.8f ) {
2022-10-12 17:00:26 +00:00
sendButtonActionSimple ( " itemselectornext " ) ;
2022-12-13 00:02:46 +00:00
itemSwitched = true ;
} else if ( primaryJoystickX < - 0.8f ) {
2022-10-12 17:00:26 +00:00
sendButtonActionSimple ( " itemselectorprev " ) ;
2022-12-13 00:02:46 +00:00
itemSwitched = true ;
2022-10-04 21:48:30 +00:00
}
2022-09-18 15:37:21 +00:00
}
2022-12-13 00:02:46 +00:00
} else if ( between ( - 0.4f , primaryJoystickX , 0.4f ) ) {
2022-10-12 17:00:26 +00:00
itemSwitched = false ;
2022-09-18 15:37:21 +00:00
}
2022-10-12 17:00:26 +00:00
}
2023-03-31 13:40:54 +00:00
if ( vr . cin_camera )
{
//To skip cinematic use any thumb or trigger
if ( ( primaryButtonsNew & primaryThumb ) ! = ( primaryButtonsOld & primaryThumb ) ) {
sendButtonAction ( " +use " , ( primaryButtonsNew & primaryThumb ) ) ;
}
if ( ( secondaryButtonsNew & secondaryThumb ) ! = ( secondaryButtonsOld & secondaryThumb ) ) {
sendButtonAction ( " +use " , ( secondaryButtonsNew & secondaryThumb ) ) ;
}
if ( ( pDominantTrackedRemoteNew - > Buttons & xrButton_Trigger ) ! = ( pDominantTrackedRemoteOld - > Buttons & xrButton_Trigger ) ) {
sendButtonAction ( " +use " , ( pDominantTrackedRemoteNew - > Buttons & xrButton_Trigger ) ) ;
// mark button as already pressed to prevent firing after entering the game
pDominantTrackedRemoteOld - > Buttons | = xrButton_Trigger ;
}
if ( ( pOffTrackedRemoteNew - > Buttons & xrButton_Trigger ) ! = ( pOffTrackedRemoteOld - > Buttons & xrButton_Trigger ) ) {
sendButtonAction ( " +use " , ( pOffTrackedRemoteNew - > Buttons & xrButton_Trigger ) ) ;
// mark button as already pressed to prevent firing after entering the game
pOffTrackedRemoteOld - > Buttons | = xrButton_Trigger ;
}
}
else if ( vr . misc_camera )
2023-03-05 08:51:50 +00:00
{
if ( between ( - 0.2f , primaryJoystickX , 0.2f ) ) {
sendButtonAction ( " +use " , pPrimaryJoystick - > y < - 0.8f | | pPrimaryJoystick - > y > 0.8f ) ;
}
}
else if ( vr . cgzoommode )
2022-10-12 21:35:27 +00:00
{
if ( between ( - 0.2f , primaryJoystickX , 0.2f ) ) {
2023-01-19 21:23:29 +00:00
if ( vr . cgzoommode = = 2 )
{ // We are in disruptor scope
2023-01-19 21:16:20 +00:00
if ( pPrimaryJoystick - > y > 0.8f ) {
vr . cgzoomdir = - 1 ; // zooming in
sendButtonAction ( " +altattack " , true ) ;
} else if ( pPrimaryJoystick - > y < - 0.8f ) {
vr . cgzoomdir = 1 ; // zooming out
sendButtonAction ( " +altattack " , true ) ;
} else {
sendButtonAction ( " +altattack " , false ) ;
}
2022-11-08 21:43:12 +00:00
}
2023-01-19 21:23:29 +00:00
else if ( vr . cgzoommode = = 1 )
{ // We are in binoculars scope - zoom in or out
sendButtonAction ( " +attack " , pPrimaryJoystick - > y > 0.8f ) ;
sendButtonAction ( " +altattack " , pPrimaryJoystick - > y < - 0.8f ) ;
2022-11-08 21:43:12 +00:00
}
2023-01-19 21:23:29 +00:00
// No function of thumbstick for nightvision (3) or blaster scope (4)
2022-10-12 21:35:27 +00:00
}
2022-11-03 22:38:34 +00:00
}
2022-11-08 21:43:12 +00:00
else if ( cl . frame . ps . weapon = = WP_SABER )
2022-10-12 21:35:27 +00:00
{
2022-11-25 23:35:49 +00:00
if ( vr_saber_3rdperson_mode - > integer = = 2 ) {
int mode = ( int ) Cvar_VariableValue ( " cg_thirdPerson " ) ;
if ( ! mode )
{
sendButtonActionSimple ( " cg_thirdPerson 1 " ) ;
}
} else if ( vr_saber_3rdperson_mode - > integer = = 1 ) {
int mode = ( int ) Cvar_VariableValue ( " cg_thirdPerson " ) ;
static bool switched = false ;
if ( between ( - 0.2f , primaryJoystickX , 0.2f ) & &
( between ( 0.8f , pPrimaryJoystick - > y , 1.0f ) | |
between ( - 1.0f , pPrimaryJoystick - > y , - 0.8f ) ) ) {
if ( ! switched ) {
mode = 1 - mode ;
sendButtonActionSimple ( va ( " cg_thirdPerson %i " , mode ) ) ;
switched = true ;
}
} else {
switched = false ;
2022-10-12 21:35:27 +00:00
}
} else {
2022-11-25 23:35:49 +00:00
int mode = ( int ) Cvar_VariableValue ( " cg_thirdPerson " ) ;
if ( mode ! = 0 )
{
sendButtonActionSimple ( " cg_thirdPerson 0 " ) ;
}
2022-10-12 21:35:27 +00:00
}
}
2022-11-03 22:38:34 +00:00
else
{
int mode = ( int ) Cvar_VariableValue ( " cg_thirdPerson " ) ;
if ( mode ! = 0 )
{
sendButtonActionSimple ( " cg_thirdPerson 0 " ) ;
}
}
2022-10-12 21:35:27 +00:00
2023-04-05 20:19:45 +00:00
/*
//Parameter Changer
static bool changed = false ;
2023-04-02 21:18:28 +00:00
if ( between ( - 0.2f , primaryJoystickX , 0.2f ) & &
between ( 0.8f , pPrimaryJoystick - > y , 1.0f ) ) {
if ( ! changed ) {
vr . tempWeaponVelocity + = 25 ;
changed = true ;
ALOGV ( " **TBDC** Projectile speed %f " , vr . tempWeaponVelocity ) ;
}
} else if ( between ( - 0.2f , primaryJoystickX , 0.2f ) & &
between ( - 1.0f , pPrimaryJoystick - > y , - 0.8f ) ) {
if ( ! changed ) {
vr . tempWeaponVelocity - = 25 ;
ALOGV ( " **TBDC** Projectile speed %f " , vr . tempWeaponVelocity ) ;
changed = true ;
}
}
else
{
changed = false ;
2023-04-05 20:19:45 +00:00
} */
2023-04-02 21:18:28 +00:00
2022-11-07 23:57:10 +00:00
//dominant hand stuff first
{
//Record recent weapon position for trajectory based stuff
for ( int i = ( NUM_WEAPON_SAMPLES - 1 ) ; i ! = 0 ; - - i ) {
VectorCopy ( vr . weaponoffset_history [ i - 1 ] , vr . weaponoffset_history [ i ] ) ;
vr . weaponoffset_history_timestamp [ i ] = vr . weaponoffset_history_timestamp [ i - 1 ] ;
}
VectorCopy ( vr . weaponoffset , vr . weaponoffset_history [ 0 ] ) ;
vr . weaponoffset_history_timestamp [ 0 ] = vr . weaponoffset_timestamp ;
2023-04-05 20:19:45 +00:00
2023-04-04 21:37:41 +00:00
VectorSet ( vr . weaponposition , pWeapon - > Pose . position . x ,
pWeapon - > Pose . position . y , pWeapon - > Pose . position . z ) ;
2022-11-07 23:57:10 +00:00
2023-04-04 21:37:41 +00:00
///Weapon location relative to view
VectorSet ( vr . weaponoffset , pWeapon - > Pose . position . x ,
pWeapon - > Pose . position . y , pWeapon - > Pose . position . z ) ;
VectorSubtract ( vr . weaponoffset , vr . hmdposition , vr . weaponoffset ) ;
vr . weaponoffset_timestamp = Sys_Milliseconds ( ) ;
2023-04-05 20:19:45 +00:00
2022-11-07 23:57:10 +00:00
vec3_t velocity ;
2022-12-04 11:46:32 +00:00
VectorSet ( velocity , pWeapon - > Velocity . linearVelocity . x ,
pWeapon - > Velocity . linearVelocity . y , pWeapon - > Velocity . linearVelocity . z ) ;
2022-11-07 23:57:10 +00:00
vr . primaryswingvelocity = VectorLength ( velocity ) ;
2022-12-04 11:46:32 +00:00
VectorSet ( velocity , pOff - > Velocity . linearVelocity . x ,
pOff - > Velocity . linearVelocity . y , pOff - > Velocity . linearVelocity . z ) ;
2022-11-07 23:57:10 +00:00
vr . secondaryswingvelocity = VectorLength ( velocity ) ;
//For melee right hand is alt attack and left hand is attack
2022-11-08 21:43:12 +00:00
if ( cl . frame . ps . weapon = = WP_MELEE ) {
2022-11-07 23:57:10 +00:00
//Does weapon velocity trigger attack (melee) and is it fast enough
if ( vr . velocitytriggered ) {
static bool fired = false ;
vr . primaryVelocityTriggeredAttack = ( vr . primaryswingvelocity >
vr_weapon_velocity_trigger - > value ) ;
if ( fired ! = vr . primaryVelocityTriggeredAttack ) {
ALOGV ( " **WEAPON EVENT** veocity triggered %s " ,
vr . primaryVelocityTriggeredAttack ? " +altattack " : " -altattack " ) ;
//normal attack is a punch with the left hand
2022-10-12 17:00:26 +00:00
sendButtonAction ( " +altattack " , vr . primaryVelocityTriggeredAttack ) ;
2022-11-07 23:57:10 +00:00
fired = vr . primaryVelocityTriggeredAttack ;
2022-10-12 17:00:26 +00:00
}
2022-11-07 23:57:10 +00:00
} else if ( vr . primaryVelocityTriggeredAttack ) {
//send a stop attack as we have an unfinished velocity attack
vr . primaryVelocityTriggeredAttack = false ;
ALOGV ( " **WEAPON EVENT** veocity triggered -altattack " ) ;
sendButtonAction ( " +altattack " , vr . primaryVelocityTriggeredAttack ) ;
}
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
if ( vr . velocitytriggered ) {
static bool fired = false ;
vr . secondaryVelocityTriggeredAttack = ( vr . secondaryswingvelocity >
vr_weapon_velocity_trigger - > value ) ;
if ( fired ! = vr . secondaryVelocityTriggeredAttack ) {
ALOGV ( " **WEAPON EVENT** veocity triggered %s " ,
vr . secondaryVelocityTriggeredAttack ? " +attack " : " -attack " ) ;
//normal attack is a punch with the left hand
2022-10-12 17:00:26 +00:00
sendButtonAction ( " +attack " , vr . secondaryVelocityTriggeredAttack ) ;
2022-11-07 23:57:10 +00:00
fired = vr . secondaryVelocityTriggeredAttack ;
2022-10-12 17:00:26 +00:00
}
2022-11-07 23:57:10 +00:00
} else if ( vr . secondaryVelocityTriggeredAttack ) {
//send a stop attack as we have an unfinished velocity attack
vr . secondaryVelocityTriggeredAttack = qfalse ;
ALOGV ( " **WEAPON EVENT** veocity triggered -attack " ) ;
sendButtonAction ( " +attack " , vr . secondaryVelocityTriggeredAttack ) ;
}
2023-03-22 20:34:12 +00:00
} else if ( cl . frame . ps . weapon = = WP_SABER | |
cl . frame . ps . weapon = = WP_STUN_BATON ) {
2022-11-07 23:57:10 +00:00
//Does weapon velocity trigger attack
if ( vr . velocitytriggered ) {
static bool fired = false ;
2023-03-28 22:19:29 +00:00
float velocityRequired = ( cl . frame . ps . weapon = = WP_SABER ) ? vr_weapon_velocity_trigger - > value :
( vr_weapon_velocity_trigger - > value / 2.0f ) ;
vr . primaryVelocityTriggeredAttack = ( vr . primaryswingvelocity > velocityRequired ) ;
2023-03-08 21:05:28 +00:00
//player has to be dual wielding for this to be true
2023-03-12 10:03:42 +00:00
if ( vr . dualsabers )
{
2023-03-28 22:19:29 +00:00
vr . secondaryVelocityTriggeredAttack = ( vr . secondaryswingvelocity > velocityRequired ) ;
2023-03-12 10:03:42 +00:00
}
2022-11-07 23:57:10 +00:00
2023-03-22 20:34:12 +00:00
bool triggered = vr . primaryVelocityTriggeredAttack | | ( vr . dualsabers & & vr . secondaryVelocityTriggeredAttack ) ;
2023-03-08 21:05:28 +00:00
if ( fired ! = triggered )
{
2022-11-07 23:57:10 +00:00
ALOGV ( " **WEAPON EVENT** veocity triggered %s " ,
2023-03-08 21:05:28 +00:00
triggered ? " +attack " : " -attack " ) ;
2022-11-07 23:57:10 +00:00
//normal attack is a punch with the left hand
2023-03-08 21:05:28 +00:00
sendButtonAction ( " +attack " , triggered ) ;
fired = triggered ;
2022-10-12 17:00:26 +00:00
}
2023-03-08 21:05:28 +00:00
} else if ( vr . primaryVelocityTriggeredAttack | | vr . secondaryVelocityTriggeredAttack ) {
2022-11-07 23:57:10 +00:00
//send a stop attack as we have an unfinished velocity attack
vr . primaryVelocityTriggeredAttack = false ;
2023-03-08 21:05:28 +00:00
vr . secondaryVelocityTriggeredAttack = false ;
2022-11-07 23:57:10 +00:00
ALOGV ( " **WEAPON EVENT** veocity triggered -attack " ) ;
sendButtonAction ( " +attack " , vr . primaryVelocityTriggeredAttack ) ;
2022-10-12 17:00:26 +00:00
}
2022-11-07 23:57:10 +00:00
}
2022-09-18 15:37:21 +00:00
2023-03-07 22:53:18 +00:00
//Should we trigger the disruptor scope?
if ( ( cl . frame . ps . weapon = = WP_DISRUPTOR | |
cl . frame . ps . weapon = = WP_BLASTER ) & &
cl . frame . ps . stats [ STAT_HEALTH ] > 0 )
{
if ( vr . weapon_stabilised & &
VectorLength ( vr . weaponoffset ) < 0.24f & &
vr . cgzoommode = = 0 ) {
sendButtonAction ( " enterscope " , true ) ;
} else if ( ( VectorLength ( vr . weaponoffset ) > 0.26f | | ! vr . weapon_stabilised ) & &
( vr . cgzoommode = = 2 | | vr . cgzoommode = = 4 ) ) {
sendButtonActionSimple ( " exitscope " ) ;
}
} else if ( vr . cgzoommode = = 2 | | vr . cgzoommode = = 4 ) {
// In case we were using weapon scope and weapon
// was changed due to out of ammo, exit scope
sendButtonActionSimple ( " exitscope " ) ;
}
2022-11-21 21:56:59 +00:00
vec3_t offhandPositionAverage ;
VectorClear ( offhandPositionAverage ) ;
for ( int i = 0 ; i < 5 ; + + i )
{
VectorAdd ( offhandPositionAverage , vr . offhandposition [ i ] , offhandPositionAverage ) ;
}
VectorScale ( offhandPositionAverage , 0.2f , offhandPositionAverage ) ;
2023-03-21 20:04:54 +00:00
if ( vr . weapon_stabilised & & ! vr . dualsabers ) {
2023-03-30 19:52:44 +00:00
if ( vr . cgzoommode = = 2 | | vr . cgzoommode = = 4 )
{
2023-03-28 12:52:23 +00:00
//If scope is engaged, lift muzzle slightly so that it aligns with the headset
2023-03-30 19:52:44 +00:00
float x = offhandPositionAverage [ 0 ] - ( vr . hmdposition [ 0 ] ) ;
float y = ( offhandPositionAverage [ 1 ] + 0.12f ) - ( vr . hmdposition [ 1 ] ) ;
float z = offhandPositionAverage [ 2 ] - ( vr . hmdposition [ 2 ] ) ;
2022-11-07 23:57:10 +00:00
float zxDist = length ( x , z ) ;
2022-11-09 21:28:18 +00:00
if ( zxDist ! = 0.0f & & z ! = 0.0f ) {
2023-02-26 09:45:41 +00:00
VectorSet ( vr . weaponangles [ ANGLES_ADJUSTED ] , - RAD2DEG ( atanf ( y / zxDist ) ) ,
- RAD2DEG ( atan2f ( x , - z ) ) , vr . weaponangles [ ANGLES_ADJUSTED ] [ ROLL ] /
2022-11-09 21:28:18 +00:00
2.0f ) ; //Dampen roll on stabilised weapon
2023-03-07 22:53:18 +00:00
// shoot from exactly where we are looking from
VectorClear ( vr . weaponoffset ) ;
VectorCopy ( vr . hmdposition , vr . weaponposition ) ;
2022-11-09 21:28:18 +00:00
}
}
2023-03-30 19:52:44 +00:00
else if ( vr_virtual_stock - > integer = = 1 )
{
//offset to the appropriate eye a little bit
vec2_t xy = { 0 , 0 } ;
rotateAboutOrigin ( Cvar_VariableValue ( " cg_stereoSeparation " ) / 2.0f , 0.0f , - vr . hmdorientation [ YAW ] , xy ) ;
float x = vr . offhandposition [ 0 ] [ 0 ] - ( vr . hmdposition [ 0 ] + xy [ 0 ] ) ;
float y = vr . offhandposition [ 0 ] [ 1 ] - ( vr . hmdposition [ 1 ] - 0.1f ) ;
float z = vr . offhandposition [ 0 ] [ 2 ] - ( vr . hmdposition [ 2 ] + xy [ 1 ] ) ;
float zxDist = length ( x , z ) ;
if ( zxDist ! = 0.0f & & z ! = 0.0f ) {
VectorSet ( vr . weaponangles [ ANGLES_ADJUSTED ] , - RAD2DEG ( atanf ( y / zxDist ) ) ,
- RAD2DEG ( atan2f ( x , - z ) ) , 0 ) ; //Dampen roll on stabilised weapon
}
}
2022-11-09 21:28:18 +00:00
else
{
2023-03-21 20:04:54 +00:00
vec3_t delta ;
delta [ 0 ] = pOff - > Pose . position . x - pWeapon - > Pose . position . x ;
delta [ 1 ] = pOff - > Pose . position . y - pWeapon - > Pose . position . y ;
delta [ 2 ] = pOff - > Pose . position . z - pWeapon - > Pose . position . z ;
2022-11-07 23:57:10 +00:00
2023-03-21 20:04:54 +00:00
int anglesToSet = ANGLES_ADJUSTED ;
2023-03-22 20:34:12 +00:00
if ( cl . frame . ps . weapon = = WP_SABER | |
cl . frame . ps . weapon = = WP_STUN_BATON )
2023-03-21 20:04:54 +00:00
{
anglesToSet = ANGLES_SABER ;
VectorNegate ( delta , delta ) ;
}
float zxDist = length ( delta [ 0 ] , delta [ 2 ] ) ;
if ( zxDist ! = 0.0f & & delta [ 2 ] ! = 0.0f ) {
VectorSet ( vr . weaponangles [ anglesToSet ] , - RAD2DEG ( atanf ( delta [ 1 ] / zxDist ) ) ,
- RAD2DEG ( atan2f ( delta [ 0 ] , - delta [ 2 ] ) ) , vr . weaponangles [ anglesToSet ] [ ROLL ] /
2022-11-07 23:57:10 +00:00
2.0f ) ; //Dampen roll on stabilised weapon
2022-10-12 17:00:26 +00:00
}
2022-09-18 15:37:21 +00:00
}
2022-11-07 23:57:10 +00:00
}
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
// Calculate if player tries to reach backpack
bool handInBackpack = false ;
bool bpDistToHMDOk = false , bpWeaponHeightOk = false , bpWeaponAngleOk = false , bpHmdToWeaponAngleOk = false ;
vec3_t hmdForwardXY = { } , weaponForwardXY = { } ;
float weaponToDownAngle = 0 , hmdToWeaponDotProduct = 0 ;
static vec3_t downVector = { 0.0 , 0.0 , - 1.0 } ;
2022-12-04 11:46:32 +00:00
if ( ( bpDistToHMDOk = distanceToHMD > = 0.2 & & distanceToHMD < =
2022-11-07 23:57:10 +00:00
0.35 ) // 2) Weapon-to-HMD distance must be within <0.2-0.35> range
& & ( bpWeaponHeightOk = vr . weaponoffset [ 1 ] > = - 0.10 & & vr . weaponoffset [ 1 ] < =
0.10 ) ) // 3) Weapon height in relation to HMD must be within <-0.10, 0.10> range
{
AngleVectors ( vr . hmdorientation , hmdForwardXY , NULL , NULL ) ;
2023-02-26 09:45:41 +00:00
AngleVectors ( vr . weaponangles [ ANGLES_ADJUSTED ] , weaponForwardXY , NULL , NULL ) ;
2022-09-27 22:19:12 +00:00
2022-11-07 23:57:10 +00:00
float weaponToDownAngle = AngleBetweenVectors ( downVector , weaponForwardXY ) ;
// 4) Angle between weapon forward vector and a down vector must be within 80-140 degrees
if ( bpWeaponAngleOk = weaponToDownAngle > = 80.0 & & weaponToDownAngle < = 140.0 ) {
hmdForwardXY [ 2 ] = 0 ;
VectorNormalize ( hmdForwardXY ) ;
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
weaponForwardXY [ 2 ] = 0 ;
VectorNormalize ( weaponForwardXY ) ;
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
hmdToWeaponDotProduct = DotProduct ( hmdForwardXY , weaponForwardXY ) ;
// 5) HMD and weapon forward on XY plane must go in opposite directions (i.e. dot product < 0)
handInBackpack = bpHmdToWeaponAngleOk = hmdToWeaponDotProduct < 0 ;
2022-09-18 15:37:21 +00:00
}
2022-11-07 23:57:10 +00:00
}
2022-10-12 17:00:26 +00:00
2022-11-07 23:57:10 +00:00
//off-hand stuff (done here as I reference it in the save state thing
{
2022-11-21 21:56:59 +00:00
for ( int i = 4 ; i > 0 ; - - i )
{
VectorCopy ( vr . offhandposition [ i - 1 ] , vr . offhandposition [ i ] ) ;
}
2022-12-04 11:46:32 +00:00
vr . offhandposition [ 0 ] [ 0 ] = pOff - > Pose . position . x ;
vr . offhandposition [ 0 ] [ 1 ] = pOff - > Pose . position . y ;
vr . offhandposition [ 0 ] [ 2 ] = pOff - > Pose . position . z ;
2022-09-18 15:37:21 +00:00
2022-12-04 11:46:32 +00:00
vr . offhandoffset [ 0 ] = pOff - > Pose . position . x - vr . hmdposition [ 0 ] ;
vr . offhandoffset [ 1 ] = pOff - > Pose . position . y - vr . hmdposition [ 1 ] ;
vr . offhandoffset [ 2 ] = pOff - > Pose . position . z - vr . hmdposition [ 2 ] ;
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
if ( vr_walkdirection - > value = = 0 ) {
2023-02-26 09:45:41 +00:00
controllerYawHeading = vr . offhandangles [ ANGLES_ADJUSTED ] [ YAW ] - vr . hmdorientation [ YAW ] ;
2022-11-07 23:57:10 +00:00
} else {
controllerYawHeading = 0.0f ;
2022-10-12 17:00:26 +00:00
}
2022-11-07 23:57:10 +00:00
}
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
// Use off hand as well to trigger save condition
canUseQuickSave = false ;
bool bpOffhandDistToHMDOk = false , bpOffhandHeightOk = false , bpOffhandAngleOk = false , bpHmdToOffhandAngleOk = false ;
vec3_t offhandForwardXY = { } ;
float hmdToOffhandDotProduct = 0 ;
float offhandToDownAngle = 0 ;
2022-12-04 11:46:32 +00:00
if ( ( bpOffhandDistToHMDOk = distanceToHMDOff > = 0.2 & &
2022-11-07 23:57:10 +00:00
distanceToHMDOff < =
0.35 ) // 2) Off-to-HMD distance must be within <0.2-0.35> range
& & ( bpOffhandHeightOk = vr . offhandoffset [ 1 ] > = - 0.10 & & vr . offhandoffset [ 1 ] < =
0.10 ) ) // 3) Offhand height in relation to HMD must be within <-0.10, 0.10> range
{
//Need to do this again as might not have done it above and cant be bothered to refactor
AngleVectors ( vr . hmdorientation , hmdForwardXY , NULL , NULL ) ;
2023-02-26 09:45:41 +00:00
AngleVectors ( vr . offhandangles [ ANGLES_ADJUSTED ] , offhandForwardXY , NULL , NULL ) ;
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
offhandToDownAngle = AngleBetweenVectors ( downVector , offhandForwardXY ) ;
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
// 4) Angle between weapon forward vector and a down vector must be within 80-140 degrees
if ( bpOffhandAngleOk =
offhandToDownAngle > = 80.0 & & offhandToDownAngle < = 140.0 ) {
hmdForwardXY [ 2 ] = 0 ;
VectorNormalize ( hmdForwardXY ) ;
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
offhandForwardXY [ 2 ] = 0 ;
VectorNormalize ( offhandForwardXY ) ;
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
hmdToOffhandDotProduct = DotProduct ( hmdForwardXY , offhandForwardXY ) ;
// 5) HMD and weapon forward on XY plane must go in opposite directions (i.e. dot product < 0)
canUseQuickSave = bpHmdToOffhandAngleOk = hmdToOffhandDotProduct < 0 ;
2022-10-12 17:00:26 +00:00
}
2022-11-07 23:57:10 +00:00
}
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
// Uncomment to debug offhand reaching
2022-09-18 15:37:21 +00:00
2022-10-12 21:35:27 +00:00
/* ALOGV("Quick Save> Dist: %f | OffHandToDownAngle: %f | HandOffs: %f %f %f\nHmdHandDot: %f | HmdFwdXY: %f %f | WpnFwdXY: %f %f\nTrackOk: %i, DistOk: %i, HeightOk: %i, HnadAngleOk: %i, HmdHandDotOk: %i",
2022-11-07 23:57:10 +00:00
distanceToHMDOff , offhandToDownAngle , vr . offhandoffset [ 0 ] ,
vr . offhandoffset [ 1 ] , vr . offhandoffset [ 2 ] ,
hmdToOffhandDotProduct , hmdForwardXY [ 0 ] , hmdForwardXY [ 1 ] , offhandForwardXY [ 0 ] ,
offhandForwardXY [ 1 ] ,
bpTrackOk , bpOffhandDistToHMDOk , bpOffhandHeightOk , bpOffhandAngleOk ,
bpHmdToOffhandAngleOk ) ;
2022-10-12 21:35:27 +00:00
*/
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
// Check quicksave
2023-03-21 20:04:54 +00:00
static bool indicateQuickSave = true ;
2022-11-07 23:57:10 +00:00
if ( canUseQuickSave ) {
2023-04-03 19:36:35 +00:00
//GB Fix buzzing left controller not right
int channel = ( vr_control_scheme - > integer > = 10 ) ? 1 : 2 ;
2023-03-21 20:04:54 +00:00
if ( indicateQuickSave )
{
TBXR_Vibrate ( 40 , channel , 0.5 ) ; // vibrate to let user know they can switch
indicateQuickSave = false ;
}
2022-09-18 15:37:21 +00:00
2023-03-21 20:04:54 +00:00
if ( ( ( secondaryButtonsNew & secondaryButton1 ) ! =
( secondaryButtonsOld & secondaryButton1 ) ) & &
( secondaryButtonsNew & secondaryButton1 ) ) {
# ifdef JK2_MODE
2023-04-05 19:57:07 +00:00
sendButtonActionSimple ( " save quik* " ) ;
2023-03-21 20:04:54 +00:00
# else
sendButtonActionSimple ( " save quick " ) ;
# endif
2022-11-07 23:57:10 +00:00
}
2022-09-18 15:37:21 +00:00
2023-03-21 20:04:54 +00:00
if ( ( ( secondaryButtonsNew & secondaryButton2 ) ! =
( secondaryButtonsOld & secondaryButton2 ) ) & &
( secondaryButtonsNew & secondaryButton2 ) ) {
# ifdef JK2_MODE
sendButtonActionSimple ( " load quik " ) ;
# else
sendButtonActionSimple ( " load quick " ) ;
# endif
2022-09-18 15:37:21 +00:00
}
}
2023-03-21 20:04:54 +00:00
else
{
//Next time we can quick save, allow a haptic blip
indicateQuickSave = true ;
}
2022-11-07 23:57:10 +00:00
}
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
//Right-hand specific stuff
{
//This section corrects for the fact that the controller actually controls direction of movement, but we want to move relative to the direction the
//player is facing for positional tracking
//Positional movement speed correction for when we are not hitting target framerate
static double lastframetime = 0 ;
2022-12-19 21:23:28 +00:00
int refresh = TBXR_GetRefresh ( ) ;
double newframetime = TBXR_GetTimeInMilliSeconds ( ) ;
2022-11-07 23:57:10 +00:00
float multiplier = ( float ) ( ( 1000.0 / refresh ) / ( newframetime - lastframetime ) ) ;
lastframetime = newframetime ;
vec2_t v ;
float factor = ( refresh / 72.0F ) *
vr_positional_factor - > value ; // adjust positional factor based on refresh rate
rotateAboutOrigin ( - vr . hmdposition_delta [ 0 ] * factor * multiplier ,
vr . hmdposition_delta [ 2 ] * factor * multiplier ,
- vr . hmdorientation [ YAW ] , v ) ;
positional_movementSideways = v [ 0 ] ;
positional_movementForward = v [ 1 ] ;
ALOGV ( " positional_movementSideways: %f, positional_movementForward: %f " ,
positional_movementSideways ,
positional_movementForward ) ;
//Jump (A Button)
if ( ( primaryButtonsNew & primaryButton1 ) ! = ( primaryButtonsOld & primaryButton1 ) ) {
sendButtonAction ( " +moveup " , ( primaryButtonsNew & primaryButton1 ) ) ;
}
2022-09-29 22:38:22 +00:00
2022-11-08 21:43:12 +00:00
//B Button
2022-11-07 23:57:10 +00:00
if ( ( primaryButtonsNew & primaryButton2 ) ! = ( primaryButtonsOld & primaryButton2 ) ) {
2023-01-19 21:23:29 +00:00
if ( vr . cgzoommode = = 1 | | vr . cgzoommode = = 3 )
{ // Exit scope only when using binoculars or nightvision
2022-11-16 22:34:41 +00:00
sendButtonActionSimple ( " exitscope " ) ;
2022-11-07 23:57:10 +00:00
}
2022-11-08 21:43:12 +00:00
else if ( cl . frame . ps . weapon = = WP_SABER & & vr . velocitytriggered )
2022-11-07 23:57:10 +00:00
{
//B button toggles saber on/off in first person
if ( primaryButtonsNew & primaryButton2 ) {
sendButtonActionSimple ( " togglesaber " ) ;
2022-10-12 21:35:27 +00:00
}
2022-10-12 17:00:26 +00:00
}
2022-11-08 21:43:12 +00:00
else if ( cl . frame . ps . weapon ! = WP_DISRUPTOR )
2022-11-07 23:57:10 +00:00
{
sendButtonAction ( " +altattack " , ( primaryButtonsNew & primaryButton2 ) ) ;
}
}
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
static bool firing = false ;
static bool throwing = false ;
2022-10-14 22:51:31 +00:00
2022-11-07 23:57:10 +00:00
int thirdPerson = Cvar_VariableIntegerValue ( " cg_thirdPerson " ) ;
2022-09-27 22:19:12 +00:00
2022-11-11 19:48:35 +00:00
if ( cl . frame . ps . weapon = = WP_SABER & & ! thirdPerson & &
vr . cgzoommode = = 0 & & cl . frame . ps . stats [ STAT_HEALTH ] > 0 )
2022-11-07 23:57:10 +00:00
{
static bool previous_throwing = false ;
previous_throwing = throwing ;
if ( ! throwing & &
vr . primaryVelocityTriggeredAttack & &
2022-12-04 11:46:32 +00:00
( pDominantTrackedRemoteNew - > Buttons & xrButton_Trigger ) )
2022-10-14 22:51:31 +00:00
{
2022-11-07 23:57:10 +00:00
throwing = true ;
2022-10-14 22:51:31 +00:00
}
2022-12-04 11:46:32 +00:00
else if ( throwing & & ! ( pDominantTrackedRemoteNew - > Buttons & xrButton_Trigger ) )
2022-10-12 17:00:26 +00:00
{
2022-11-07 23:57:10 +00:00
throwing = false ;
}
2022-10-14 22:51:31 +00:00
2022-11-07 23:57:10 +00:00
if ( previous_throwing ! = throwing ) {
sendButtonAction ( " +altattack " , throwing ) ;
}
}
else if ( ! vr . velocitytriggered ) // Don't fire velocity triggered weapons
{
//Fire Primary - Doesn't trigger the saber
2022-12-04 11:46:32 +00:00
if ( ( pDominantTrackedRemoteNew - > Buttons & xrButton_Trigger ) ! =
( pDominantTrackedRemoteOld - > Buttons & xrButton_Trigger ) ) {
2022-11-07 23:57:10 +00:00
2022-12-04 11:46:32 +00:00
firing = ( pDominantTrackedRemoteNew - > Buttons & xrButton_Trigger ) & &
2022-11-30 17:52:57 +00:00
! vr . item_selector ;
2022-11-07 23:57:10 +00:00
sendButtonAction ( " +attack " , firing ) ;
}
if ( throwing )
{
//if throwing is still activated here, just disable
throwing = false ;
sendButtonAction ( " +altattack " , throwing ) ;
2022-10-12 22:03:17 +00:00
}
2022-11-07 23:57:10 +00:00
}
2022-09-18 15:37:21 +00:00
2022-09-29 19:18:23 +00:00
2022-11-07 23:57:10 +00:00
//Duck - off hand joystick
if ( ( secondaryButtonsNew & secondaryThumb ) ! =
( secondaryButtonsOld & secondaryThumb ) ) {
2022-09-18 15:37:21 +00:00
2022-11-11 23:43:50 +00:00
if ( vr_crouch_toggle - > integer )
{
2022-11-12 09:30:41 +00:00
if ( secondaryButtonsOld & secondaryThumb ) {
vr . crouched = ! vr . crouched ;
sendButtonAction ( " +movedown " , vr . crouched ) ;
}
2022-11-11 23:43:50 +00:00
}
else
{
sendButtonAction ( " +movedown " , ( secondaryButtonsNew & secondaryThumb ) ) ;
}
2022-11-16 21:27:36 +00:00
// Reset max height for IRL crouch
vr . maxHeight = 0 ;
2022-11-07 23:57:10 +00:00
}
2022-09-28 22:07:22 +00:00
2022-11-07 23:57:10 +00:00
//Use
2023-03-31 12:52:40 +00:00
if ( ( primaryButtonsNew & primaryThumb ) ! =
( primaryButtonsOld & primaryThumb ) ) {
2022-09-18 15:37:21 +00:00
2023-03-31 12:52:40 +00:00
sendButtonAction ( " +use " , ( primaryButtonsNew & primaryThumb ) ) ;
2022-09-18 15:37:21 +00:00
}
2022-11-07 23:57:10 +00:00
}
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
{
//Apply a filter and quadratic scaler so small movements are easier to make
float dist = length ( pSecondaryJoystick - > x , pSecondaryJoystick - > y ) ;
float nlf = nonLinearFilter ( dist ) ;
2023-01-18 21:55:47 +00:00
dist = ( dist > 1.0f ) ? dist : 1.0f ;
float x = nlf * ( pSecondaryJoystick - > x / dist ) ;
float y = nlf * ( pSecondaryJoystick - > y / dist ) ;
2022-11-07 23:57:10 +00:00
vr . player_moving = ( fabs ( x ) + fabs ( y ) ) > 0.05f ;
//Adjust to be off-hand controller oriented
vec2_t v ;
rotateAboutOrigin ( x , y , controllerYawHeading , v ) ;
//Move a lot slower if scope is engaged
remote_movementSideways =
2022-11-25 23:25:37 +00:00
v [ 0 ] * ( vr . move_speed = = 0 ? 0.75f : ( vr . move_speed = = 1 ? 1.0f : 0.5f ) ) ;
2022-11-07 23:57:10 +00:00
remote_movementForward =
2022-11-25 23:25:37 +00:00
v [ 1 ] * ( vr . move_speed = = 0 ? 0.75f : ( vr . move_speed = = 1 ? 1.0f : 0.5f ) ) ;
2022-11-07 23:57:10 +00:00
ALOGV ( " remote_movementSideways: %f, remote_movementForward: %f " ,
remote_movementSideways ,
remote_movementForward ) ;
if ( ! canUseQuickSave ) {
2022-11-25 23:25:37 +00:00
if ( ( ( secondaryButtonsNew & secondaryButton1 ) ! =
( secondaryButtonsOld & secondaryButton1 ) ) & &
( secondaryButtonsNew & secondaryButton1 ) ) {
2022-11-07 23:57:10 +00:00
//Toggle walk/run somehow?!
2022-11-25 23:25:37 +00:00
vr . move_speed = ( + + vr . move_speed ) % 3 ;
2022-09-18 15:37:21 +00:00
}
2022-11-07 23:57:10 +00:00
}
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
//Open the datapad
if ( ! canUseQuickSave ) {
if ( ( ( secondaryButtonsNew & secondaryButton2 ) ! =
( secondaryButtonsOld & secondaryButton2 ) ) & &
( secondaryButtonsNew & secondaryButton2 ) ) {
Sys_QueEvent ( 0 , SE_KEY , A_TAB , true , 0 , NULL ) ;
2022-10-12 17:00:26 +00:00
}
2022-11-07 23:57:10 +00:00
}
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
//Use Force - off hand trigger
{
2022-12-04 11:46:32 +00:00
if ( ( pOffTrackedRemoteNew - > Buttons & xrButton_Trigger ) ! =
( pOffTrackedRemoteOld - > Buttons & xrButton_Trigger ) )
2022-10-12 17:00:26 +00:00
{
2022-12-04 11:46:32 +00:00
sendButtonAction ( " +useforce " , ( pOffTrackedRemoteNew - > Buttons & xrButton_Trigger ) ) ;
2022-10-12 17:00:26 +00:00
}
2022-11-07 23:57:10 +00:00
}
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
//Use smooth in 3rd person
bool usingSnapTurn = vr_turn_mode - > integer = = 0 | |
( ! vr . third_person & & vr_turn_mode - > integer = = 1 ) ;
static int increaseSnap = true ;
2022-11-21 21:56:59 +00:00
if ( ! vr . item_selector ) {
2022-11-07 23:57:10 +00:00
if ( usingSnapTurn ) {
if ( primaryJoystickX > 0.7f ) {
if ( increaseSnap ) {
vr . snapTurn - = vr_turn_angle - > value ;
increaseSnap = false ;
if ( vr . snapTurn < - 180.0f ) {
vr . snapTurn + = 360.f ;
2022-10-12 17:00:26 +00:00
}
2022-09-18 15:37:21 +00:00
}
2022-11-07 23:57:10 +00:00
} else if ( primaryJoystickX < 0.3f ) {
increaseSnap = true ;
2022-09-18 15:37:21 +00:00
}
2022-11-07 23:57:10 +00:00
}
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
static int decreaseSnap = true ;
if ( usingSnapTurn ) {
if ( primaryJoystickX < - 0.7f ) {
if ( decreaseSnap ) {
vr . snapTurn + = vr_turn_angle - > value ;
decreaseSnap = false ;
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
if ( vr . snapTurn > 180.0f ) {
vr . snapTurn - = 360.f ;
2022-10-12 17:00:26 +00:00
}
2022-10-31 22:17:09 +00:00
}
2022-11-07 23:57:10 +00:00
} else if ( primaryJoystickX > - 0.3f ) {
decreaseSnap = true ;
2022-10-31 22:17:09 +00:00
}
2022-11-07 23:57:10 +00:00
}
2022-10-31 22:17:09 +00:00
2022-11-07 23:57:10 +00:00
if ( ! usingSnapTurn & & fabs ( primaryJoystickX ) > 0.1f ) //smooth turn
{
vr . snapTurn - = ( ( vr_turn_angle - > value / 10.0f ) *
primaryJoystickX ) ;
if ( vr . snapTurn > 180.0f ) {
vr . snapTurn - = 360.f ;
2022-10-12 17:00:26 +00:00
}
2022-11-07 23:57:10 +00:00
}
} else {
if ( fabs ( primaryJoystickX ) > 0.5f ) {
increaseSnap = false ;
2022-10-12 17:00:26 +00:00
} else {
2022-11-07 23:57:10 +00:00
increaseSnap = true ;
2022-09-18 15:37:21 +00:00
}
}
2022-11-07 23:57:10 +00:00
}
2022-09-18 15:37:21 +00:00
2022-11-07 23:57:10 +00:00
//process force motion controls here
2023-01-28 15:28:24 +00:00
if ( vr_force_motion_controlled - > integer & &
2023-03-11 15:39:22 +00:00
! vr . weapon_stabilised & &
// If dual sabers we can't really use motion control force as the off hand could be swinging for an attack
! vr . dualsabers )
2022-11-07 23:57:10 +00:00
{
if ( vr . secondaryswingvelocity > vr_force_velocity_trigger - > value )
{
if ( ! vr . secondaryVelocityTriggeredAttack )
{
2022-11-21 21:56:59 +00:00
VectorCopy ( vr . offhandposition [ 0 ] , vr . secondaryVelocityTriggerLocation ) ;
2022-11-07 23:57:10 +00:00
vr . secondaryVelocityTriggeredAttack = true ;
}
}
else
{
if ( vr . secondaryVelocityTriggeredAttack )
{
2022-11-27 14:51:07 +00:00
vec3_t start , end , chest ;
2023-03-22 22:58:17 +00:00
vec3_t offhandRightXY = { } ;
vec3_t hmdForwardXY = { } ;
float hmdToOffhandDotProduct = 0 ;
AngleVectors ( vr . hmdorientation , hmdForwardXY , NULL , NULL ) ;
AngleVectors ( vr . offhandangles [ ANGLES_DEFAULT ] , NULL , offhandRightXY , NULL ) ;
hmdForwardXY [ 1 ] = 0 ;
VectorNormalize ( hmdForwardXY ) ;
offhandRightXY [ 1 ] = 0 ;
VectorNormalize ( offhandRightXY ) ;
hmdToOffhandDotProduct = DotProduct ( hmdForwardXY , offhandRightXY ) ;
bool palmAway = hmdToOffhandDotProduct > 0 ;
if ( ! vr . right_handed )
{
//Opposite direction for the other controller
palmAway = ! palmAway ;
}
2022-11-27 14:51:07 +00:00
//Estimate that middle of chest is about 20cm below HMD
VectorCopy ( vr . hmdposition , chest ) ;
chest [ 1 ] - = 0.2f ;
VectorSubtract ( vr . secondaryVelocityTriggerLocation , chest , start ) ;
VectorSubtract ( vr . offhandposition [ 0 ] , chest , end ) ;
2022-11-12 17:05:39 +00:00
float deltaLength = VectorLength ( end ) - VectorLength ( start ) ;
2022-11-27 14:51:07 +00:00
if ( fabs ( deltaLength ) > vr_force_distance_trigger - > value ) {
2023-03-22 22:58:17 +00:00
if ( deltaLength < 0 & & ! palmAway )
{
2022-11-12 17:05:39 +00:00
sendButtonActionSimple ( va ( " useGivenForce %i " , FP_PULL ) ) ;
2023-03-22 22:58:17 +00:00
}
else if ( deltaLength > 0 & & palmAway )
{
2022-11-12 17:05:39 +00:00
sendButtonActionSimple ( va ( " useGivenForce %i " , FP_PUSH ) ) ;
}
2022-11-07 23:57:10 +00:00
2022-11-12 17:05:39 +00:00
vr . secondaryVelocityTriggeredAttack = false ;
}
2022-11-07 23:57:10 +00:00
}
}
2022-10-12 17:00:26 +00:00
}
2022-11-26 15:38:17 +00:00
// Process "use" gesture
if ( vr_gesture_triggered_use - > integer ) {
2023-03-05 08:48:31 +00:00
bool thirdPersonActive = ! ! ( ( int ) Cvar_VariableValue ( " cg_thirdPerson " ) ) ;
bool gestureUseAllowed = ! vr . weapon_stabilised & & ! vr . cin_camera & & ! vr . misc_camera & & ! vr . remote_turret & & ! vr . emplaced_gun & & ! vr . in_vehicle & & ! thirdPersonActive ;
// Off-hand gesture
float distanceToBody = sqrt ( vr . offhandoffset [ 0 ] * vr . offhandoffset [ 0 ] + vr . offhandoffset [ 2 ] * vr . offhandoffset [ 2 ] ) ;
if ( gestureUseAllowed & & ( distanceToBody > vr_use_gesture_boundary - > value ) ) {
if ( ! ( vr . useGestureState & USE_GESTURE_OFF_HAND ) ) {
sendButtonAction ( " +altuse " , true ) ;
}
vr . useGestureState | = USE_GESTURE_OFF_HAND ;
2022-11-26 15:38:17 +00:00
} else {
2023-03-05 08:48:31 +00:00
if ( vr . useGestureState & USE_GESTURE_OFF_HAND ) {
sendButtonAction ( " +altuse " , false ) ;
}
vr . useGestureState & = ~ USE_GESTURE_OFF_HAND ;
2022-11-26 15:38:17 +00:00
}
2023-03-05 08:48:31 +00:00
// Weapon-hand gesture
distanceToBody = sqrt ( vr . weaponoffset [ 0 ] * vr . weaponoffset [ 0 ] + vr . weaponoffset [ 2 ] * vr . weaponoffset [ 2 ] ) ;
if ( gestureUseAllowed & & ( distanceToBody > vr_use_gesture_boundary - > value ) ) {
if ( ! ( vr . useGestureState & USE_GESTURE_WEAPON_HAND ) ) {
2022-11-26 15:38:17 +00:00
sendButtonAction ( " +use " , true ) ;
}
2023-03-05 08:48:31 +00:00
vr . useGestureState | = USE_GESTURE_WEAPON_HAND ;
} else {
if ( vr . useGestureState & USE_GESTURE_WEAPON_HAND ) {
sendButtonAction ( " +use " , false ) ;
}
vr . useGestureState & = ~ USE_GESTURE_WEAPON_HAND ;
}
} else {
if ( vr . useGestureState & USE_GESTURE_OFF_HAND ) {
sendButtonAction ( " +altuse " , false ) ;
}
if ( vr . useGestureState & USE_GESTURE_WEAPON_HAND ) {
2022-11-26 15:38:17 +00:00
sendButtonAction ( " +use " , false ) ;
}
2023-03-05 08:48:31 +00:00
vr . useGestureState = 0 ;
2022-11-26 15:38:17 +00:00
}
2022-09-18 15:37:21 +00:00
}
2022-11-07 23:57:10 +00:00
2022-09-18 15:37:21 +00:00
//Save state
rightTrackedRemoteState_old = rightTrackedRemoteState_new ;
leftTrackedRemoteState_old = leftTrackedRemoteState_new ;
}