Skip to content

Commit

Permalink
OpenXR - Do not apply head rotation on identity matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
lvonasek committed Nov 9, 2022
1 parent 584ca5d commit 8716021
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
19 changes: 6 additions & 13 deletions Common/VR/PPSSPPVR.cpp
Expand Up @@ -644,20 +644,8 @@ bool Is2DVRObject(float* projMatrix, bool ortho) {
return true;
}

// Chceck if the projection matrix is identity
bool identity = true;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
float value = projMatrix[i * 4 + j];

// Other number than zero on non-diagonale
if ((i != j) && (fabs(value) > EPSILON)) identity = false;
// Other number than one on diagonale
if ((i == j) && (fabs(value - 1.0f) > EPSILON)) identity = false;
}
}

// Update 3D geometry count
bool identity = IsMatrixIdentity(projMatrix);
if (!identity && !ortho) {
vr3DGeometryCount++;
}
Expand Down Expand Up @@ -708,6 +696,11 @@ void UpdateVRView(float* leftEye, float* rightEye) {
float* matrix[] = {vrMatrix[VR_VIEW_MATRIX_LEFT_EYE], vrMatrix[VR_VIEW_MATRIX_RIGHT_EYE]};
for (int index = 0; index < 2; index++) {

// Validate the view matrix
if (IsMatrixIdentity(dst[index])) {
return;
}

// Get view matrix from the game
Lin::Matrix4x4 gameView = {};
memcpy(gameView.m, dst[index], 16 * sizeof(float));
Expand Down
14 changes: 14 additions & 0 deletions Common/VR/VRMath.cpp
Expand Up @@ -13,6 +13,20 @@ float ToRadians(float deg) {
return (float)(deg * M_PI / 180.0f);
}

bool IsMatrixIdentity(float* matrix) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
float value = matrix[i * 4 + j];

// Other number than zero on non-diagonale
if ((i != j) && (fabs(value) > EPSILON)) return false;
// Other number than one on diagonale
if ((i == j) && (fabs(value - 1.0f) > EPSILON)) return false;
}
}
return true;
}

/*
================================================================================
Expand Down
1 change: 1 addition & 0 deletions Common/VR/VRMath.h
Expand Up @@ -9,6 +9,7 @@

float ToDegrees(float rad);
float ToRadians(float deg);
bool IsMatrixIdentity(float* matrix);

// XrPosef
XrPosef XrPosef_Identity();
Expand Down

0 comments on commit 8716021

Please sign in to comment.