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 753ee96a..98a74c2d 100644 --- a/android/app/src/main/cpp/code/vr/vr_input.c +++ b/android/app/src/main/cpp/code/vr/vr_input.c @@ -2,7 +2,6 @@ //#if __ANDROID__ -#include "../qcommon/q_shared.h" #include "../qcommon/qcommon.h" #include "../client/keycodes.h" #include "../client/client.h" @@ -1329,37 +1328,6 @@ void IN_VRInputFrame( void ) //trigger frame tick for haptics VR_HapticEvent("frame_tick", 0, 0, 0, 0, 0); - { - // 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(VR_GetEngine()->appState.HeadSpace, VR_GetEngine()->appState.CurrentSpace, VR_GetEngine()->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); - - //Keep this for our records - VectorCopy(vr.hmdposition, vr.hmdposition_last); - - //Orientation - VectorSubtract(vr.hmdorientation_last, vr.hmdorientation, vr.hmdorientation_delta); - - //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; - } - if (leftControllerAimSpace == XR_NULL_HANDLE) { leftControllerAimSpace = CreateActionSpace(aimPoseAction, leftHandPath); } 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 bb68c044..ff681509 100644 --- a/android/app/src/main/cpp/code/vr/vr_input.h +++ b/android/app/src/main/cpp/code/vr/vr_input.h @@ -1,11 +1,16 @@ #ifndef __VR_INPUT_H #define __VR_INPUT_H +#include "../qcommon/q_shared.h" +#include "vr_types.h" + #if __ANDROID__ void IN_VRInputFrame( void ); void IN_VRInit( void ); +void QuatToYawPitchRoll(XrQuaternionf q, vec3_t rotation, vec3_t out); + #endif #endif 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 0ad762f3..26ad8b69 100644 --- a/android/app/src/main/cpp/code/vr/vr_renderer.c +++ b/android/app/src/main/cpp/code/vr/vr_renderer.c @@ -6,6 +6,7 @@ #include "../client/client.h" #include "vr_clientinfo.h" +#include "vr_input.h" #include "vr_types.h" #include @@ -19,6 +20,7 @@ #endif extern vr_clientinfo_t vr; +extern cvar_t *vr_heightAdjust; XrView* projections; @@ -364,6 +366,38 @@ void VR_DrawFrame( engine_t* engine ) { OXR(xrLocateSpace( engine->appState.HeadSpace, engine->appState.LocalSpace, frameState.predictedDisplayTime, &loc)); + + { + // 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); + + //Keep this for our records + VectorCopy(vr.hmdposition, vr.hmdposition_last); + + //Orientation + VectorSubtract(vr.hmdorientation_last, vr.hmdorientation, vr.hmdorientation_delta); + + //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; + } + XrViewLocateInfo projectionInfo = {}; projectionInfo.type = XR_TYPE_VIEW_LOCATE_INFO; projectionInfo.viewConfigurationType = engine->appState.ViewportConfig.viewConfigurationType;