9
9
#include < impl/OpenXrInterfaceImpl.h>
10
10
11
11
// #define DEBUG_RENDERING
12
+ // #define DEBUG_RENDERING_LOCATION
12
13
13
14
14
15
bool OpenXrInterface::checkExtensions ()
@@ -504,8 +505,8 @@ bool OpenXrInterface::prepareXrCompositionLayers()
504
505
m_pimpl->depth_projection_views [i].next = NULL ;
505
506
m_pimpl->depth_projection_views [i].minDepth = 0 .f ;
506
507
m_pimpl->depth_projection_views [i].maxDepth = 1 .f ;
507
- m_pimpl->depth_projection_views [i].nearZ = 0 . 01f ;
508
- m_pimpl->depth_projection_views [i].farZ = 100 . 0f ;
508
+ m_pimpl->depth_projection_views [i].nearZ = m_pimpl-> nearZ ;
509
+ m_pimpl->depth_projection_views [i].farZ = m_pimpl-> farZ ;
509
510
510
511
m_pimpl->depth_projection_views [i].subImage .swapchain = m_pimpl->projection_view_depth_swapchains [i].swapchain ;
511
512
m_pimpl->depth_projection_views [i].subImage .imageArrayIndex = 0 ;
@@ -524,7 +525,7 @@ bool OpenXrInterface::prepareXrCompositionLayers()
524
525
.type = XR_TYPE_COMPOSITION_LAYER_PROJECTION,
525
526
.next = NULL ,
526
527
.layerFlags = 0 ,
527
- .space = m_pimpl->view_space ,
528
+ .space = m_pimpl->renderInPlaySpace ? m_pimpl-> play_space : m_pimpl-> view_space ,
528
529
.viewCount = static_cast <uint32_t >(m_pimpl->projection_views .size ()),
529
530
.views = m_pimpl->projection_views .data (),
530
531
};
@@ -882,23 +883,37 @@ void OpenXrInterface::updateXrSpaces()
882
883
.viewConfigurationType =
883
884
XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO,
884
885
.displayTime = m_pimpl->frame_state .predictedDisplayTime ,
885
- .space = m_pimpl->view_space };
886
+ .space = m_pimpl->renderInPlaySpace ? m_pimpl-> play_space : m_pimpl-> view_space };
886
887
887
888
888
- uint32_t output_viewCount = m_pimpl->views .size ();
889
+ uint32_t output_viewCount = static_cast < uint32_t >( m_pimpl->views .size () );
889
890
XrResult result = xrLocateViews (m_pimpl->session , &view_locate_info, &(m_pimpl->view_state ),
890
- m_pimpl->views .size (), &output_viewCount, m_pimpl->views .data ());
891
+ static_cast < uint32_t >( m_pimpl->views .size () ), &output_viewCount, m_pimpl->views .data ());
891
892
if (!m_pimpl->checkXrOutput (result, " Failed to locate the views!" ))
892
893
{
893
894
m_pimpl->view_state .viewStateFlags = 0 ; // Set to zero all the valid/tracked flags
894
895
}
895
896
896
- XrPosef identity_pose = { .orientation = {.x = 0 , .y = 0 , .z = 0 , .w = 1.0 },
897
- .position = {.x = 0 , .y = 0 , .z = 0 } };
897
+ m_pimpl->mid_views_pose = m_pimpl->views [0 ].pose ;
898
+
899
+ for (size_t i = 1 ; i < m_pimpl->views .size (); ++i)
900
+ {
901
+ m_pimpl->mid_views_pose .position = toXr (Eigen::Vector3f (toEigen (m_pimpl->mid_views_pose .position ) + toEigen (m_pimpl->views [i].pose .position )));
902
+ }
903
+ m_pimpl->mid_views_pose .position = toXr (Eigen::Vector3f (toEigen (m_pimpl->mid_views_pose .position )/static_cast <float >(m_pimpl->views .size ())));
904
+
905
+ m_pimpl->mid_views_pose_inverted .orientation = toXr (toEigen (m_pimpl->mid_views_pose .orientation ).inverse ());
906
+ m_pimpl->mid_views_pose_inverted .position = toXr (toEigen (m_pimpl->mid_views_pose_inverted .orientation ) * -toEigen (m_pimpl->mid_views_pose .position ));
898
907
899
908
for (size_t i = 0 ; i < m_pimpl->views .size (); ++i)
900
909
{
910
+ #ifdef DEBUG_RENDERING_LOCATION
911
+ XrPosef identity_pose = {.orientation = {.x = 0 , .y = 0 , .z = 0 , .w = 1.0 },
912
+ .position = {.x = 0 , .y = 0 , .z = 0 }};
901
913
m_pimpl->projection_views [i].pose = identity_pose;
914
+ #else
915
+ m_pimpl->projection_views [i].pose = m_pimpl->mid_views_pose ;
916
+ #endif
902
917
m_pimpl->projection_views [i].fov = m_pimpl->views [i].fov ;
903
918
}
904
919
@@ -1170,12 +1185,14 @@ void OpenXrInterface::render()
1170
1185
{
1171
1186
if (openGLLayer->shouldRender () && (openGLLayer->visibility () == IOpenXrQuadLayer::Visibility::LEFT_EYE || openGLLayer->visibility () == IOpenXrQuadLayer::Visibility::BOTH_EYES))
1172
1187
{
1173
- openGLLayer->setFOVs (std::abs (m_pimpl->views [0 ].fov .angleLeft ) + std::abs (m_pimpl->views [0 ].fov .angleRight ), std::abs (m_pimpl->views [0 ].fov .angleUp ) + std::abs (m_pimpl->views [0 ].fov .angleDown ));
1188
+ openGLLayer->setFOVs (m_pimpl->views [0 ].fov );
1189
+ openGLLayer->setDepthLimits (m_pimpl->nearZ , m_pimpl->farZ );
1174
1190
if (openGLLayer->visibility () == IOpenXrQuadLayer::Visibility::BOTH_EYES || !openGLLayer->offsetIsSet ())
1175
1191
{
1176
1192
if (viewIsValid)
1177
1193
{
1178
- openGLLayer->setOffsetPosition (toEigen (m_pimpl->views [0 ].pose .position ));
1194
+ Eigen::Vector3f offset = toEigen (m_pimpl->mid_views_pose_inverted .orientation ) * toEigen (m_pimpl->views [0 ].pose .position ) + toEigen (m_pimpl->mid_views_pose_inverted .position );
1195
+ openGLLayer->setOffsetPosition (offset);
1179
1196
}
1180
1197
else
1181
1198
{
@@ -1219,12 +1236,14 @@ void OpenXrInterface::render()
1219
1236
{
1220
1237
if (openGLLayer->shouldRender () && (openGLLayer->visibility () == IOpenXrQuadLayer::Visibility::RIGHT_EYE || openGLLayer->visibility () == IOpenXrQuadLayer::Visibility::BOTH_EYES))
1221
1238
{
1222
- openGLLayer->setFOVs (std::abs (m_pimpl->views [1 ].fov .angleLeft ) + std::abs (m_pimpl->views [1 ].fov .angleRight ), std::abs (m_pimpl->views [1 ].fov .angleUp ) + std::abs (m_pimpl->views [1 ].fov .angleDown ));
1239
+ openGLLayer->setFOVs (m_pimpl->views [1 ].fov );
1240
+ openGLLayer->setDepthLimits (m_pimpl->nearZ , m_pimpl->farZ );
1223
1241
if (openGLLayer->visibility () == IOpenXrQuadLayer::Visibility::BOTH_EYES || !openGLLayer->offsetIsSet ())
1224
1242
{
1225
1243
if (viewIsValid)
1226
1244
{
1227
- openGLLayer->setOffsetPosition (toEigen (m_pimpl->views [1 ].pose .position ));
1245
+ Eigen::Vector3f offset = toEigen (m_pimpl->mid_views_pose_inverted .orientation ) * toEigen (m_pimpl->views [1 ].pose .position ) + toEigen (m_pimpl->mid_views_pose_inverted .position );
1246
+ openGLLayer->setOffsetPosition (offset);
1228
1247
}
1229
1248
else
1230
1249
{
@@ -1293,6 +1312,12 @@ void OpenXrInterface::endXrFrame()
1293
1312
{
1294
1313
if (layer->shouldSubmit ())
1295
1314
{
1315
+ #ifdef DEBUG_RENDERING_LOCATION
1316
+ layer->layer .pose = layer->desiredHeadFixedPose ;
1317
+ #else
1318
+ layer->layer .pose = toXr (Eigen::Matrix4f (toEigen (m_pimpl->mid_views_pose ) * toEigen (layer->desiredHeadFixedPose )));
1319
+ #endif
1320
+
1296
1321
m_pimpl->submitLayer ((XrCompositionLayerBaseHeader*) &layer->layer );
1297
1322
}
1298
1323
}
@@ -1339,6 +1364,12 @@ bool OpenXrInterface::initialize(const OpenXrInterfaceSettings &settings)
1339
1364
m_pimpl->locate_space_prediction_in_ns = static_cast <long >(std::round (settings.posesPredictionInMs * 1e6 ));
1340
1365
1341
1366
m_pimpl->hideWindow = settings.hideWindow ;
1367
+ m_pimpl->renderInPlaySpace = settings.renderInPlaySpace ;
1368
+
1369
+ #ifdef DEBUG_RENDERING_LOCATION
1370
+ m_pimpl->renderInPlaySpace = true ;
1371
+ #endif // DEBUG_RENDERING_LOCATION
1372
+
1342
1373
1343
1374
m_pimpl->closing = false ;
1344
1375
m_pimpl->closed = false ;
@@ -1442,7 +1473,7 @@ std::shared_ptr<IOpenXrQuadLayer> OpenXrInterface::addHeadFixedQuadLayer()
1442
1473
.type = XR_TYPE_COMPOSITION_LAYER_QUAD,
1443
1474
.next = NULL ,
1444
1475
.layerFlags = 0 ,
1445
- .space = m_pimpl->view_space , // Head fixed
1476
+ .space = m_pimpl->renderInPlaySpace ? m_pimpl-> play_space : m_pimpl-> view_space ,
1446
1477
.eyeVisibility = XR_EYE_VISIBILITY_BOTH,
1447
1478
.subImage = {
1448
1479
.swapchain = XR_NULL_HANDLE,
0 commit comments