diff --git a/Projects/Android/jni/RTCWVR/VrCommon.h b/Projects/Android/jni/RTCWVR/VrCommon.h index 948ca0d..7e6adcd 100644 --- a/Projects/Android/jni/RTCWVR/VrCommon.h +++ b/Projects/Android/jni/RTCWVR/VrCommon.h @@ -53,7 +53,7 @@ qboolean between(float min, float val, float max); void rotateAboutOrigin(float v1, float v2, float rotation, vec2_t out); void QuatToYawPitchRoll(ovrQuatf q, vec3_t rotation, vec3_t out); void handleTrackedControllerButton(ovrInputStateTrackedRemote * trackedRemoteState, ovrInputStateTrackedRemote * prevTrackedRemoteState, uint32_t button, int key); -void interactWithTouchScreen(qboolean reset, ovrInputStateTrackedRemote *newState, ovrInputStateTrackedRemote *oldState); +void interactWithTouchScreen(float menuYaw, vec3_t controllerAngles); int GetRefresh(); //Called from engine code diff --git a/Projects/Android/jni/RTCWVR/VrInputCommon.c b/Projects/Android/jni/RTCWVR/VrInputCommon.c index 7bded56..d1ab838 100644 --- a/Projects/Android/jni/RTCWVR/VrInputCommon.c +++ b/Projects/Android/jni/RTCWVR/VrInputCommon.c @@ -171,20 +171,9 @@ inline float clamp(float _min, float _val, float _max) return max(min(_val, _max), _min); } -void interactWithTouchScreen(qboolean reset, ovrInputStateTrackedRemote *newState, ovrInputStateTrackedRemote *oldState) { - static float cursorX = 0.25f; - static float cursorY = 0.125f; - - if (reset) - { - cursorX = 0.25f; - cursorY = 0.125f; - } - - cursorX += (float)(vr.weaponangles_delta[YAW] / 180.0); - cursorX = clamp(0.0, cursorX, 0.5); - cursorY += (float)(-vr.weaponangles_delta[PITCH] / 220.0); - cursorY = clamp(0.0, cursorY, 0.4); +void interactWithTouchScreen(float menuYaw, vec3_t controllerAngles) { + float cursorX = -sinf(DEG2RAD(controllerAngles[YAW] - menuYaw)) + 0.5f; + float cursorY = (float)(controllerAngles[PITCH] / 90.0) + 0.5f; PortableMouseAbs(cursorX, cursorY); } \ No newline at end of file diff --git a/Projects/Android/jni/RTCWVR/VrInputDefault.c b/Projects/Android/jni/RTCWVR/VrInputDefault.c index c30b4f2..6d64319 100644 --- a/Projects/Android/jni/RTCWVR/VrInputDefault.c +++ b/Projects/Android/jni/RTCWVR/VrInputDefault.c @@ -132,19 +132,32 @@ void HandleInput_Default( ovrInputStateGamepad *pFootTrackingNew, ovrInputStateG //Menu button handleTrackedControllerButton(&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, ovrButton_Enter, K_ESCAPE); - static qboolean resetCursor = qtrue; + static float menuYaw = 0; + static bool switchedMenuControls = qfalse; if ( RTCWVR_useScreenLayer() ) { - interactWithTouchScreen(resetCursor, pDominantTrackedRemoteNew, pDominantTrackedRemoteOld); - resetCursor = qfalse; - - handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton1, K_MOUSE1); - handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, ovrButton_Trigger, K_MOUSE1); - handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton2, K_ESCAPE); + bool controlsLeftHanded = vr_control_scheme->integer >= 10; + if ((controlsLeftHanded && !switchedMenuControls) || (!controlsLeftHanded && switchedMenuControls)) { + interactWithTouchScreen(menuYaw, vr.offhandangles); + handleTrackedControllerButton(pOffTrackedRemoteNew, pOffTrackedRemoteOld, offButton1, K_MOUSE1); + handleTrackedControllerButton(pOffTrackedRemoteNew, pOffTrackedRemoteOld, ovrButton_Trigger, K_MOUSE1); + handleTrackedControllerButton(pOffTrackedRemoteNew, pOffTrackedRemoteOld, offButton2, K_ESCAPE); + if ((pDominantTrackedRemoteNew->Buttons & ovrButton_Trigger) != (pDominantTrackedRemoteOld->Buttons & ovrButton_Trigger) && (pDominantTrackedRemoteNew->Buttons & ovrButton_Trigger)) { + switchedMenuControls = !switchedMenuControls; + } + } else { + interactWithTouchScreen(menuYaw, vr.weaponangles); + handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton1, K_MOUSE1); + handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, ovrButton_Trigger, K_MOUSE1); + handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton2, K_ESCAPE); + if ((pOffTrackedRemoteNew->Buttons & ovrButton_Trigger) != (pOffTrackedRemoteOld->Buttons & ovrButton_Trigger) && (pOffTrackedRemoteNew->Buttons & ovrButton_Trigger)) { + switchedMenuControls = !switchedMenuControls; + } + } } else { - resetCursor = qtrue; + menuYaw = vr.hmdorientation[YAW]; 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) + diff --git a/Projects/Android/jni/RTCWVR/VrInputWeaponAlign.c b/Projects/Android/jni/RTCWVR/VrInputWeaponAlign.c index f552edb..81ffe9a 100644 --- a/Projects/Android/jni/RTCWVR/VrInputWeaponAlign.c +++ b/Projects/Android/jni/RTCWVR/VrInputWeaponAlign.c @@ -64,19 +64,32 @@ void HandleInput_WeaponAlign( ovrInputStateTrackedRemote *pDominantTrackedRemote //Menu button handleTrackedControllerButton(&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, ovrButton_Enter, K_ESCAPE); - static qboolean resetCursor = qtrue; + static float menuYaw = 0; + static bool switchedMenuControls = qfalse; if ( RTCWVR_useScreenLayer() ) { - interactWithTouchScreen(resetCursor, pDominantTrackedRemoteNew, pDominantTrackedRemoteOld); - resetCursor = qfalse; - - handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton1, K_MOUSE1); - handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, ovrButton_Trigger, K_MOUSE1); - handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton2, K_ESCAPE); + bool controlsLeftHanded = vr_control_scheme->integer >= 10; + if ((controlsLeftHanded && !switchedMenuControls) || (!controlsLeftHanded && switchedMenuControls)) { + interactWithTouchScreen(menuYaw, vr.offhandangles); + handleTrackedControllerButton(pOffTrackedRemoteNew, pOffTrackedRemoteOld, offButton1, K_MOUSE1); + handleTrackedControllerButton(pOffTrackedRemoteNew, pOffTrackedRemoteOld, ovrButton_Trigger, K_MOUSE1); + handleTrackedControllerButton(pOffTrackedRemoteNew, pOffTrackedRemoteOld, offButton2, K_ESCAPE); + if ((pDominantTrackedRemoteNew->Buttons & ovrButton_Trigger) != (pDominantTrackedRemoteOld->Buttons & ovrButton_Trigger) && (pDominantTrackedRemoteNew->Buttons & ovrButton_Trigger)) { + switchedMenuControls = !switchedMenuControls; + } + } else { + interactWithTouchScreen(menuYaw, vr.weaponangles); + handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton1, K_MOUSE1); + handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, ovrButton_Trigger, K_MOUSE1); + handleTrackedControllerButton(pDominantTrackedRemoteNew, pDominantTrackedRemoteOld, domButton2, K_ESCAPE); + if ((pOffTrackedRemoteNew->Buttons & ovrButton_Trigger) != (pOffTrackedRemoteOld->Buttons & ovrButton_Trigger) && (pOffTrackedRemoteNew->Buttons & ovrButton_Trigger)) { + switchedMenuControls = !switchedMenuControls; + } + } } else { - resetCursor = qtrue; + menuYaw = vr.hmdorientation[YAW]; //dominant hand stuff first { diff --git a/Projects/Android/jni/rtcw/src/android/in_android.c b/Projects/Android/jni/rtcw/src/android/in_android.c index 597c8d6..0687561 100644 --- a/Projects/Android/jni/rtcw/src/android/in_android.c +++ b/Projects/Android/jni/rtcw/src/android/in_android.c @@ -228,11 +228,8 @@ int absx=0,absy=0; RTCWVR_GetScreenRes(int *width, int *height); void PortableMouseAbs(float x,float y) { - int width; - int height; - RTCWVR_GetScreenRes(&width, &height); - absx = x * width; - absy = y * height; + absx = x * 640; + absy = y * 480; } diff --git a/Projects/Android/jni/rtcw/src/ui/ui_main.c b/Projects/Android/jni/rtcw/src/ui/ui_main.c index 2164cba..93e119a 100644 --- a/Projects/Android/jni/rtcw/src/ui/ui_main.c +++ b/Projects/Android/jni/rtcw/src/ui/ui_main.c @@ -6782,20 +6782,22 @@ void _UI_MouseEvent( int dx, int dy ) { UI_MouseEvent ================= */ +const int cursorSize = 16; void _UI_MouseEventAbs( int x, int y ) { // update mouse screen position + // allow to hide cursor beyond the screen edges uiInfo.uiDC.cursorx = x; - if ( uiInfo.uiDC.cursorx < 0 ) { - uiInfo.uiDC.cursorx = 0; - } else if ( uiInfo.uiDC.cursorx > SCREEN_WIDTH ) { - uiInfo.uiDC.cursorx = SCREEN_WIDTH; + if ( uiInfo.uiDC.cursorx < -cursorSize ) { + uiInfo.uiDC.cursorx = -cursorSize; + } else if ( uiInfo.uiDC.cursorx > SCREEN_WIDTH + cursorSize ) { + uiInfo.uiDC.cursorx = SCREEN_WIDTH + cursorSize; } uiInfo.uiDC.cursory = y; - if ( uiInfo.uiDC.cursory < 0 ) { - uiInfo.uiDC.cursory = 0; - } else if ( uiInfo.uiDC.cursory > SCREEN_HEIGHT ) { - uiInfo.uiDC.cursory = SCREEN_HEIGHT; + if ( uiInfo.uiDC.cursory < -cursorSize ) { + uiInfo.uiDC.cursory = -cursorSize; + } else if ( uiInfo.uiDC.cursory > SCREEN_HEIGHT + cursorSize) { + uiInfo.uiDC.cursory = SCREEN_HEIGHT + cursorSize; } if ( Menu_Count() > 0 ) {