diff --git a/Projects/Android/jni/OpenJK/JKXR/OpenXrInput.cpp b/Projects/Android/jni/OpenJK/JKXR/OpenXrInput.cpp index a627c15..926b6c2 100644 --- a/Projects/Android/jni/OpenJK/JKXR/OpenXrInput.cpp +++ b/Projects/Android/jni/OpenJK/JKXR/OpenXrInput.cpp @@ -16,14 +16,6 @@ XrResult CheckXrResult(XrResult res, const char* originator) { #define SIDE_RIGHT 1 #define SIDE_COUNT 2 -#define VIVE_CONTROLLERS 10 -#define INDEX_CONTROLLERS 11 -#define PICO_CONTROLLERS 12 -#define TOUCH_CONTROLLERS 13 -//Anything else will emulate touch - -int controllersPresent; - XrActionSet actionSet = nullptr; XrAction grabAction; XrAction gripAction; @@ -698,9 +690,6 @@ void TBXR_InitActions( void ) CHECK_XRCMD(xrAttachSessionActionSets(gAppState.Session, &attachInfo)); - - - } void TBXR_SyncActions( void ) @@ -719,10 +708,57 @@ void TBXR_SyncActions( void ) } } +void TBXR_CheckControllers(void) +{ + if (gAppState.controllersPresent == -1) + { + XrInteractionProfileState profileState = { XR_TYPE_INTERACTION_PROFILE_STATE }; + XrResult _res = CHECK_XRCMD(xrGetCurrentInteractionProfile(gAppState.Session, handSubactionPath[SIDE_RIGHT], &profileState)); + if (profileState.interactionProfile != XR_NULL_PATH) + { + uint32_t bufferLength = 0; + XrResult result = xrPathToString(gAppState.Instance, profileState.interactionProfile, 0, &bufferLength, nullptr); + + if (result == XR_SUCCESS) { + // Allocate a buffer to store the string + char* pathString = new char[bufferLength]; + + // Convert XrPath to a string + result = xrPathToString(gAppState.Instance, profileState.interactionProfile, bufferLength, &bufferLength, pathString); + if (result == XR_SUCCESS) { + + Com_Printf("Controllers Found: %s", pathString); + + if (strcmp(pathString, "/interaction_profiles/valve/index_controller") == 0) + { + gAppState.controllersPresent = INDEX_CONTROLLERS; + } + else if (strcmp(pathString, "/interaction_profiles/htc/vive_controller") == 0) + { + gAppState.controllersPresent = VIVE_CONTROLLERS; + } + else if (strcmp(pathString, "/interaction_profiles/oculus/touch_controller") == 0) + { + gAppState.controllersPresent = TOUCH_CONTROLLERS; + } + else if (strcmp(pathString, "/interaction_profiles/bytedance/pico4_controller") == 0 || + strcmp(pathString, "/interaction_profiles/bytedance/pico3_controller") == 0) + { + gAppState.controllersPresent = PICO_CONTROLLERS; + } + } + + + } + } + } +} + void TBXR_UpdateControllers( ) { + TBXR_CheckControllers(); TBXR_SyncActions(); - + //get controller poses for (int i = 0; i < 2; i++) { XrSpaceVelocity vel = {}; @@ -848,7 +884,7 @@ void TBXR_ProcessHaptics() { vibration.amplitude = vibration_channel_intensity[i]; vibration.duration = ToXrTime(vibration_channel_duration[i]); - if(controllersPresent == VIVE_CONTROLLERS) + if(gAppState.controllersPresent == VIVE_CONTROLLERS) vibration.duration /= 100; //Lets see what happens when the runtime decides it (as per https://registry.khronos.org/OpenXR/specs/1.0/man/html/XrHapticVibration.html) diff --git a/Projects/Android/jni/OpenJK/JKXR/VrInputDefault.cpp b/Projects/Android/jni/OpenJK/JKXR/VrInputDefault.cpp index 1e3a523..11511a1 100644 --- a/Projects/Android/jni/OpenJK/JKXR/VrInputDefault.cpp +++ b/Projects/Android/jni/OpenJK/JKXR/VrInputDefault.cpp @@ -136,8 +136,9 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, QuatToYawPitchRoll(pOff->Pose.orientation, rotation, vr.offhandangles[ANGLES_DEFAULT]); //If we are in a saberBlockDebounce thing then add on an angle - //Lerped upon how far from the start of the saber move - rotation[PITCH] = vr_saber_pitchadjust->value; + //Lerped upon how far from the start of the saber move + //Index default -> vr_saber_pitchadjust->value = -2.42187500 + rotation[PITCH] = vr_saber_pitchadjust->value + (gAppState.controllersPresent == INDEX_CONTROLLERS ? 10.938125f : 0.0f); if (vr.saberBlockDebounce > cl.serverTime) { float lerp = 0.0f; //Where are we in the lerp @@ -198,7 +199,7 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, QuatToYawPitchRoll(pWeapon->GripPose.orientation, rotation, vr.weaponangles[ANGLES_SABER]); QuatToYawPitchRoll(pOff->GripPose.orientation, rotation, vr.offhandangles[ANGLES_SABER]); - + // + (gAppState.controllersPresent == INDEX_CONTROLLERS ? -35 rotation[PITCH] = vr_weapon_pitchadjust->value; QuatToYawPitchRoll(pWeapon->Pose.orientation, rotation, vr.weaponangles[ANGLES_ADJUSTED]); QuatToYawPitchRoll(pOff->Pose.orientation, rotation, vr.offhandangles[ANGLES_ADJUSTED]); diff --git a/Projects/Android/jni/OpenJK/JKXR/VrInputWeaponAlign.cpp b/Projects/Android/jni/OpenJK/JKXR/VrInputWeaponAlign.cpp index 441c96f..dcf6d8d 100644 --- a/Projects/Android/jni/OpenJK/JKXR/VrInputWeaponAlign.cpp +++ b/Projects/Android/jni/OpenJK/JKXR/VrInputWeaponAlign.cpp @@ -45,7 +45,7 @@ void HandleInput_WeaponAlign( ovrInputStateTrackedRemote *pDominantTrackedRemote //if we are in saber block debounce, don't update the saber angles if (vr.saberBlockDebounce < cl.serverTime) { - rotation[PITCH] = vr_saber_pitchadjust->value; + rotation[PITCH] = vr_saber_pitchadjust->value + (gAppState.controllersPresent == INDEX_CONTROLLERS ? 10.938125f : 0.0f); QuatToYawPitchRoll(pDominantTracking->GripPose.orientation, rotation, vr.weaponangles[ANGLES_SABER]); QuatToYawPitchRoll(pOffTracking->GripPose.orientation, rotation, vr.offhandangles[ANGLES_SABER]); } diff --git a/Projects/Android/jni/OpenJK/JKXR/windows/TBXR_Common.h b/Projects/Android/jni/OpenJK/JKXR/windows/TBXR_Common.h index b13cef9..8990769 100644 --- a/Projects/Android/jni/OpenJK/JKXR/windows/TBXR_Common.h +++ b/Projects/Android/jni/OpenJK/JKXR/windows/TBXR_Common.h @@ -193,8 +193,8 @@ typedef struct GLboolean SessionActive; XrPosef xfStageFromHead; XrView* Views; - - + + int controllersPresent = -1; float currentDisplayRefreshRate; float* SupportedDisplayRefreshRates; uint32_t RequestedDisplayRefreshRateIndex; @@ -267,4 +267,10 @@ void TBXR_prepareEyeBuffer(int eye ); void TBXR_finishEyeBuffer(int eye ); void TBXR_submitFrame(); +#define VIVE_CONTROLLERS 10 +#define INDEX_CONTROLLERS 11 +#define PICO_CONTROLLERS 12 +#define TOUCH_CONTROLLERS 13 +//Anything else will emulate touch + #endif //vrcommon_h \ No newline at end of file