From e473ecfddd540d3a2de37966aa507a1ca8a8e018 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 10 Dec 2022 00:34:51 +0000 Subject: [PATCH] Most stuff working.. but looks pretty bad at the moment --- .../Android/jni/JKVR/JKVR_SurfaceView.cpp | 48 ++++++++++++++++--- Projects/Android/jni/JKVR/VrCommon.h | 5 ++ Projects/Android/jni/JKVR/VrInputCommon.cpp | 15 ++++-- .../jni/OpenJK/code/client/cl_main.cpp | 10 ---- .../jni/OpenJK/code/client/cl_scrn.cpp | 39 ++++++++------- .../jni/OpenJK/code/rd-common/tr_public.h | 1 - .../jni/OpenJK/code/rd-gles/tr_backend.cpp | 2 - 7 files changed, 77 insertions(+), 43 deletions(-) diff --git a/Projects/Android/jni/JKVR/JKVR_SurfaceView.cpp b/Projects/Android/jni/JKVR/JKVR_SurfaceView.cpp index d4dc734..2921d6a 100644 --- a/Projects/Android/jni/JKVR/JKVR_SurfaceView.cpp +++ b/Projects/Android/jni/JKVR/JKVR_SurfaceView.cpp @@ -1992,7 +1992,13 @@ void JKVR_FrameSetup() //get any cvar values required here vr.immersive_cinematics = (vr_immersive_cinematics->value != 0.0f); + JKVR_processMessageQueue(); + //Get controller state here + JKVR_getHMDOrientation(); + JKVR_getTrackedRemotesOrientation(); + + JKVR_processHaptics(); } int GetRefresh() @@ -2031,7 +2037,7 @@ void JKVR_finishEyeBuffer(int eye ) // Clear the alpha channel, other way OpenXR would not transfer the framebuffer fully glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE); - glClearColor(1.0, 0.0, 0.0, 1.0); + glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); @@ -2206,6 +2212,7 @@ void JKVR_UpdateControllers( ) gAppState.TrackedController[i].Active = (loc.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) != 0; gAppState.TrackedController[i].Pose = loc.pose; + gAppState.TrackedController[i].Velocity = vel; // apply velocity // float dt = (in_vrEventTime - lastframetime) * 0.001f; @@ -2217,11 +2224,40 @@ void JKVR_UpdateControllers( ) } } - //apply controller poses -// if (gAppState.TrackedController[0].Active) -// IN_VRController(qfalse, gAppState.TrackedController[0].Pose); -// if (gAppState.TrackedController[1].Active) -// IN_VRController(qtrue, gAppState.TrackedController[1].Pose); + leftRemoteTracking_new = gAppState.TrackedController[0]; + rightRemoteTracking_new = gAppState.TrackedController[1]; + + + memset(&leftTrackedRemoteState_new, 0, sizeof leftTrackedRemoteState_new); + memset(&rightTrackedRemoteState_new, 0, sizeof rightTrackedRemoteState_new); + + //button mapping + if (GetActionStateBoolean(menuAction).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_Enter; + if (GetActionStateBoolean(buttonXAction).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_X; + if (GetActionStateBoolean(buttonYAction).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_Y; + leftTrackedRemoteState_new.GripTrigger = GetActionStateFloat(gripLeftAction).currentState; + leftTrackedRemoteState_new.IndexTrigger = GetActionStateFloat(indexLeftAction).currentState; + if (GetActionStateBoolean(thumbstickLeftClickAction).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_LThumb; + + if (GetActionStateBoolean(buttonAAction).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_A; + if (GetActionStateBoolean(buttonBAction).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_B; + rightTrackedRemoteState_new.GripTrigger = GetActionStateFloat(gripRightAction).currentState; + rightTrackedRemoteState_new.IndexTrigger = GetActionStateFloat(indexRightAction).currentState; + if (GetActionStateBoolean(thumbstickRightClickAction).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_RThumb; + + //index finger click + if (GetActionStateBoolean(indexLeftAction).currentState) leftTrackedRemoteState_new.Buttons |= xrButton_Trigger; + if (GetActionStateBoolean(indexRightAction).currentState) rightTrackedRemoteState_new.Buttons |= xrButton_Trigger; + + //thumbstick + XrActionStateVector2f moveJoystickState; + moveJoystickState = GetActionStateVector2(moveOnLeftJoystickAction); + leftTrackedRemoteState_new.Joystick.x = moveJoystickState.currentState.x; + leftTrackedRemoteState_new.Joystick.y = moveJoystickState.currentState.y; + + moveJoystickState = GetActionStateVector2(moveOnRightJoystickAction); + rightTrackedRemoteState_new.Joystick.x = moveJoystickState.currentState.x; + rightTrackedRemoteState_new.Joystick.y = moveJoystickState.currentState.y; } void JKVR_getHMDOrientation() {//Get orientation diff --git a/Projects/Android/jni/JKVR/VrCommon.h b/Projects/Android/jni/JKVR/VrCommon.h index 56d93fc..38f22ac 100644 --- a/Projects/Android/jni/JKVR/VrCommon.h +++ b/Projects/Android/jni/JKVR/VrCommon.h @@ -275,6 +275,11 @@ int GetRefresh(); //XrAction stuff bool ActionPoseIsActive(XrAction action, XrPath subactionPath); +XrActionStateBoolean GetActionStateBoolean(XrAction action); +XrActionStateFloat GetActionStateFloat(XrAction action); +XrActionStateVector2f GetActionStateVector2(XrAction action); + + void VR_Recenter(); //Called from engine code diff --git a/Projects/Android/jni/JKVR/VrInputCommon.cpp b/Projects/Android/jni/JKVR/VrInputCommon.cpp index 6362b62..69c3533 100644 --- a/Projects/Android/jni/JKVR/VrInputCommon.cpp +++ b/Projects/Android/jni/JKVR/VrInputCommon.cpp @@ -213,6 +213,13 @@ void JKVR_InitActions( void ) handPoseLeftAction = CreateAction(runningActionSet, XR_ACTION_TYPE_POSE_INPUT, "hand_pose_left", NULL, 1, &leftHandPath); handPoseRightAction = CreateAction(runningActionSet, XR_ACTION_TYPE_POSE_INPUT, "hand_pose_right", NULL, 1, &rightHandPath); + if (leftControllerAimSpace == XR_NULL_HANDLE) { + leftControllerAimSpace = CreateActionSpace(handPoseLeftAction, leftHandPath); + } + if (rightControllerAimSpace == XR_NULL_HANDLE) { + rightControllerAimSpace = CreateActionSpace(handPoseRightAction, rightHandPath); + } + XrPath interactionProfilePath = XR_NULL_PATH; XrPath interactionProfilePathTouch = XR_NULL_PATH; XrPath interactionProfilePathKHRSimple = XR_NULL_PATH; @@ -401,14 +408,14 @@ void JKVR_Vibrate( int duration, int chan, float intensity ) int channel = (i + 1) & chan; if (channel) { - if (vibration_channel_duration[channel-1] > 0.0f) + if (vibration_channel_duration[channel] > 0.0f) return; - if (vibration_channel_duration[channel-1] == -1.0f && duration != 0.0f) + if (vibration_channel_duration[channel] == -1.0f && duration != 0.0f) return; - vibration_channel_duration[channel-1] = duration; - vibration_channel_intensity[channel-1] = intensity * vr_haptic_intensity->value; + vibration_channel_duration[channel] = duration; + vibration_channel_intensity[channel] = intensity * vr_haptic_intensity->value; } } } diff --git a/Projects/Android/jni/OpenJK/code/client/cl_main.cpp b/Projects/Android/jni/OpenJK/code/client/cl_main.cpp index 5a73e21..9090f4b 100644 --- a/Projects/Android/jni/OpenJK/code/client/cl_main.cpp +++ b/Projects/Android/jni/OpenJK/code/client/cl_main.cpp @@ -832,15 +832,6 @@ void CL_Frame ( int msec,float fractionMsec ) { SCR_DebugGraph ( cls.realFrametime * 0.25, 0 ); } - JKVR_FrameSetup(); - JKVR_processMessageQueue(); - - //Get controller state here - JKVR_getHMDOrientation(); - JKVR_getTrackedRemotesOrientation(); - - JKVR_processHaptics(); - // see if we need to update any userinfo CL_CheckUserinfo(); @@ -1200,7 +1191,6 @@ void CL_InitRef( void ) { rit.saved_game = &ojk::SavedGame::get_instance(); - rit.JKVR_prepareEyeBuffer = JKVR_prepareEyeBuffer; rit.JKVR_useScreenLayer = JKVR_useScreenLayer; ret = GetRefAPI( REF_API_VERSION, &rit ); diff --git a/Projects/Android/jni/OpenJK/code/client/cl_scrn.cpp b/Projects/Android/jni/OpenJK/code/client/cl_scrn.cpp index 68f183b..7e9f61a 100644 --- a/Projects/Android/jni/OpenJK/code/client/cl_scrn.cpp +++ b/Projects/Android/jni/OpenJK/code/client/cl_scrn.cpp @@ -507,31 +507,30 @@ void SCR_UpdateScreen( void ) { // that case. if ( cls.uiStarted ) { - //Draw twice for Quest - SCR_DrawScreenField( STEREO_LEFT ); + JKVR_FrameSetup(); - //This won't perform the submit eye buffers + for (int eye = 0; eye < 2; ++eye) { - if (com_speeds->integer) { - re.EndFrame(&time_frontend, &time_backend); - } else { - re.EndFrame(NULL, NULL); + JKVR_prepareEyeBuffer(eye); + + //Draw twice for Quest + SCR_DrawScreenField(eye == 0 ? STEREO_LEFT : STEREO_RIGHT); + + //This won't perform the submit eye buffers + { + if (com_speeds->integer) + { + re.EndFrame(&time_frontend, &time_backend); + } + else + { + re.EndFrame(NULL, NULL); + } } + + JKVR_finishEyeBuffer(eye); } - JKVR_finishEyeBuffer(0); - - SCR_DrawScreenField( STEREO_RIGHT ); - - //This will perform the submit eye buffers - if ( com_speeds->integer ) { - re.EndFrame( &time_frontend, &time_backend ); - } else { - re.EndFrame( NULL, NULL ); - } - - JKVR_finishEyeBuffer(1); - //And we're done re.SubmitStereoFrame(); diff --git a/Projects/Android/jni/OpenJK/code/rd-common/tr_public.h b/Projects/Android/jni/OpenJK/code/rd-common/tr_public.h index 6dbf3bf..6943867 100644 --- a/Projects/Android/jni/OpenJK/code/rd-common/tr_public.h +++ b/Projects/Android/jni/OpenJK/code/rd-common/tr_public.h @@ -128,7 +128,6 @@ typedef struct { int (*com_frameTime) ( void ); //JKVR Functions - void (*JKVR_prepareEyeBuffer) (int eye ); bool (*JKVR_useScreenLayer) ( void ); } refimport_t; diff --git a/Projects/Android/jni/OpenJK/code/rd-gles/tr_backend.cpp b/Projects/Android/jni/OpenJK/code/rd-gles/tr_backend.cpp index 68fe458..0322308 100644 --- a/Projects/Android/jni/OpenJK/code/rd-gles/tr_backend.cpp +++ b/Projects/Android/jni/OpenJK/code/rd-gles/tr_backend.cpp @@ -1435,8 +1435,6 @@ const void *RB_DrawBuffer( const void *data ) { qglDrawBuffer( cmd->buffer ); #endif */ - ri.JKVR_prepareEyeBuffer(cmd->buffer); - // clear screen for debugging if ( r_clear->integer ) { qglClearColor( 0, 0, 0, 1 );