Skip to content

Commit efdafc2

Browse files
committed
minor cleanups post-first-commit
1 parent c7d5270 commit efdafc2

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

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

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const int MAXIMUM_TRACKING_FRAMES = 360;
3232
struct NativeContext {
3333
JavaVM *javaVm = nullptr;
3434
jobject javaContext = nullptr;
35-
EGLContext eglContext = nullptr;
3635

3736
CardboardHeadTracker *headTracker = nullptr;
3837
CardboardLensDistortion *lensDistortion = nullptr;
@@ -126,13 +125,13 @@ AlvrPose getPose(uint64_t timestampNs) {
126125
AlvrPose pose = {};
127126
bool returnLastPosition = false;
128127

129-
float pos[3];
130-
float q[4];
131-
CardboardHeadTracker_getPose(CTX.headTracker, (int64_t) timestampNs, kLandscapeLeft, pos, q);
132-
133-
auto inverseOrientation = AlvrQuat{q[0], q[1], q[2], q[3]};
134-
pose.orientation = inverseQuat(inverseOrientation);
135128
if (!CTX.arcoreEnabled || (CTX.arcoreEnabled && !useARCoreOrientation)) {
129+
float pos[3];
130+
float q[4];
131+
CardboardHeadTracker_getPose(CTX.headTracker, (int64_t) timestampNs, kLandscapeLeft, pos, q);
132+
133+
auto inverseOrientation = AlvrQuat{q[0], q[1], q[2], q[3]};
134+
pose.orientation = inverseQuat(inverseOrientation);
136135
CTX.lastOrientation = pose.orientation;
137136
}
138137

@@ -166,24 +165,21 @@ AlvrPose getPose(uint64_t timestampNs) {
166165
ArPose_create(CTX.arSession, nullptr, &arPose);
167166
ArCamera_getPose(CTX.arSession, arCamera, arPose);
168167
// ArPose_getPoseRaw() returns a pose in {qx, qy, qz, qw, tx, ty, tz} format.
169-
float arRawPose[7] = {0.f};
168+
float arRawPose[7] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
170169
ArPose_getPoseRaw(CTX.arSession, arPose, arRawPose);
171-
pose.position[0] = arRawPose[4];
172-
pose.position[1] = arRawPose[5];
173-
pose.position[2] = arRawPose[6];
174-
175-
if (useARCoreOrientation) {
176-
auto inverseOrientation = AlvrQuat{arRawPose[0], arRawPose[1], arRawPose[2],
177-
arRawPose[3]};
178-
pose.orientation = inverseOrientation;
179-
CTX.lastOrientation = pose.orientation;
180-
}
181170

182171
for (int i = 0; i < 3; i++) {
183172
pose.position[i] = arRawPose[i + 4];
184173
CTX.lastPosition[i] = arRawPose[i + 4];
185174
}
186175

176+
if (useARCoreOrientation) {
177+
auto orientation = AlvrQuat{arRawPose[0], arRawPose[1], arRawPose[2],
178+
arRawPose[3]};
179+
pose.orientation = orientation;
180+
CTX.lastOrientation = pose.orientation;
181+
}
182+
187183
ArPose_destroy(arPose);
188184
ArCamera_release(arCamera);
189185
}
@@ -338,6 +334,7 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_initia
338334
if (CTX.arcoreEnabled) {
339335
if (ArSession_create(env, CTX.javaContext, &CTX.arSession) != AR_SUCCESS) {
340336
error("initializeNative: Could not create ARCore session");
337+
CTX.arcoreEnabled = false;
341338
return;
342339
}
343340

@@ -447,10 +444,6 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_sendBa
447444
extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_renderNative(JNIEnv *,
448445
jobject) {
449446
try {
450-
if (CTX.eglContext == nullptr) {
451-
CTX.eglContext = eglGetCurrentContext();
452-
}
453-
454447
if (CTX.renderingParamsChanged) {
455448
info("renderingParamsChanged, processing new params");
456449
uint8_t *buffer;

0 commit comments

Comments
 (0)