From f8ab514d5c37ef394acae3f91aa08633c79aed1b Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 16 May 2021 19:35:30 +0100 Subject: [PATCH] Merged @Baggyg's changes for Cybershoes support --- .../Android/jni/QzDoom/QzDoom_SurfaceView.c | 8 ++- Projects/Android/jni/QzDoom/VrInput.h | 7 ++- Projects/Android/jni/QzDoom/VrInputCommon.c | 61 ++++++++++++------- Projects/Android/jni/QzDoom/VrInputDefault.c | 7 ++- 4 files changed, 55 insertions(+), 28 deletions(-) diff --git a/Projects/Android/jni/QzDoom/QzDoom_SurfaceView.c b/Projects/Android/jni/QzDoom/QzDoom_SurfaceView.c index 369e691..c5bf347 100644 --- a/Projects/Android/jni/QzDoom/QzDoom_SurfaceView.c +++ b/Projects/Android/jni/QzDoom/QzDoom_SurfaceView.c @@ -1629,13 +1629,17 @@ void QzDoom_getTrackedRemotesOrientation(int vr_control_scheme) {//Get info for switch ((int)vr_control_scheme) { case RIGHT_HANDED_DEFAULT: - HandleInput_Default(vr_control_scheme, &rightTrackedRemoteState_new, &rightTrackedRemoteState_old, &rightRemoteTracking_new, + HandleInput_Default(vr_control_scheme, + &footTrackedRemoteState_new, &footTrackedRemoteState_old, + &rightTrackedRemoteState_new, &rightTrackedRemoteState_old, &rightRemoteTracking_new, &leftTrackedRemoteState_new, &leftTrackedRemoteState_old, &leftRemoteTracking_new, ovrButton_A, ovrButton_B, ovrButton_X, ovrButton_Y); break; case LEFT_HANDED_DEFAULT: case LEFT_HANDED_ALT: - HandleInput_Default(vr_control_scheme, &leftTrackedRemoteState_new, &leftTrackedRemoteState_old, &leftRemoteTracking_new, + HandleInput_Default(vr_control_scheme, + &footTrackedRemoteState_new, &footTrackedRemoteState_old, + &leftTrackedRemoteState_new, &leftTrackedRemoteState_old, &leftRemoteTracking_new, &rightTrackedRemoteState_new, &rightTrackedRemoteState_old, &rightRemoteTracking_new, ovrButton_X, ovrButton_Y, ovrButton_A, ovrButton_B); break; diff --git a/Projects/Android/jni/QzDoom/VrInput.h b/Projects/Android/jni/QzDoom/VrInput.h index a4783af..2ec3fd8 100644 --- a/Projects/Android/jni/QzDoom/VrInput.h +++ b/Projects/Android/jni/QzDoom/VrInput.h @@ -12,6 +12,10 @@ ovrInputStateTrackedRemote rightTrackedRemoteState_old; ovrInputStateTrackedRemote rightTrackedRemoteState_new; ovrTracking rightRemoteTracking_new; +ovrInputStateGamepad footTrackedRemoteState_old; +ovrInputStateGamepad footTrackedRemoteState_new; + + ovrDeviceID controllerIDs[2]; float remote_movementSideways; @@ -26,7 +30,8 @@ float cinemamodePitch; void acquireTrackedRemotesData(const ovrMobile *Ovr, double displayTime); -void HandleInput_Default( int control_scheme, ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTracking* pDominantTracking, +void HandleInput_Default( int control_scheme, ovrInputStateGamepad *pFootTrackingNew, ovrInputStateGamepad *pFootTrackingOld, ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, + ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTracking* pDominantTracking, ovrInputStateTrackedRemote *pOffTrackedRemoteNew, ovrInputStateTrackedRemote *pOffTrackedRemoteOld, ovrTracking* pOffTracking, int domButton1, int domButton2, int offButton1, int offButton2 ); diff --git a/Projects/Android/jni/QzDoom/VrInputCommon.c b/Projects/Android/jni/QzDoom/VrInputCommon.c index 7521ad3..ae3fc2d 100644 --- a/Projects/Android/jni/QzDoom/VrInputCommon.c +++ b/Projects/Android/jni/QzDoom/VrInputCommon.c @@ -84,34 +84,51 @@ bool between(float min, float val, float max) void acquireTrackedRemotesData(const ovrMobile *Ovr, double displayTime) {//The amount of yaw changed by controller for ( int i = 0; ; i++ ) { - ovrInputCapabilityHeader cap; - ovrResult result = vrapi_EnumerateInputDevices(Ovr, i, &cap); + ovrInputCapabilityHeader capsHeader; + ovrResult result = vrapi_EnumerateInputDevices(Ovr, i, &capsHeader); if (result < 0) { break; } - if (cap.Type == ovrControllerType_TrackedRemote) { + if (capsHeader.Type == ovrControllerType_Gamepad) { + + ovrInputGamepadCapabilities remoteCaps; + remoteCaps.Header = capsHeader; + if (vrapi_GetInputDeviceCapabilities(Ovr, &remoteCaps.Header) >= 0) { + // remote is connected + ovrInputStateGamepad remoteState; + remoteState.Header.ControllerType = ovrControllerType_Gamepad; + if ( vrapi_GetCurrentInputState( Ovr, capsHeader.DeviceID, &remoteState.Header ) >= 0 ) + { + // act on device state returned in remoteState + footTrackedRemoteState_new = remoteState; + } + } + } + else if (capsHeader.Type == ovrControllerType_TrackedRemote) { ovrTracking remoteTracking; - ovrInputStateTrackedRemote trackedRemoteState; - trackedRemoteState.Header.ControllerType = ovrControllerType_TrackedRemote; - result = vrapi_GetCurrentInputState(Ovr, cap.DeviceID, &trackedRemoteState.Header); + ovrInputTrackedRemoteCapabilities remoteCaps; + remoteCaps.Header = capsHeader; + if ( vrapi_GetInputDeviceCapabilities( Ovr, &remoteCaps.Header ) >= 0 ) + { + // remote is connected + ovrInputStateTrackedRemote remoteState; + remoteState.Header.ControllerType = ovrControllerType_TrackedRemote; - if (result == ovrSuccess) { - ovrInputTrackedRemoteCapabilities remoteCapabilities; - remoteCapabilities.Header = cap; - result = vrapi_GetInputDeviceCapabilities(Ovr, &remoteCapabilities.Header); - - result = vrapi_GetInputTrackingState(Ovr, cap.DeviceID, displayTime, - &remoteTracking); - - if (remoteCapabilities.ControllerCapabilities & ovrControllerCaps_RightHand) { - rightTrackedRemoteState_new = trackedRemoteState; - rightRemoteTracking_new = remoteTracking; - controllerIDs[1] = cap.DeviceID; - } else{ - leftTrackedRemoteState_new = trackedRemoteState; - leftRemoteTracking_new = remoteTracking; - controllerIDs[0] = cap.DeviceID; + if(vrapi_GetCurrentInputState(Ovr, capsHeader.DeviceID, &remoteState.Header) >= 0) { + if (vrapi_GetInputTrackingState(Ovr, capsHeader.DeviceID, displayTime, + &remoteTracking) >= 0) { + // act on device state returned in remoteState + if (remoteCaps.ControllerCapabilities & ovrControllerCaps_RightHand) { + rightTrackedRemoteState_new = remoteState; + rightRemoteTracking_new = remoteTracking; + controllerIDs[1] = capsHeader.DeviceID; + } else { + leftTrackedRemoteState_new = remoteState; + leftRemoteTracking_new = remoteTracking; + controllerIDs[0] = capsHeader.DeviceID; + } + } } } } diff --git a/Projects/Android/jni/QzDoom/VrInputDefault.c b/Projects/Android/jni/QzDoom/VrInputDefault.c index bc6a732..d334183 100644 --- a/Projects/Android/jni/QzDoom/VrInputDefault.c +++ b/Projects/Android/jni/QzDoom/VrInputDefault.c @@ -23,7 +23,8 @@ int getMenuState(); void Joy_GenerateButtonEvents(int oldbuttons, int newbuttons, int numbuttons, int base); float getViewpointYaw(); -void HandleInput_Default( int control_scheme, ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTracking* pDominantTracking, +void HandleInput_Default( int control_scheme, ovrInputStateGamepad *pFootTrackingNew, ovrInputStateGamepad *pFootTrackingOld, + ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTracking* pDominantTracking, ovrInputStateTrackedRemote *pOffTrackedRemoteNew, ovrInputStateTrackedRemote *pOffTrackedRemoteOld, ovrTracking* pOffTracking, int domButton1, int domButton2, int offButton1, int offButton2 ) @@ -243,8 +244,8 @@ void HandleInput_Default( int control_scheme, ovrInputStateTrackedRemote *pDomin //and we don't get movement jitter when the joystick doesn't quite center properly float dist = length(pSecondaryTrackedRemoteNew->Joystick.x, pSecondaryTrackedRemoteNew->Joystick.y); float nlf = nonLinearFilter(dist); - float x = nlf * pSecondaryTrackedRemoteNew->Joystick.x; - float y = nlf * pSecondaryTrackedRemoteNew->Joystick.y; + float x = nlf * pSecondaryTrackedRemoteNew->Joystick.x + pFootTrackingNew->LeftJoystick.x; + float y = nlf * pSecondaryTrackedRemoteNew->Joystick.y - pFootTrackingNew->LeftJoystick.y; //Apply a simple deadzone player_moving = (fabs(x) + fabs(y)) > 0.05f;