Skip to content

Commit a7635e5

Browse files
committed
minor cleanups post-first-commit
1 parent e142144 commit a7635e5

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

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

Lines changed: 16 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

@@ -165,25 +164,23 @@ AlvrPose getPose(uint64_t timestampNs) {
165164
ArPose *arPose = nullptr;
166165
ArPose_create(CTX.arSession, nullptr, &arPose);
167166
ArCamera_getPose(CTX.arSession, arCamera, arPose);
167+
//ArFrame_getAndroidSensorPose(CTX.arSession, CTX.arFrame, arPose);
168168
// ArPose_getPoseRaw() returns a pose in {qx, qy, qz, qw, tx, ty, tz} format.
169169
float arRawPose[7] = {0.f};
170170
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-
}
181171

182172
for (int i = 0; i < 3; i++) {
183173
pose.position[i] = arRawPose[i + 4];
184174
CTX.lastPosition[i] = arRawPose[i + 4];
185175
}
186176

177+
if (useARCoreOrientation) {
178+
auto orientation = AlvrQuat{arRawPose[0], arRawPose[1], arRawPose[2],
179+
arRawPose[3]};
180+
pose.orientation = orientation;
181+
CTX.lastOrientation = pose.orientation;
182+
}
183+
187184
ArPose_destroy(arPose);
188185
ArCamera_release(arCamera);
189186
}
@@ -338,14 +335,15 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_initia
338335
if (CTX.arcoreEnabled) {
339336
if (ArSession_create(env, CTX.javaContext, &CTX.arSession) != AR_SUCCESS) {
340337
error("initializeNative: Could not create ARCore session");
338+
CTX.arcoreEnabled = false;
341339
return;
342340
}
343341

344342
ArConfig* arConfig = nullptr;
345343
ArConfig_create(CTX.arSession, &arConfig);
346344

347345
// Explicitly disable all unnecessary features to preserve CPU power.
348-
ArConfig_setDepthMode(CTX.arSession, arConfig, AR_DEPTH_MODE_DISABLED);
346+
ArConfig_setDepthMode(CTX.arSession, arConfig, AR_DEPTH_MODE_AUTOMATIC);
349347
ArConfig_setLightEstimationMode(CTX.arSession, arConfig, AR_LIGHT_ESTIMATION_MODE_DISABLED);
350348
ArConfig_setPlaneFindingMode(CTX.arSession, arConfig, AR_PLANE_FINDING_MODE_HORIZONTAL_AND_VERTICAL);
351349

@@ -447,10 +445,6 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_sendBa
447445
extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_renderNative(JNIEnv *,
448446
jobject) {
449447
try {
450-
if (CTX.eglContext == nullptr) {
451-
CTX.eglContext = eglGetCurrentContext();
452-
}
453-
454448
if (CTX.renderingParamsChanged) {
455449
info("renderingParamsChanged, processing new params");
456450
uint8_t *buffer;

0 commit comments

Comments
 (0)