From d354212c5d0f2a65664ce11e4131a9093473a9aa Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 10 May 2022 22:26:55 +0200 Subject: [PATCH] OpenXR change the way of getting the head position --- android/app/src/main/cpp/code/vr/vr_input.c | 10 +--------- android/app/src/main/cpp/code/vr/vr_input.h | 2 +- android/app/src/main/cpp/code/vr/vr_renderer.c | 14 +++++++------- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/android/app/src/main/cpp/code/vr/vr_input.c b/android/app/src/main/cpp/code/vr/vr_input.c index 1994e005..0afb600c 100644 --- a/android/app/src/main/cpp/code/vr/vr_input.c +++ b/android/app/src/main/cpp/code/vr/vr_input.c @@ -1425,16 +1425,10 @@ void IN_VRUpdateControllers( float predictedDisplayTime ) IN_VRController(qtrue, engine->appState.TrackedController[1].Pose); } -XrPosef IN_VRUpdateHMD( float predictedDisplayTime ) +void IN_VRUpdateHMD( XrPosef xfStageFromHead ) { - engine_t* engine = VR_GetEngine(); - // We extract Yaw, Pitch, Roll instead of directly using the orientation // to allow "additional" yaw manipulation with mouse/controller. - XrSpaceLocation loc = {}; - loc.type = XR_TYPE_SPACE_LOCATION; - OXR(xrLocateSpace(engine->appState.HeadSpace, engine->appState.CurrentSpace, predictedDisplayTime, &loc)); - XrPosef xfStageFromHead = loc.pose; const XrQuaternionf quatHmd = xfStageFromHead.orientation; const XrVector3f positionHmd = xfStageFromHead.position; vec3_t rotation = {0, 0, 0}; @@ -1457,8 +1451,6 @@ XrPosef IN_VRUpdateHMD( float predictedDisplayTime ) const float clientview_yaw = vr.clientviewangles[YAW] - vr.hmdorientation[YAW]; vr.clientview_yaw_delta = vr.clientview_yaw_last - clientview_yaw; vr.clientview_yaw_last = clientview_yaw; - - return xfStageFromHead; } //#endif diff --git a/android/app/src/main/cpp/code/vr/vr_input.h b/android/app/src/main/cpp/code/vr/vr_input.h index 358cb5fb..02a2f900 100644 --- a/android/app/src/main/cpp/code/vr/vr_input.h +++ b/android/app/src/main/cpp/code/vr/vr_input.h @@ -9,7 +9,7 @@ void IN_VRInputFrame( void ); void IN_VRInit( void ); void IN_VRSyncActions( void ); -XrPosef IN_VRUpdateHMD( float predictedDisplayTime ); +void IN_VRUpdateHMD( XrPosef xfStageFromHead ); void IN_VRUpdateControllers( float predictedDisplayTime ); void QuatToYawPitchRoll(XrQuaternionf q, vec3_t rotation, vec3_t out); diff --git a/android/app/src/main/cpp/code/vr/vr_renderer.c b/android/app/src/main/cpp/code/vr/vr_renderer.c index ca3ee413..5d73ab80 100644 --- a/android/app/src/main/cpp/code/vr/vr_renderer.c +++ b/android/app/src/main/cpp/code/vr/vr_renderer.c @@ -384,11 +384,6 @@ void VR_DrawFrame( engine_t* engine ) { beginFrameDesc.next = NULL; OXR(xrBeginFrame(engine->appState.Session, &beginFrameDesc)); - // Update HMD and controllers - XrPosef xfStageFromHead = IN_VRUpdateHMD( frameState.predictedDisplayTime ); - IN_VRSyncActions(); - IN_VRUpdateControllers( frameState.predictedDisplayTime ); - XrViewLocateInfo projectionInfo = {}; projectionInfo.type = XR_TYPE_VIEW_LOCATE_INFO; projectionInfo.viewConfigurationType = engine->appState.ViewportConfig.viewConfigurationType; @@ -422,6 +417,11 @@ void VR_DrawFrame( engine_t* engine ) { vr.fov_x = (fabs(fov.angleLeft) + fabs(fov.angleRight)) * 180.0f / M_PI; vr.fov_y = (fabs(fov.angleUp) + fabs(fov.angleDown)) * 180.0f / M_PI; + // Update HMD and controllers + IN_VRUpdateHMD( invViewTransform[0] ); + IN_VRSyncActions(); + IN_VRUpdateControllers( frameState.predictedDisplayTime ); + //Projection used for drawing HUD models etc float hudScale = M_PI * 15.0f / 180.0f; const ovrMatrix4f monoVRMatrix = ovrMatrix4f_CreateProjectionFov( @@ -505,9 +505,9 @@ void VR_DrawFrame( engine_t* engine ) { cylinder_layer.subImage.imageArrayIndex = 0; const XrVector3f axis = {0.0f, 1.0f, 0.0f}; XrVector3f pos = { - xfStageFromHead.position.x - sin(radians(vr.menuYaw)) * 4.0f, + invViewTransform[0].position.x - sin(radians(vr.menuYaw)) * 4.0f, -0.25f, - xfStageFromHead.position.z - cos(radians(vr.menuYaw)) * 4.0f + invViewTransform[0].position.z - cos(radians(vr.menuYaw)) * 4.0f }; cylinder_layer.pose.orientation = XrQuaternionf_CreateFromVectorAngle(axis, radians(vr.menuYaw)); cylinder_layer.pose.position = pos;