From a1de0e1ffe5081d0a15f4bd50b99f6a1c1439eac Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 2 May 2022 22:17:53 +0200 Subject: [PATCH 1/5] OpenXR menuYaw support added --- android/app/src/main/cpp/code/vr/vr_renderer.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 2b6cb72c..379f3539 100644 --- a/android/app/src/main/cpp/code/vr/vr_renderer.c +++ b/android/app/src/main/cpp/code/vr/vr_renderer.c @@ -465,6 +465,7 @@ void VR_DrawFrame( engine_t* engine ) { XrCompositionLayerProjectionView projection_layer_elements[2] = {}; if (!VR_useScreenLayer() && !(cl.snap.ps.pm_flags & PMF_FOLLOW && vr.follow_mode == VRFM_FIRSTPERSON)) { + vr.menuYaw = vr.hmdorientation[YAW]; for (int eye = 0; eye < ovrMaxNumEyes; eye++) { ovrFramebuffer* frameBuffer = &engine->appState.Renderer.FrameBuffer; @@ -510,8 +511,12 @@ void VR_DrawFrame( engine_t* engine ) { cylinder_layer.subImage.imageRect.extent.height = height; cylinder_layer.subImage.imageArrayIndex = 0; const XrVector3f axis = {0.0f, 1.0f, 0.0f}; - const XrVector3f pos = {xfStageFromHead.position.x, -0.25f, xfStageFromHead.position.z - 4.0f}; - cylinder_layer.pose.orientation = XrQuaternionf_CreateFromVectorAngle(axis, 0); + XrVector3f pos = { + xfStageFromHead.position.x - sin(radians(vr.menuYaw)) * 4.0f, + -0.25f, + xfStageFromHead.position.z - cos(radians(vr.menuYaw)) * 4.0f + }; + cylinder_layer.pose.orientation = XrQuaternionf_CreateFromVectorAngle(axis, radians(vr.menuYaw)); cylinder_layer.pose.position = pos; cylinder_layer.radius = 12.0f; cylinder_layer.centralAngle = MATH_PI * 0.5f; From 08a4fc7fbf95e70f4a467350129a79d8358b34bd Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 3 May 2022 18:37:28 +0200 Subject: [PATCH 2/5] OpenXR use the same coordinate system in all layers --- android/app/src/main/cpp/code/vr/vr_renderer.c | 6 ++++-- android/app/src/main/cpp/code/vr/vr_types.c | 5 ++++- android/app/src/main/cpp/code/vr/vr_types.h | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) 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 379f3539..f2759568 100644 --- a/android/app/src/main/cpp/code/vr/vr_renderer.c +++ b/android/app/src/main/cpp/code/vr/vr_renderer.c @@ -323,7 +323,9 @@ void VR_DrawFrame( engine_t* engine ) { } GLboolean stageBoundsDirty = GL_TRUE; - ovrApp_HandleXrEvents(&engine->appState); + if (ovrApp_HandleXrEvents(&engine->appState)) { + vr.menuYaw = vr.hmdorientation[YAW]; + } if (engine->appState.SessionActive == GL_FALSE) { return; } @@ -501,7 +503,7 @@ void VR_DrawFrame( engine_t* engine ) { XrCompositionLayerCylinderKHR cylinder_layer = {}; cylinder_layer.type = XR_TYPE_COMPOSITION_LAYER_CYLINDER_KHR; cylinder_layer.layerFlags = XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT; - cylinder_layer.space = engine->appState.LocalSpace; + cylinder_layer.space = engine->appState.CurrentSpace; cylinder_layer.eyeVisibility = XR_EYE_VISIBILITY_BOTH; memset(&cylinder_layer.subImage, 0, sizeof(XrSwapchainSubImage)); cylinder_layer.subImage.swapchain = engine->appState.Renderer.FrameBuffer.ColorSwapChain.Handle; diff --git a/android/app/src/main/cpp/code/vr/vr_types.c b/android/app/src/main/cpp/code/vr/vr_types.c index eaac6ce6..ba77abf6 100644 --- a/android/app/src/main/cpp/code/vr/vr_types.c +++ b/android/app/src/main/cpp/code/vr/vr_types.c @@ -314,8 +314,9 @@ void ovrApp_HandleSessionStateChanges(ovrApp* app, XrSessionState state) { } } -void ovrApp_HandleXrEvents(ovrApp* app) { +GLboolean ovrApp_HandleXrEvents(ovrApp* app) { XrEventDataBuffer eventDataBuffer = {}; + GLboolean recenter = GL_FALSE; // Poll for events for (;;) { @@ -368,6 +369,7 @@ void ovrApp_HandleXrEvents(ovrApp* app) { ref_space_change_event->referenceSpaceType, (void*)ref_space_change_event->session, FromXrTime(ref_space_change_event->changeTime)); + recenter = GL_TRUE; } break; case XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED: { const XrEventDataSessionStateChanged* session_state_changed_event = @@ -398,6 +400,7 @@ void ovrApp_HandleXrEvents(ovrApp* app) { break; } } + return recenter; } /* diff --git a/android/app/src/main/cpp/code/vr/vr_types.h b/android/app/src/main/cpp/code/vr/vr_types.h index 3f62c69c..ee155858 100644 --- a/android/app/src/main/cpp/code/vr/vr_types.h +++ b/android/app/src/main/cpp/code/vr/vr_types.h @@ -159,7 +159,7 @@ typedef enum { void ovrApp_Clear(ovrApp* app); void ovrApp_Destroy(ovrApp* app); -void ovrApp_HandleXrEvents(ovrApp* app); +GLboolean ovrApp_HandleXrEvents(ovrApp* app); void ovrFramebuffer_Acquire(ovrFramebuffer* frameBuffer); void ovrFramebuffer_Resolve(ovrFramebuffer* frameBuffer); From 8e5f6414a6cb598c17b7d3cdbd208fe11d0d4fb3 Mon Sep 17 00:00:00 2001 From: Lubos Date: Wed, 4 May 2022 16:19:48 +0200 Subject: [PATCH 3/5] OpenXR recenter integrated --- android/app/src/main/cpp/code/vr/vr_base.c | 1 - .../app/src/main/cpp/code/vr/vr_clientinfo.h | 2 + .../app/src/main/cpp/code/vr/vr_renderer.c | 129 +++++++++++------- android/app/src/main/cpp/code/vr/vr_types.c | 1 - android/app/src/main/cpp/code/vr/vr_types.h | 1 - 5 files changed, 79 insertions(+), 55 deletions(-) diff --git a/android/app/src/main/cpp/code/vr/vr_base.c b/android/app/src/main/cpp/code/vr/vr_base.c index c6d17a0e..59b09be7 100644 --- a/android/app/src/main/cpp/code/vr/vr_base.c +++ b/android/app/src/main/cpp/code/vr/vr_base.c @@ -299,7 +299,6 @@ void VR_EnterVR( engine_t* engine, ovrJava java ) { void VR_LeaveVR( engine_t* engine ) { if (engine->appState.Session) { OXR(xrDestroySpace(engine->appState.HeadSpace)); - OXR(xrDestroySpace(engine->appState.LocalSpace)); // StageSpace is optional. if (engine->appState.StageSpace != XR_NULL_HANDLE) { OXR(xrDestroySpace(engine->appState.StageSpace)); diff --git a/android/app/src/main/cpp/code/vr/vr_clientinfo.h b/android/app/src/main/cpp/code/vr/vr_clientinfo.h index 2dd5430d..620293cc 100644 --- a/android/app/src/main/cpp/code/vr/vr_clientinfo.h +++ b/android/app/src/main/cpp/code/vr/vr_clientinfo.h @@ -63,6 +63,8 @@ typedef struct { int *menuCursorX; int *menuCursorY; qboolean menuLeftHanded; + + float recenterYaw; } vr_clientinfo_t; #endif //vr_clientinfo_h \ No newline at end of file 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 f2759568..b2df12a3 100644 --- a/android/app/src/main/cpp/code/vr/vr_renderer.c +++ b/android/app/src/main/cpp/code/vr/vr_renderer.c @@ -23,6 +23,7 @@ extern vr_clientinfo_t vr; extern cvar_t *vr_heightAdjust; XrView* projections; +GLboolean stageSupported = GL_FALSE; void VR_UpdateStageBounds(ovrApp* pappState) { XrExtent2Df stageBounds = {}; @@ -161,6 +162,60 @@ void VR_GetResolution(engine_t* engine, int *pWidth, int *pHeight) } } +void VR_Recenter(engine_t* engine) { + + // Delete previous space instances + qboolean spacesAlreadyExisted = qfalse; + if (engine->appState.StageSpace != XR_NULL_HANDLE) { + OXR(xrDestroySpace(engine->appState.StageSpace)); + } + if (engine->appState.FakeStageSpace != XR_NULL_HANDLE) { + OXR(xrDestroySpace(engine->appState.FakeStageSpace)); + spacesAlreadyExisted = qtrue; + } + + // Create a space to the first path + XrReferenceSpaceCreateInfo spaceCreateInfo = {}; + spaceCreateInfo.type = XR_TYPE_REFERENCE_SPACE_CREATE_INFO; + spaceCreateInfo.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_VIEW; + spaceCreateInfo.poseInReferenceSpace.orientation.w = 1.0f; + + // Calculate recenter reference + if (engine->appState.CurrentSpace != XR_NULL_HANDLE) { + vr.recenterYaw += radians(vr.clientviewangles[YAW]); + spaceCreateInfo.poseInReferenceSpace.orientation.x = 0; + spaceCreateInfo.poseInReferenceSpace.orientation.y = sin(vr.recenterYaw / 2); + spaceCreateInfo.poseInReferenceSpace.orientation.z = 0; + spaceCreateInfo.poseInReferenceSpace.orientation.w = cos(vr.recenterYaw / 2); + } + + // Create a default stage space to use if SPACE_TYPE_STAGE is not + // supported, or calls to xrGetReferenceSpaceBoundsRect fail. + spaceCreateInfo.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_LOCAL; + spaceCreateInfo.poseInReferenceSpace.position.y = -1.6750f; + OXR(xrCreateReferenceSpace(engine->appState.Session, &spaceCreateInfo, &engine->appState.FakeStageSpace)); + ALOGV("Created fake stage space from local space with offset"); + engine->appState.CurrentSpace = engine->appState.FakeStageSpace; + + if (stageSupported) { + spaceCreateInfo.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_STAGE; + spaceCreateInfo.poseInReferenceSpace.position.y = 0.0f; + OXR(xrCreateReferenceSpace(engine->appState.Session, &spaceCreateInfo, &engine->appState.StageSpace)); + ALOGV("Created stage space"); + engine->appState.CurrentSpace = engine->appState.StageSpace; + } + + // Update menu orientation + if (spacesAlreadyExisted) { + vec3_t rotation = {0, 0, 0}; + XrSpaceLocation loc = {}; + loc.type = XR_TYPE_SPACE_LOCATION; + OXR(xrLocateSpace(engine->appState.HeadSpace, engine->appState.CurrentSpace, engine->predictedDisplayTime, &loc)); + QuatToYawPitchRoll(loc.pose.orientation, rotation, vr.hmdorientation); + vr.menuYaw = vr.hmdorientation[YAW]; + } +} + void VR_InitRenderer( engine_t* engine ) { #if ENABLE_GL_DEBUG glEnable(GL_DEBUG_OUTPUT); @@ -227,7 +282,6 @@ void VR_InitRenderer( engine_t* engine ) { OXR(xrEnumerateReferenceSpaces( engine->appState.Session, numOutputSpaces, &numOutputSpaces, referenceSpaces)); - GLboolean stageSupported = GL_FALSE; for (uint32_t i = 0; i < numOutputSpaces; i++) { if (referenceSpaces[i] == XR_REFERENCE_SPACE_TYPE_STAGE) { stageSupported = GL_TRUE; @@ -244,26 +298,7 @@ void VR_InitRenderer( engine_t* engine ) { spaceCreateInfo.poseInReferenceSpace.orientation.w = 1.0f; OXR(xrCreateReferenceSpace(engine->appState.Session, &spaceCreateInfo, &engine->appState.HeadSpace)); - spaceCreateInfo.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_LOCAL; - OXR(xrCreateReferenceSpace(engine->appState.Session, &spaceCreateInfo, &engine->appState.LocalSpace)); - - // Create a default stage space to use if SPACE_TYPE_STAGE is not - // supported, or calls to xrGetReferenceSpaceBoundsRect fail. - { - spaceCreateInfo.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_LOCAL; - spaceCreateInfo.poseInReferenceSpace.position.y = -1.6750f; - OXR(xrCreateReferenceSpace(engine->appState.Session, &spaceCreateInfo, &engine->appState.FakeStageSpace)); - ALOGV("Created fake stage space from local space with offset"); - engine->appState.CurrentSpace = engine->appState.FakeStageSpace; - } - - if (stageSupported) { - spaceCreateInfo.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_STAGE; - spaceCreateInfo.poseInReferenceSpace.position.y = 0.0f; - OXR(xrCreateReferenceSpace(engine->appState.Session, &spaceCreateInfo, &engine->appState.StageSpace)); - ALOGV("Created stage space"); - engine->appState.CurrentSpace = engine->appState.StageSpace; - } + VR_Recenter(engine); projections = (XrView*)(malloc(ovrMaxNumEyes * sizeof(XrView))); @@ -324,7 +359,7 @@ void VR_DrawFrame( engine_t* engine ) { GLboolean stageBoundsDirty = GL_TRUE; if (ovrApp_HandleXrEvents(&engine->appState)) { - vr.menuYaw = vr.hmdorientation[YAW]; + VR_Recenter(engine); } if (engine->appState.SessionActive == GL_FALSE) { return; @@ -360,44 +395,34 @@ void VR_DrawFrame( engine_t* engine ) { beginFrameDesc.next = NULL; OXR(xrBeginFrame(engine->appState.Session, &beginFrameDesc)); + // 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, frameState.predictedDisplayTime, &loc)); + OXR(xrLocateSpace(engine->appState.HeadSpace, engine->appState.CurrentSpace, frameState.predictedDisplayTime, &loc)); XrPosef xfStageFromHead = loc.pose; - OXR(xrLocateSpace( - engine->appState.HeadSpace, engine->appState.LocalSpace, frameState.predictedDisplayTime, &loc)); + const XrQuaternionf quatHmd = xfStageFromHead.orientation; + const XrVector3f positionHmd = xfStageFromHead.position; + vec3_t rotation = {0, 0, 0}; + QuatToYawPitchRoll(quatHmd, rotation, vr.hmdorientation); + VectorSet(vr.hmdposition, positionHmd.x, positionHmd.y + vr_heightAdjust->value, positionHmd.z); - { - // 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, frameState.predictedDisplayTime, &loc)); - XrPosef xfStageFromHead = loc.pose; - const XrQuaternionf quatHmd = xfStageFromHead.orientation; - const XrVector3f positionHmd = xfStageFromHead.position; - vec3_t rotation = {0, 0, 0}; - QuatToYawPitchRoll(quatHmd, rotation, vr.hmdorientation); - VectorSet(vr.hmdposition, positionHmd.x, positionHmd.y + vr_heightAdjust->value, positionHmd.z); + //Position + VectorSubtract(vr.hmdposition_last, vr.hmdposition, vr.hmdposition_delta); - //Position - VectorSubtract(vr.hmdposition_last, vr.hmdposition, vr.hmdposition_delta); + //Keep this for our records + VectorCopy(vr.hmdposition, vr.hmdposition_last); - //Keep this for our records - VectorCopy(vr.hmdposition, vr.hmdposition_last); + //Orientation + VectorSubtract(vr.hmdorientation_last, vr.hmdorientation, vr.hmdorientation_delta); - //Orientation - VectorSubtract(vr.hmdorientation_last, vr.hmdorientation, vr.hmdorientation_delta); + //Keep this for our records + VectorCopy(vr.hmdorientation, vr.hmdorientation_last); - //Keep this for our records - VectorCopy(vr.hmdorientation, vr.hmdorientation_last); - - // View yaw delta - 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; - } + // View yaw delta + 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; XrViewLocateInfo projectionInfo = {}; projectionInfo.type = XR_TYPE_VIEW_LOCATE_INFO; diff --git a/android/app/src/main/cpp/code/vr/vr_types.c b/android/app/src/main/cpp/code/vr/vr_types.c index ba77abf6..768ffef0 100644 --- a/android/app/src/main/cpp/code/vr/vr_types.c +++ b/android/app/src/main/cpp/code/vr/vr_types.c @@ -236,7 +236,6 @@ void ovrApp_Clear(ovrApp* app) { memset(&app->ViewConfigurationView, 0, ovrMaxNumEyes * sizeof(XrViewConfigurationView)); app->SystemId = XR_NULL_SYSTEM_ID; app->HeadSpace = XR_NULL_HANDLE; - app->LocalSpace = XR_NULL_HANDLE; app->StageSpace = XR_NULL_HANDLE; app->FakeStageSpace = XR_NULL_HANDLE; app->CurrentSpace = XR_NULL_HANDLE; diff --git a/android/app/src/main/cpp/code/vr/vr_types.h b/android/app/src/main/cpp/code/vr/vr_types.h index ee155858..f1e20574 100644 --- a/android/app/src/main/cpp/code/vr/vr_types.h +++ b/android/app/src/main/cpp/code/vr/vr_types.h @@ -79,7 +79,6 @@ typedef struct { XrViewConfigurationView ViewConfigurationView[ovrMaxNumEyes]; XrSystemId SystemId; XrSpace HeadSpace; - XrSpace LocalSpace; XrSpace StageSpace; XrSpace FakeStageSpace; XrSpace CurrentSpace; From 7072b0b89e0313a3bb39e8bb49dfdfa78e2972d9 Mon Sep 17 00:00:00 2001 From: Lubos Date: Wed, 4 May 2022 21:05:45 +0200 Subject: [PATCH 4/5] OpenXR recenter sets yaw always to 0 --- android/app/src/main/cpp/code/vr/vr_base.c | 1 - .../app/src/main/cpp/code/vr/vr_renderer.c | 44 ++++++++----------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/android/app/src/main/cpp/code/vr/vr_base.c b/android/app/src/main/cpp/code/vr/vr_base.c index 59b09be7..ba986cfb 100644 --- a/android/app/src/main/cpp/code/vr/vr_base.c +++ b/android/app/src/main/cpp/code/vr/vr_base.c @@ -306,7 +306,6 @@ void VR_LeaveVR( engine_t* engine ) { OXR(xrDestroySpace(engine->appState.FakeStageSpace)); engine->appState.CurrentSpace = XR_NULL_HANDLE; OXR(xrDestroySession(engine->appState.Session)); - OXR(xrDestroyInstance(engine->appState.Instance)); engine->appState.Session = NULL; } } 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 b2df12a3..1e162f17 100644 --- a/android/app/src/main/cpp/code/vr/vr_renderer.c +++ b/android/app/src/main/cpp/code/vr/vr_renderer.c @@ -164,29 +164,30 @@ void VR_GetResolution(engine_t* engine, int *pWidth, int *pHeight) void VR_Recenter(engine_t* engine) { + // Calculate recenter reference + XrReferenceSpaceCreateInfo spaceCreateInfo = {}; + spaceCreateInfo.type = XR_TYPE_REFERENCE_SPACE_CREATE_INFO; + spaceCreateInfo.poseInReferenceSpace.orientation.w = 1.0f; + if (engine->appState.CurrentSpace != XR_NULL_HANDLE) { + vec3_t rotation = {0, 0, 0}; + XrSpaceLocation loc = {}; + loc.type = XR_TYPE_SPACE_LOCATION; + OXR(xrLocateSpace(engine->appState.HeadSpace, engine->appState.CurrentSpace, engine->predictedDisplayTime, &loc)); + QuatToYawPitchRoll(loc.pose.orientation, rotation, vr.hmdorientation); + + vr.recenterYaw += radians(vr.hmdorientation[YAW]); + spaceCreateInfo.poseInReferenceSpace.orientation.x = 0; + spaceCreateInfo.poseInReferenceSpace.orientation.y = sin(vr.recenterYaw / 2); + spaceCreateInfo.poseInReferenceSpace.orientation.z = 0; + spaceCreateInfo.poseInReferenceSpace.orientation.w = cos(vr.recenterYaw / 2); + } + // Delete previous space instances - qboolean spacesAlreadyExisted = qfalse; if (engine->appState.StageSpace != XR_NULL_HANDLE) { OXR(xrDestroySpace(engine->appState.StageSpace)); } if (engine->appState.FakeStageSpace != XR_NULL_HANDLE) { OXR(xrDestroySpace(engine->appState.FakeStageSpace)); - spacesAlreadyExisted = qtrue; - } - - // Create a space to the first path - XrReferenceSpaceCreateInfo spaceCreateInfo = {}; - spaceCreateInfo.type = XR_TYPE_REFERENCE_SPACE_CREATE_INFO; - spaceCreateInfo.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_VIEW; - spaceCreateInfo.poseInReferenceSpace.orientation.w = 1.0f; - - // Calculate recenter reference - if (engine->appState.CurrentSpace != XR_NULL_HANDLE) { - vr.recenterYaw += radians(vr.clientviewangles[YAW]); - spaceCreateInfo.poseInReferenceSpace.orientation.x = 0; - spaceCreateInfo.poseInReferenceSpace.orientation.y = sin(vr.recenterYaw / 2); - spaceCreateInfo.poseInReferenceSpace.orientation.z = 0; - spaceCreateInfo.poseInReferenceSpace.orientation.w = cos(vr.recenterYaw / 2); } // Create a default stage space to use if SPACE_TYPE_STAGE is not @@ -206,14 +207,7 @@ void VR_Recenter(engine_t* engine) { } // Update menu orientation - if (spacesAlreadyExisted) { - vec3_t rotation = {0, 0, 0}; - XrSpaceLocation loc = {}; - loc.type = XR_TYPE_SPACE_LOCATION; - OXR(xrLocateSpace(engine->appState.HeadSpace, engine->appState.CurrentSpace, engine->predictedDisplayTime, &loc)); - QuatToYawPitchRoll(loc.pose.orientation, rotation, vr.hmdorientation); - vr.menuYaw = vr.hmdorientation[YAW]; - } + vr.menuYaw = 0; } void VR_InitRenderer( engine_t* engine ) { From 3ee3f590584f6a8ff8d1e5cace7b999965c7e5cd Mon Sep 17 00:00:00 2001 From: Lubos Date: Thu, 5 May 2022 12:22:36 +0200 Subject: [PATCH 5/5] OpenXR do not recenter on renderer reload --- android/app/src/main/cpp/code/vr/vr_base.c | 7 +++++++ android/app/src/main/cpp/code/vr/vr_renderer.c | 11 +++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/android/app/src/main/cpp/code/vr/vr_base.c b/android/app/src/main/cpp/code/vr/vr_base.c index ba986cfb..6970be90 100644 --- a/android/app/src/main/cpp/code/vr/vr_base.c +++ b/android/app/src/main/cpp/code/vr/vr_base.c @@ -294,6 +294,13 @@ void VR_EnterVR( engine_t* engine, ovrJava java ) { ALOGE("Failed to create XR session: %d.", initResult); exit(1); } + + // Create a space to the first path + XrReferenceSpaceCreateInfo spaceCreateInfo = {}; + spaceCreateInfo.type = XR_TYPE_REFERENCE_SPACE_CREATE_INFO; + spaceCreateInfo.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_VIEW; + spaceCreateInfo.poseInReferenceSpace.orientation.w = 1.0f; + OXR(xrCreateReferenceSpace(engine->appState.Session, &spaceCreateInfo, &engine->appState.HeadSpace)); } void VR_LeaveVR( engine_t* engine ) { 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 1e162f17..8ec4a1c1 100644 --- a/android/app/src/main/cpp/code/vr/vr_renderer.c +++ b/android/app/src/main/cpp/code/vr/vr_renderer.c @@ -285,14 +285,9 @@ void VR_InitRenderer( engine_t* engine ) { free(referenceSpaces); - // Create a space to the first path - XrReferenceSpaceCreateInfo spaceCreateInfo = {}; - spaceCreateInfo.type = XR_TYPE_REFERENCE_SPACE_CREATE_INFO; - spaceCreateInfo.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_VIEW; - spaceCreateInfo.poseInReferenceSpace.orientation.w = 1.0f; - OXR(xrCreateReferenceSpace(engine->appState.Session, &spaceCreateInfo, &engine->appState.HeadSpace)); - - VR_Recenter(engine); + if (engine->appState.CurrentSpace == XR_NULL_HANDLE) { + VR_Recenter(engine); + } projections = (XrView*)(malloc(ovrMaxNumEyes * sizeof(XrView)));