mirror of
https://github.com/amwatson/CitraVR.git
synced 2024-09-20 03:11:40 +02:00
[vr_main] add sep method for creating runtime-initated reference spaces
This commit is contained in:
parent
fb4d160b16
commit
5b3f405c9a
1 changed files with 37 additions and 32 deletions
|
@ -352,38 +352,7 @@ private:
|
|||
// Re-initialize the reference spaces on the first frame so
|
||||
// it is in-sync with user
|
||||
if (mFrameIndex == 1) {
|
||||
|
||||
// Create a reference space with the forward direction from the
|
||||
// starting frame.
|
||||
{
|
||||
const XrReferenceSpaceCreateInfo sci = {XR_TYPE_REFERENCE_SPACE_CREATE_INFO,
|
||||
nullptr, XR_REFERENCE_SPACE_TYPE_LOCAL,
|
||||
XrMath::Posef::Identity()};
|
||||
OXR(xrCreateReferenceSpace(gOpenXr->mSession, &sci,
|
||||
&gOpenXr->mForwardDirectionSpace));
|
||||
}
|
||||
|
||||
{
|
||||
const XrReferenceSpaceCreateInfo sci = {XR_TYPE_REFERENCE_SPACE_CREATE_INFO,
|
||||
nullptr, XR_REFERENCE_SPACE_TYPE_VIEW,
|
||||
XrMath::Posef::Identity()};
|
||||
OXR(xrCreateReferenceSpace(gOpenXr->mSession, &sci, &gOpenXr->mViewSpace));
|
||||
}
|
||||
|
||||
// Get the pose of the local space.
|
||||
XrSpaceLocation lsl = {XR_TYPE_SPACE_LOCATION};
|
||||
OXR(xrLocateSpace(gOpenXr->mForwardDirectionSpace, gOpenXr->mLocalSpace,
|
||||
frameState.predictedDisplayTime, &lsl));
|
||||
|
||||
// Set the forward direction of the new space.
|
||||
const XrPosef forwardDirectionPose = lsl.pose;
|
||||
|
||||
// Create a reference space with the same position and rotation as
|
||||
// local.
|
||||
const XrReferenceSpaceCreateInfo sci = {XR_TYPE_REFERENCE_SPACE_CREATE_INFO, nullptr,
|
||||
XR_REFERENCE_SPACE_TYPE_LOCAL,
|
||||
forwardDirectionPose};
|
||||
OXR(xrCreateReferenceSpace(gOpenXr->mSession, &sci, &gOpenXr->mHeadSpace));
|
||||
CreateRuntimeInitatedReferenceSpaces(frameState.predictedDisplayTime);
|
||||
}
|
||||
|
||||
gOpenXr->headLocation = {XR_TYPE_SPACE_LOCATION};
|
||||
|
@ -806,6 +775,42 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
// Called whenever a session is started/resumed. Creates the head space based on the
|
||||
// current pose of the HMD.
|
||||
void CreateRuntimeInitatedReferenceSpaces(const XrTime predictedDisplayTime) const {
|
||||
// Create a reference space with the forward direction from the
|
||||
// starting frame.
|
||||
{
|
||||
const XrReferenceSpaceCreateInfo sci = {XR_TYPE_REFERENCE_SPACE_CREATE_INFO,
|
||||
nullptr, XR_REFERENCE_SPACE_TYPE_LOCAL,
|
||||
XrMath::Posef::Identity()};
|
||||
OXR(xrCreateReferenceSpace(gOpenXr->mSession, &sci,
|
||||
&gOpenXr->mForwardDirectionSpace));
|
||||
}
|
||||
|
||||
{
|
||||
const XrReferenceSpaceCreateInfo sci = {XR_TYPE_REFERENCE_SPACE_CREATE_INFO,
|
||||
nullptr, XR_REFERENCE_SPACE_TYPE_VIEW,
|
||||
XrMath::Posef::Identity()};
|
||||
OXR(xrCreateReferenceSpace(gOpenXr->mSession, &sci, &gOpenXr->mViewSpace));
|
||||
}
|
||||
|
||||
// Get the pose of the local space.
|
||||
XrSpaceLocation lsl = {XR_TYPE_SPACE_LOCATION};
|
||||
OXR(xrLocateSpace(gOpenXr->mForwardDirectionSpace, gOpenXr->mLocalSpace,
|
||||
predictedDisplayTime, &lsl));
|
||||
|
||||
// Set the forward direction of the new space.
|
||||
const XrPosef forwardDirectionPose = lsl.pose;
|
||||
|
||||
// Create a reference space with the same position and rotation as
|
||||
// local.
|
||||
const XrReferenceSpaceCreateInfo sci = {XR_TYPE_REFERENCE_SPACE_CREATE_INFO, nullptr,
|
||||
XR_REFERENCE_SPACE_TYPE_LOCAL,
|
||||
forwardDirectionPose};
|
||||
OXR(xrCreateReferenceSpace(gOpenXr->mSession, &sci, &gOpenXr->mHeadSpace));
|
||||
}
|
||||
|
||||
void HandleSessionStateChanges(const XrSessionState state) {
|
||||
if (state == XR_SESSION_STATE_READY) {
|
||||
assert(mIsXrSessionActive == false);
|
||||
|
|
Loading…
Reference in a new issue