2020-09-08 22:10:45 +00:00
/************************************************************************************
Filename : VrInputDefault . c
Content : Handles default controller input
Created : August 2019
Authors : Simon Brown
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "../../../../../../VrApi/Include/VrApi.h"
# include "../../../../../../VrApi/Include/VrApi_Helpers.h"
# include "../../../../../../VrApi/Include/VrApi_SystemUtils.h"
# include "../../../../../../VrApi/Include/VrApi_Input.h"
# include "../../../../../../VrApi/Include/VrApi_Types.h"
# include <android/keycodes.h>
# include <sys/time.h>
# include "VrInput.h"
2020-09-09 22:16:24 +00:00
# include "doomkeys.h"
2020-09-15 23:02:29 +00:00
float vr_reloadtimeoutms = 200.0f ;
float vr_walkdirection = 0 ;
float vr_weapon_pitchadjust = - 30.0f ;
2020-09-08 22:10:45 +00:00
float vr_teleport ;
2020-09-09 22:16:24 +00:00
float vr_switch_sticks = 0 ;
2020-09-08 22:10:45 +00:00
2020-09-16 21:41:35 +00:00
extern bool forceVirtualScreen ;
2020-09-08 22:10:45 +00:00
/*
= = = = = = = = = = = = = = = =
Sys_Milliseconds
= = = = = = = = = = = = = = = =
*/
int curtime ;
int sys_timeBase ;
int Sys_Milliseconds ( void ) {
struct timeval tp ;
struct timezone tzp ;
gettimeofday ( & tp , & tzp ) ;
if ( ! sys_timeBase ) {
sys_timeBase = tp . tv_sec ;
return tp . tv_usec / 1000 ;
}
curtime = ( tp . tv_sec - sys_timeBase ) * 1000 + tp . tv_usec / 1000 ;
return curtime ;
}
2020-11-15 18:52:37 +00:00
void Android_SetImpulse ( int impulse ) ;
2020-09-11 21:41:18 +00:00
void Android_SetCommand ( const char * cmd ) ;
2020-09-17 21:46:48 +00:00
void Android_ButtonChange ( int key , int state ) ;
2020-09-23 18:34:14 +00:00
int Android_GetCVarInteger ( const char * cvar ) ;
2020-09-08 22:10:45 +00:00
2020-09-16 21:41:35 +00:00
extern bool inMenu ;
extern bool inGameGuiActive ;
extern bool objectiveSystemActive ;
extern bool inCinematic ;
2020-09-23 22:06:34 +00:00
2021-01-06 17:22:29 +00:00
void HandleInput_Default ( int controlscheme , int switchsticks , ovrInputStateTrackedRemote * pDominantTrackedRemoteNew , ovrInputStateTrackedRemote * pDominantTrackedRemoteOld , ovrTracking * pDominantTracking ,
2020-09-08 22:10:45 +00:00
ovrInputStateTrackedRemote * pOffTrackedRemoteNew , ovrInputStateTrackedRemote * pOffTrackedRemoteOld , ovrTracking * pOffTracking ,
int domButton1 , int domButton2 , int offButton1 , int offButton2 )
{
2020-11-15 18:52:37 +00:00
//pVRClientInfo->teleportenabled = vr_teleport != 0;
2020-09-08 22:10:45 +00:00
static bool dominantGripPushed = false ;
static float dominantGripPushTime = 0.0f ;
//Need this for the touch screen
ovrTracking * pWeapon = pDominantTracking ;
ovrTracking * pOff = pOffTracking ;
//All this to allow stick and button switching!
ovrVector2f * pPrimaryJoystick ;
ovrVector2f * pSecondaryJoystick ;
uint32_t primaryButtonsNew ;
uint32_t primaryButtonsOld ;
uint32_t secondaryButtonsNew ;
uint32_t secondaryButtonsOld ;
int primaryButton1 ;
int primaryButton2 ;
int secondaryButton1 ;
int secondaryButton2 ;
2021-01-06 17:22:29 +00:00
if ( controlscheme = = 1 ) //Left Handed
2020-09-08 22:10:45 +00:00
{
secondaryButtonsNew = pDominantTrackedRemoteNew - > Buttons ;
secondaryButtonsOld = pDominantTrackedRemoteOld - > Buttons ;
primaryButtonsNew = pOffTrackedRemoteNew - > Buttons ;
primaryButtonsOld = pOffTrackedRemoteOld - > Buttons ;
secondaryButton1 = domButton1 ;
secondaryButton2 = domButton2 ;
2021-01-06 17:22:29 +00:00
primaryButton1 = offButton1 ;
primaryButton2 = offButton2 ;
if ( switchsticks = = 1 ) //Switch
{
pPrimaryJoystick = & pDominantTrackedRemoteNew - > Joystick ;
pSecondaryJoystick = & pOffTrackedRemoteNew - > Joystick ;
} else {
pSecondaryJoystick = & pDominantTrackedRemoteNew - > Joystick ;
pPrimaryJoystick = & pOffTrackedRemoteNew - > Joystick ;
}
} else //Right Handed
2020-09-08 22:10:45 +00:00
{
primaryButtonsNew = pDominantTrackedRemoteNew - > Buttons ;
primaryButtonsOld = pDominantTrackedRemoteOld - > Buttons ;
secondaryButtonsNew = pOffTrackedRemoteNew - > Buttons ;
secondaryButtonsOld = pOffTrackedRemoteOld - > Buttons ;
primaryButton1 = domButton1 ;
primaryButton2 = domButton2 ;
secondaryButton1 = offButton1 ;
secondaryButton2 = offButton2 ;
2021-01-06 17:22:29 +00:00
if ( switchsticks = = 1 ) //Switch
{
pSecondaryJoystick = & pDominantTrackedRemoteNew - > Joystick ;
pPrimaryJoystick = & pOffTrackedRemoteNew - > Joystick ;
} else {
pPrimaryJoystick = & pDominantTrackedRemoteNew - > Joystick ;
pSecondaryJoystick = & pOffTrackedRemoteNew - > Joystick ;
}
2020-09-08 22:10:45 +00:00
}
2021-01-06 17:22:29 +00:00
2020-09-08 22:10:45 +00:00
{
2020-11-15 18:52:37 +00:00
//Store original values
const ovrQuatf quatRHand = pWeapon - > HeadPose . Pose . Orientation ;
const ovrVector3f positionRHand = pWeapon - > HeadPose . Pose . Position ;
const ovrQuatf quatLHand = pOff - > HeadPose . Pose . Orientation ;
const ovrVector3f positionLHand = pOff - > HeadPose . Pose . Position ;
2020-12-22 17:47:20 +00:00
2021-01-06 17:22:29 +00:00
/*VectorSet(pVRClientInfo->rhandposition, positionRHand.x, positionRHand.y, positionRHand.z);
2020-12-22 17:47:20 +00:00
Vector4Set ( pVRClientInfo - > rhand_orientation_quat , quatRHand . x , quatRHand . y , quatRHand . z , quatRHand . w ) ;
VectorSet ( pVRClientInfo - > lhandposition , positionLHand . x , positionLHand . y , positionLHand . z ) ;
2021-01-06 17:22:29 +00:00
Vector4Set ( pVRClientInfo - > lhand_orientation_quat , quatLHand . x , quatLHand . y , quatLHand . z , quatLHand . w ) ; */
2020-12-22 17:47:20 +00:00
2020-11-15 18:52:37 +00:00
//Right Hand
2020-12-22 17:47:20 +00:00
//GB - FP Already does this so we end up with backward hands
2021-01-06 17:22:29 +00:00
if ( controlscheme = = 1 ) { //Left Handed
2020-11-15 18:52:37 +00:00
VectorSet ( pVRClientInfo - > lhandposition , positionRHand . x , positionRHand . y , positionRHand . z ) ;
Vector4Set ( pVRClientInfo - > lhand_orientation_quat , quatRHand . x , quatRHand . y , quatRHand . z , quatRHand . w ) ;
VectorSet ( pVRClientInfo - > rhandposition , positionLHand . x , positionLHand . y , positionLHand . z ) ;
Vector4Set ( pVRClientInfo - > rhand_orientation_quat , quatLHand . x , quatLHand . y , quatLHand . z , quatLHand . w ) ;
2021-01-06 17:22:29 +00:00
} else {
VectorSet ( pVRClientInfo - > rhandposition , positionRHand . x , positionRHand . y , positionRHand . z ) ;
Vector4Set ( pVRClientInfo - > rhand_orientation_quat , quatRHand . x , quatRHand . y , quatRHand . z , quatRHand . w ) ;
VectorSet ( pVRClientInfo - > lhandposition , positionLHand . x , positionLHand . y , positionLHand . z ) ;
Vector4Set ( pVRClientInfo - > lhand_orientation_quat , quatLHand . x , quatLHand . y , quatLHand . z , quatLHand . w ) ;
}
2020-11-15 18:52:37 +00:00
2020-09-08 22:10:45 +00:00
//Set gun angles - We need to calculate all those we might need (including adjustments) for the client to then take its pick
vec3_t rotation = { 0 } ;
2020-09-23 22:06:34 +00:00
rotation [ PITCH ] = 30 ;
2020-11-15 18:52:37 +00:00
rotation [ PITCH ] = vr_weapon_pitchadjust ;
QuatToYawPitchRoll ( pWeapon - > HeadPose . Pose . Orientation , rotation , pVRClientInfo - > weaponangles_temp ) ;
VectorSubtract ( pVRClientInfo - > weaponangles_last_temp , pVRClientInfo - > weaponangles_temp , pVRClientInfo - > weaponangles_delta_temp ) ;
VectorCopy ( pVRClientInfo - > weaponangles_temp , pVRClientInfo - > weaponangles_last_temp ) ;
/*
vec3_t rotation = { 0 } ;
rotation [ PITCH ] = 30 ;
2020-09-23 22:06:34 +00:00
QuatToYawPitchRoll ( pWeapon - > HeadPose . Pose . Orientation , rotation , pVRClientInfo - > weaponangles_unadjusted ) ;
2020-09-11 21:41:18 +00:00
rotation [ PITCH ] = vr_weapon_pitchadjust ;
2020-09-08 22:10:45 +00:00
QuatToYawPitchRoll ( pWeapon - > HeadPose . Pose . Orientation , rotation , pVRClientInfo - > weaponangles ) ;
VectorSubtract ( pVRClientInfo - > weaponangles_last , pVRClientInfo - > weaponangles , pVRClientInfo - > weaponangles_delta ) ;
VectorCopy ( pVRClientInfo - > weaponangles , pVRClientInfo - > weaponangles_last ) ;
2020-11-15 18:52:37 +00:00
*/
2020-09-08 22:10:45 +00:00
}
2020-09-16 21:41:35 +00:00
//Menu button - can be used in all modes
2020-09-11 21:41:18 +00:00
handleTrackedControllerButton_AsKey ( & leftTrackedRemoteState_new , & leftTrackedRemoteState_old , ovrButton_Enter , K_ESCAPE ) ;
2020-09-08 22:10:45 +00:00
2020-11-15 18:52:37 +00:00
if ( inMenu | | inCinematic ) // Specific cases where we need to interact using mouse etc
2020-09-08 22:10:45 +00:00
{
2020-09-16 21:41:35 +00:00
controlMouse ( pDominantTrackedRemoteNew , pDominantTrackedRemoteOld ) ;
2020-09-11 21:41:18 +00:00
handleTrackedControllerButton_AsButton ( pDominantTrackedRemoteNew , pDominantTrackedRemoteOld , true , ovrButton_Trigger , 1 ) ;
2020-09-08 22:10:45 +00:00
}
2020-09-16 21:41:35 +00:00
2020-11-15 18:52:37 +00:00
/*if ( objectiveSystemActive )
2020-09-08 22:10:45 +00:00
{
2020-09-16 21:41:35 +00:00
controlMouse ( pDominantTrackedRemoteNew , pDominantTrackedRemoteOld ) ;
handleTrackedControllerButton_AsButton ( pDominantTrackedRemoteNew , pDominantTrackedRemoteOld , true , ovrButton_Trigger , 1 ) ;
if ( ( ( pOffTrackedRemoteNew - > Buttons & offButton1 ) ! = ( pOffTrackedRemoteOld - > Buttons & offButton1 ) ) & & ( pOffTrackedRemoteNew - > Buttons & offButton1 ) )
{
2020-11-15 18:52:37 +00:00
Android_SetImpulse ( UB_IMPULSE19 ) ;
2020-09-16 21:41:35 +00:00
}
2020-11-15 18:52:37 +00:00
} */
2020-09-08 22:10:45 +00:00
2020-09-16 21:41:35 +00:00
if ( ! inCinematic & & ! inMenu )
{
2020-09-08 22:10:45 +00:00
static bool canUseQuickSave = false ;
if ( pOffTracking - > Status & ( VRAPI_TRACKING_STATUS_POSITION_TRACKED | VRAPI_TRACKING_STATUS_POSITION_VALID ) ) {
canUseQuickSave = false ;
}
else if ( ! canUseQuickSave ) {
2020-09-23 18:34:14 +00:00
int channel = ( controlscheme > = 10 ) ? 1 : 0 ;
2020-11-15 18:52:37 +00:00
//Doom3Quest_Vibrate(channel, 0.5,0.5); // vibrate to let user know they can switch
2020-09-08 22:10:45 +00:00
canUseQuickSave = true ;
}
if ( canUseQuickSave )
{
if ( ( ( pOffTrackedRemoteNew - > Buttons & offButton1 ) ! =
( pOffTrackedRemoteOld - > Buttons & offButton1 ) ) & &
( pOffTrackedRemoteNew - > Buttons & offButton1 ) ) {
2020-09-11 21:41:18 +00:00
Android_SetCommand ( " savegame quick " ) ;
2020-09-08 22:10:45 +00:00
}
if ( ( ( pOffTrackedRemoteNew - > Buttons & offButton2 ) ! =
( pOffTrackedRemoteOld - > Buttons & offButton2 ) ) & &
( pOffTrackedRemoteNew - > Buttons & offButton2 ) ) {
2020-09-11 21:41:18 +00:00
Android_SetCommand ( " loadgame quick " ) ;
}
2020-09-15 23:02:29 +00:00
} else
{
//PDA
2020-09-11 21:41:18 +00:00
if ( ( ( pOffTrackedRemoteNew - > Buttons & offButton1 ) ! =
2020-09-15 23:02:29 +00:00
( pOffTrackedRemoteOld - > Buttons & offButton1 ) ) & &
( pOffTrackedRemoteNew - > Buttons & offButton1 ) ) {
2020-11-15 18:52:37 +00:00
Android_SetImpulse ( UB_IMPULSE19 ) ;
2020-09-20 21:56:36 +00:00
}
2020-09-08 22:10:45 +00:00
}
float distance = sqrtf ( powf ( pOff - > HeadPose . Pose . Position . x - pWeapon - > HeadPose . Pose . Position . x , 2 ) +
powf ( pOff - > HeadPose . Pose . Position . y - pWeapon - > HeadPose . Pose . Position . y , 2 ) +
powf ( pOff - > HeadPose . Pose . Position . z - pWeapon - > HeadPose . Pose . Position . z , 2 ) ) ;
//Turn on weapon stabilisation?
bool stabilised = false ;
if ( ! pVRClientInfo - > pistol & & // Don't stabilise pistols
( pOffTrackedRemoteNew - > Buttons & ovrButton_GripTrigger ) & & ( distance < STABILISATION_DISTANCE ) )
{
stabilised = true ;
}
pVRClientInfo - > weapon_stabilised = stabilised ;
//dominant hand stuff first
{
//Record recent weapon position for trajectory based stuff
2020-11-15 18:52:37 +00:00
/*
2020-09-08 22:10:45 +00:00
for ( int i = ( NUM_WEAPON_SAMPLES - 1 ) ; i ! = 0 ; - - i )
{
VectorCopy ( pVRClientInfo - > weaponoffset_history [ i - 1 ] , pVRClientInfo - > weaponoffset_history [ i ] ) ;
pVRClientInfo - > weaponoffset_history_timestamp [ i ] = pVRClientInfo - > weaponoffset_history_timestamp [ i - 1 ] ;
}
VectorCopy ( pVRClientInfo - > current_weaponoffset , pVRClientInfo - > weaponoffset_history [ 0 ] ) ;
pVRClientInfo - > weaponoffset_history_timestamp [ 0 ] = pVRClientInfo - > current_weaponoffset_timestamp ;
///Weapon location relative to view
pVRClientInfo - > current_weaponoffset [ 0 ] = pWeapon - > HeadPose . Pose . Position . x - pVRClientInfo - > hmdposition [ 0 ] ;
pVRClientInfo - > current_weaponoffset [ 1 ] = pWeapon - > HeadPose . Pose . Position . y - pVRClientInfo - > hmdposition [ 1 ] ;
pVRClientInfo - > current_weaponoffset [ 2 ] = pWeapon - > HeadPose . Pose . Position . z - pVRClientInfo - > hmdposition [ 2 ] ;
pVRClientInfo - > current_weaponoffset_timestamp = Sys_Milliseconds ( ) ;
2020-09-20 21:56:36 +00:00
{
//Caclulate speed between two historic controller position readings
float distance = VectorDistance ( pVRClientInfo - > weaponoffset_history [ NEWER_READING ] , pVRClientInfo - > weaponoffset_history [ OLDER_READING ] ) ;
float t = pVRClientInfo - > weaponoffset_history_timestamp [ NEWER_READING ] - pVRClientInfo - > weaponoffset_history_timestamp [ OLDER_READING ] ;
pVRClientInfo - > throw_power = distance / ( t / ( float ) 1000.0 ) ;
//Calculate trajectory
VectorSubtract ( pVRClientInfo - > weaponoffset_history [ NEWER_READING ] , pVRClientInfo - > weaponoffset_history [ OLDER_READING ] , pVRClientInfo - > throw_trajectory ) ;
VectorNormalize ( pVRClientInfo - > throw_trajectory ) ;
//Set origin to the newer reading offset
VectorCopy ( pVRClientInfo - > weaponoffset_history [ NEWER_READING ] , pVRClientInfo - > throw_origin ) ;
2020-11-15 18:52:37 +00:00
} */
2020-09-20 21:56:36 +00:00
2020-09-08 22:10:45 +00:00
//Does weapon velocity trigger attack (knife) and is it fast enough
static bool velocityTriggeredAttack = false ;
if ( pVRClientInfo - > velocitytriggered )
{
static bool fired = false ;
float velocity = sqrtf ( powf ( pWeapon - > HeadPose . LinearVelocity . x , 2 ) +
powf ( pWeapon - > HeadPose . LinearVelocity . y , 2 ) +
powf ( pWeapon - > HeadPose . LinearVelocity . z , 2 ) ) ;
velocityTriggeredAttack = ( velocity > VELOCITY_TRIGGER ) ;
if ( fired ! = velocityTriggeredAttack ) {
2020-11-15 18:52:37 +00:00
ALOGV ( " **WEAPON EVENT** velocity triggered %s " , velocityTriggeredAttack ? " +attack " : " -attack " ) ;
2020-09-17 21:46:48 +00:00
Android_ButtonChange ( UB_ATTACK , velocityTriggeredAttack ? 1 : 0 ) ;
2020-09-08 22:10:45 +00:00
fired = velocityTriggeredAttack ;
}
}
else if ( velocityTriggeredAttack )
{
//send a stop attack as we have an unfinished velocity attack
velocityTriggeredAttack = false ;
2020-11-15 18:52:37 +00:00
ALOGV ( " **WEAPON EVENT** velocity triggered -attack " ) ;
2020-09-17 21:46:48 +00:00
Android_ButtonChange ( UB_ATTACK , velocityTriggeredAttack ? 1 : 0 ) ;
2020-09-08 22:10:45 +00:00
}
2020-12-10 18:52:33 +00:00
//Does weapon velocity trigger attack (knife) and is it fast enough
static bool velocityTriggeredAttackOffHand = false ;
pVRClientInfo - > velocitytriggeredoffhandstate = false ;
if ( pVRClientInfo - > velocitytriggeredoffhand )
{
static bool firedOffHand = false ;
float velocity = sqrtf ( powf ( pOff - > HeadPose . LinearVelocity . x , 2 ) +
powf ( pOff - > HeadPose . LinearVelocity . y , 2 ) +
powf ( pOff - > HeadPose . LinearVelocity . z , 2 ) ) ;
velocityTriggeredAttackOffHand = ( velocity > VELOCITY_TRIGGER ) ;
if ( firedOffHand ! = velocityTriggeredAttackOffHand ) {
ALOGV ( " **WEAPON EVENT** velocity triggered (offhand) %s " , velocityTriggeredAttackOffHand ? " +attack " : " -attack " ) ;
//Android_ButtonChange(UB_IMPULSE37, velocityTriggeredAttackOffHand ? 1 : 0);
//Android_SetImpulse(UB_IMPULSE37);
pVRClientInfo - > velocitytriggeredoffhandstate = true ;
firedOffHand = velocityTriggeredAttackOffHand ;
}
}
else //GB This actually nevers gets run currently as we are always returning true for pVRClientInfo->velocitytriggeredoffhand (but we might not in the future when weapons are sorted)
{
//send a stop attack as we have an unfinished velocity attack
velocityTriggeredAttackOffHand = false ;
ALOGV ( " **WEAPON EVENT** velocity triggered -attack (offhand) " ) ;
//Android_ButtonChange(UB_IMPULSE37, velocityTriggeredAttackOffHand ? 1 : 0);
pVRClientInfo - > velocitytriggeredoffhandstate = false ;
}
2020-11-15 18:52:37 +00:00
/*if (pVRClientInfo->weapon_stabilised)
2020-09-08 22:10:45 +00:00
{
{
float x = pOff - > HeadPose . Pose . Position . x - pWeapon - > HeadPose . Pose . Position . x ;
float y = pOff - > HeadPose . Pose . Position . y - pWeapon - > HeadPose . Pose . Position . y ;
float z = pOff - > HeadPose . Pose . Position . z - pWeapon - > HeadPose . Pose . Position . z ;
float zxDist = length ( x , z ) ;
if ( zxDist ! = 0.0f & & z ! = 0.0f ) {
{
VectorSet ( pVRClientInfo - > weaponangles , - degrees ( atanf ( y / zxDist ) ) ,
- degrees ( atan2f ( x , - z ) ) , pVRClientInfo - > weaponangles [ ROLL ] / 2.0f ) ; //Dampen roll on stabilised weapon
}
}
}
2020-11-15 18:52:37 +00:00
} */
2020-09-08 22:10:45 +00:00
dominantGripPushed = ( pDominantTrackedRemoteNew - > Buttons &
ovrButton_GripTrigger ) ! = 0 ;
2020-09-17 22:50:54 +00:00
if ( dominantGripPushed ) {
2020-12-28 19:43:53 +00:00
if ( dominantGripPushTime = = 0 ) {
dominantGripPushTime = GetTimeInMilliSeconds ( ) ;
2020-09-08 22:10:45 +00:00
}
}
2020-09-17 22:50:54 +00:00
else
{
2020-12-28 19:43:53 +00:00
if ( ( GetTimeInMilliSeconds ( ) - dominantGripPushTime ) < vr_reloadtimeoutms ) {
2020-09-17 22:50:54 +00:00
//Reload
2020-11-15 18:52:37 +00:00
Android_SetImpulse ( UB_IMPULSE13 ) ;
2020-09-17 22:50:54 +00:00
}
dominantGripPushTime = 0 ;
}
2020-09-08 22:10:45 +00:00
}
float controllerYawHeading = 0.0f ;
2020-11-15 18:52:37 +00:00
//GBFP - off-hand stuff
{
pVRClientInfo - > offhandoffset_temp [ 0 ] = pOff - > HeadPose . Pose . Position . x - pVRClientInfo - > hmdposition [ 0 ] ;
pVRClientInfo - > offhandoffset_temp [ 1 ] = pOff - > HeadPose . Pose . Position . y - pVRClientInfo - > hmdposition [ 1 ] ;
pVRClientInfo - > offhandoffset_temp [ 2 ] = pOff - > HeadPose . Pose . Position . z - pVRClientInfo - > hmdposition [ 2 ] ;
vec3_t rotation = { 0 } ;
rotation [ PITCH ] = - 45 ;
QuatToYawPitchRoll ( pOff - > HeadPose . Pose . Orientation , rotation , pVRClientInfo - > offhandangles_temp ) ;
}
/*
2020-09-08 22:10:45 +00:00
//off-hand stuff
{
pVRClientInfo - > offhandoffset [ 0 ] = pOff - > HeadPose . Pose . Position . x - pVRClientInfo - > hmdposition [ 0 ] ;
pVRClientInfo - > offhandoffset [ 1 ] = pOff - > HeadPose . Pose . Position . y - pVRClientInfo - > hmdposition [ 1 ] ;
pVRClientInfo - > offhandoffset [ 2 ] = pOff - > HeadPose . Pose . Position . z - pVRClientInfo - > hmdposition [ 2 ] ;
vec3_t rotation = { 0 } ;
2020-09-24 23:10:19 +00:00
rotation [ PITCH ] = - 45 ;
2020-09-08 22:10:45 +00:00
QuatToYawPitchRoll ( pOff - > HeadPose . Pose . Orientation , rotation , pVRClientInfo - > offhandangles ) ;
if ( vr_walkdirection = = 0 ) {
controllerYawHeading = pVRClientInfo - > offhandangles [ YAW ] - pVRClientInfo - > hmdorientation [ YAW ] ;
}
else
{
controllerYawHeading = 0.0f ;
}
2020-11-15 18:52:37 +00:00
} */
2020-09-08 22:10:45 +00:00
//Right-hand specific stuff
{
2020-09-13 09:36:58 +00:00
//Adjust positional factor for this sample based on how long the last frame took, it should
//approximately even out the positional movement on a per frame basis (especially when fps is much lower than 60)
2020-11-15 18:52:37 +00:00
/*
2020-09-13 09:36:58 +00:00
static float lastSampleTime = 0 ;
float sampleTime = Sys_Milliseconds ( ) ;
2020-10-16 19:45:26 +00:00
float vr_positional_factor = 2400.0f * ( ( 1000.0f / ( float ) Doom3Quest_GetRefresh ( ) ) / ( sampleTime - lastSampleTime ) ) ;
2020-09-13 09:36:58 +00:00
lastSampleTime = sampleTime ;
2020-09-08 22:10:45 +00:00
//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
2020-11-15 18:52:37 +00:00
2020-09-08 22:10:45 +00:00
vec2_t v ;
rotateAboutOrigin ( - pVRClientInfo - > hmdposition_delta [ 0 ] * vr_positional_factor ,
pVRClientInfo - > hmdposition_delta [ 2 ] * vr_positional_factor , - pVRClientInfo - > hmdorientation [ YAW ] , v ) ;
positional_movementSideways = v [ 0 ] ;
positional_movementForward = v [ 1 ] ;
2020-11-15 18:52:37 +00:00
*/
2020-09-08 22:10:45 +00:00
//Jump (B Button)
2020-12-28 19:43:53 +00:00
if ( ( primaryButtonsNew & primaryButton2 ) ! = ( primaryButtonsOld & primaryButton2 ) )
{
handleTrackedControllerButton_AsButton ( pDominantTrackedRemoteNew , pDominantTrackedRemoteOld , false , primaryButton2 , UB_UP ) ;
2020-09-08 22:10:45 +00:00
}
2020-09-11 21:41:18 +00:00
//Fire Primary
2020-12-28 19:43:53 +00:00
if ( ( pDominantTrackedRemoteNew - > Buttons & ovrButton_Trigger ) ! =
2020-09-11 21:41:18 +00:00
( pDominantTrackedRemoteOld - > Buttons & ovrButton_Trigger ) ) {
2020-09-08 22:10:45 +00:00
2020-09-11 21:41:18 +00:00
ALOGV ( " **WEAPON EVENT** Not Grip Pushed %sattack " , ( pDominantTrackedRemoteNew - > Buttons & ovrButton_Trigger ) ? " + " : " - " ) ;
2020-09-09 22:16:24 +00:00
2020-09-11 21:41:18 +00:00
handleTrackedControllerButton_AsButton ( pDominantTrackedRemoteNew , pDominantTrackedRemoteOld , false , ovrButton_Trigger , UB_ATTACK ) ;
2020-09-08 22:10:45 +00:00
}
//Duck
2020-12-28 19:43:53 +00:00
if ( ( primaryButtonsNew & primaryButton1 ) ! =
2020-09-08 22:10:45 +00:00
( primaryButtonsOld & primaryButton1 ) ) {
2020-09-11 21:41:18 +00:00
handleTrackedControllerButton_AsToggleButton ( pDominantTrackedRemoteNew , pDominantTrackedRemoteOld , primaryButton1 , UB_DOWN ) ;
2020-09-08 22:10:45 +00:00
}
//Weapon Chooser
static bool itemSwitched = false ;
if ( between ( - 0.2f , pPrimaryJoystick - > x , 0.2f ) & &
( between ( 0.8f , pPrimaryJoystick - > y , 1.0f ) | |
between ( - 1.0f , pPrimaryJoystick - > y , - 0.8f ) ) )
{
if ( ! itemSwitched ) {
if ( between ( 0.8f , pPrimaryJoystick - > y , 1.0f ) )
{
2020-09-11 21:41:18 +00:00
//Previous Weapon
2020-11-15 18:52:37 +00:00
Android_SetImpulse ( UB_IMPULSE15 ) ;
2020-09-08 22:10:45 +00:00
}
else
{
2020-09-11 21:41:18 +00:00
//Next Weapon
2020-11-15 18:52:37 +00:00
Android_SetImpulse ( UB_IMPULSE14 ) ;
2020-09-08 22:10:45 +00:00
}
itemSwitched = true ;
}
} else {
itemSwitched = false ;
}
}
{
//Apply a filter and quadratic scaler so small movements are easier to make
float dist = length ( pSecondaryJoystick - > x , pSecondaryJoystick - > y ) ;
float nlf = nonLinearFilter ( dist ) ;
float x = nlf * pSecondaryJoystick - > x ;
float y = nlf * pSecondaryJoystick - > y ;
pVRClientInfo - > 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
2020-09-23 18:34:14 +00:00
float vr_movement_multiplier = 127 ;
2020-09-16 21:41:35 +00:00
remote_movementSideways = v [ 0 ] * vr_movement_multiplier ;
remote_movementForward = v [ 1 ] * vr_movement_multiplier ;
2020-09-08 22:10:45 +00:00
if ( ! canUseQuickSave ) {
2020-11-15 18:52:37 +00:00
if ( ( ( secondaryButtonsNew & secondaryButton2 ) ! =
( secondaryButtonsOld & secondaryButton2 ) ) & &
( secondaryButtonsNew & secondaryButton2 ) ) {
2020-09-08 22:10:45 +00:00
if ( dominantGripPushed ) {
2020-09-11 21:41:18 +00:00
Android_SetCommand ( " give all " ) ;
2020-09-08 22:10:45 +00:00
}
}
}
2020-09-16 21:41:35 +00:00
if ( ( ( pOffTrackedRemoteNew - > Buttons & ovrButton_Joystick ) ! =
( pOffTrackedRemoteOld - > Buttons & ovrButton_Joystick ) ) & &
( pOffTrackedRemoteOld - > Buttons & ovrButton_Joystick ) ) {
2020-09-11 21:41:18 +00:00
2020-12-28 19:43:53 +00:00
//forceVirtualScreen = !forceVirtualScreen;
2020-09-16 21:41:35 +00:00
pVRClientInfo - > visible_hud = ! pVRClientInfo - > visible_hud ;
2020-11-15 18:52:37 +00:00
//Turn on Flashlight
Android_SetImpulse ( UB_IMPULSE16 ) ;
2020-09-08 22:10:45 +00:00
}
//We need to record if we have started firing primary so that releasing trigger will stop definitely firing, if user has pushed grip
//in meantime, then it wouldn't stop the gun firing and it would get stuck
2020-11-15 18:52:37 +00:00
handleTrackedControllerButton_AsButton ( pOffTrackedRemoteNew , pOffTrackedRemoteOld , false , ovrButton_Trigger , UB_SPEED ) ;
2020-09-08 22:10:45 +00:00
2020-09-23 18:34:14 +00:00
int vr_turn_mode = Android_GetCVarInteger ( " vr_turnmode " ) ;
float vr_turn_angle = Android_GetCVarInteger ( " vr_turnangle " ) ;
2020-09-08 22:10:45 +00:00
//No snap turn when using mounted gun
2020-12-10 18:52:33 +00:00
snapTurn = 0 ;
2020-09-08 22:10:45 +00:00
static int increaseSnap = true ;
2020-09-16 21:41:35 +00:00
{
2020-09-08 22:10:45 +00:00
if ( pPrimaryJoystick - > x > 0.7f ) {
if ( increaseSnap ) {
float turnAngle = vr_turn_mode ? ( vr_turn_angle / 9.0f ) : vr_turn_angle ;
snapTurn - = turnAngle ;
if ( vr_turn_mode = = 0 ) {
increaseSnap = false ;
}
if ( snapTurn < - 180.0f ) {
snapTurn + = 360.f ;
}
2020-11-15 18:52:37 +00:00
} else {
snapTurn = 0 ;
2020-09-08 22:10:45 +00:00
}
} else if ( pPrimaryJoystick - > x < 0.3f ) {
increaseSnap = true ;
}
static int decreaseSnap = true ;
if ( pPrimaryJoystick - > x < - 0.7f ) {
if ( decreaseSnap ) {
float turnAngle = vr_turn_mode ? ( vr_turn_angle / 9.0f ) : vr_turn_angle ;
snapTurn + = turnAngle ;
//If snap turn configured for less than 10 degrees
if ( vr_turn_mode = = 0 ) {
decreaseSnap = false ;
}
if ( snapTurn > 180.0f ) {
snapTurn - = 360.f ;
}
2020-11-15 18:52:37 +00:00
} else {
snapTurn = 0 ;
2020-09-08 22:10:45 +00:00
}
} else if ( pPrimaryJoystick - > x > - 0.3f ) {
decreaseSnap = true ;
}
}
}
}
//Save state
rightTrackedRemoteState_old = rightTrackedRemoteState_new ;
leftTrackedRemoteState_old = leftTrackedRemoteState_new ;
}