OpenXR - Estimate world unit scale

This commit is contained in:
Lubos 2022-08-01 19:28:50 +02:00
parent 4a3f809588
commit 2103874c0f
4 changed files with 12 additions and 6 deletions

View File

@ -221,7 +221,7 @@ bool GLRenderManager::ThreadFrame() {
VR_SetConfig(VR_CONFIG_3D_GEOMETRY_COUNT, VR_GetConfig(VR_CONFIG_3D_GEOMETRY_COUNT) / 2);
// Set customizations
VR_SetConfig(VR_CONFIG_6DOF, g_Config.bEnable6DoF);
VR_SetConfig(VR_CONFIG_6DOF_ENABLED, g_Config.bEnable6DoF);
VR_SetConfig(VR_CONFIG_FOV_SCALE, g_Config.iFieldOfViewPercentage);
// hack to quick enable 2D mode in game

View File

@ -477,10 +477,11 @@ ovrMatrix4f VR_GetMatrix( VRMatrix matrix ) {
}
output = ovrMatrix4f_CreateFromQuaternion(&invView.orientation);
if (vrConfig[VR_CONFIG_6DOF]) {
output.M[0][3] -= hmdposition.x * (vrConfig[VR_CONFIG_MIRROR_AXIS_X] ? -1.0f : 1.0f);
output.M[1][3] -= hmdposition.y * (vrConfig[VR_CONFIG_MIRROR_AXIS_Y] ? -1.0f : 1.0f);
output.M[2][3] -= hmdposition.z * (vrConfig[VR_CONFIG_MIRROR_AXIS_Z] ? -1.0f : 1.0f);
if (vrConfig[VR_CONFIG_6DOF_ENABLED]) {
float scale = (float)VR_GetConfig(VR_CONFIG_6DOF_SCALE) * 0.001f;
output.M[0][3] -= hmdposition.x * (vrConfig[VR_CONFIG_MIRROR_AXIS_X] ? -1.0f : 1.0f) * scale;
output.M[1][3] -= hmdposition.y * (vrConfig[VR_CONFIG_MIRROR_AXIS_Y] ? -1.0f : 1.0f) * scale;
output.M[2][3] -= hmdposition.z * (vrConfig[VR_CONFIG_MIRROR_AXIS_Z] ? -1.0f : 1.0f) * scale;
}
} else {
assert(false);

View File

@ -5,7 +5,8 @@
enum VRConfig {
VR_CONFIG_MODE,
VR_CONFIG_6DOF,
VR_CONFIG_6DOF_ENABLED,
VR_CONFIG_6DOF_SCALE,
VR_CONFIG_MIRROR_AXIS_X,
VR_CONFIG_MIRROR_AXIS_Y,
VR_CONFIG_MIRROR_AXIS_Z,

View File

@ -538,6 +538,10 @@ void LinkedShader::UpdateUniforms(u32 vertType, const ShaderID &vsid, bool useBu
ConvertMatrix4x3To4x4Transposed(m4x4, gstate.viewMatrix);
memcpy(gameView.M, m4x4, 16 * sizeof(float));
// Set 6DoF scale
float scale = pow(fabs(gstate.projMatrix[14]), 1.15f);
VR_SetConfig(VR_CONFIG_6DOF_SCALE, (int)(scale * 1000));
// Get view matrix from the headset
ovrMatrix4f hmdView = VR_GetMatrix(VR_VIEW_MATRIX_LEFT_EYE);