Skip to content

Commit 0982197

Browse files
fix: correct inverted cross-eye stereoscopic projection (#323)
* Update alvr_main.cpp * lint fix
1 parent 54cefdc commit 0982197

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

code/mobile/android/PhoneVR/app/src/main/cpp/alvr_main.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,19 @@ struct NativeContext {
7777
std::thread inputThread;
7878

7979
// Une one texture per eye, no need for swapchains.
80-
GLuint lobbyTextures[2] = {};
81-
GLuint streamTextures[2] = {};
80+
GLuint lobbyTextures[2] = {0, 0};
81+
GLuint streamTextures[2] = {0, 0};
8282

83-
float eyeOffsets[2] = {};
83+
float eyeOffsets[2] = {0.0, 0.0};
8484
AlvrFov fovArr[2] = {};
8585
AlvrViewParams viewParams[2] = {};
8686
AlvrDeviceMotion deviceMotion = {};
87+
88+
NativeContext() {
89+
memset(&fovArr, 0, (sizeof(fovArr)) / sizeof(int));
90+
memset(&viewParams, 0, (sizeof(viewParams)) / sizeof(int));
91+
memset(&deviceMotion, 0, (sizeof(deviceMotion)) / sizeof(int));
92+
}
8793
};
8894

8995
NativeContext CTX = {};
@@ -117,9 +123,9 @@ void offsetPosWithQuat(AlvrQuat q, float offset[3], float outPos[3]) {
117123
float rotatedOffset[3];
118124
quatVecMultiply(q, offset, rotatedOffset);
119125

120-
outPos[0] += rotatedOffset[0];
121-
outPos[1] += rotatedOffset[1] + FLOOR_HEIGHT;
122-
outPos[2] += rotatedOffset[2];
126+
outPos[0] -= rotatedOffset[0];
127+
outPos[1] -= rotatedOffset[1] - FLOOR_HEIGHT;
128+
outPos[2] -= rotatedOffset[2];
123129
}
124130

125131
AlvrFov getFov(CardboardEye eye) {
@@ -327,8 +333,8 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_render
327333
CTX.eyeOffsets[eye] = matrix[12];
328334
}
329335

330-
CTX.fovArr[0] = getFov((CardboardEye) 0);
331-
CTX.fovArr[1] = getFov((CardboardEye) 1);
336+
CTX.fovArr[kLeft] = getFov(kLeft);
337+
CTX.fovArr[kRight] = getFov(kRight);
332338

333339
info("renderingParamsChanged, updating new view configs (FOV) to alvr");
334340
// alvr_send_views_config(fovArr, CTX.eyeOffsets[0] - CTX.eyeOffsets[1]);

0 commit comments

Comments
 (0)