Skip to content

Commit

Permalink
minor cleanups post-first-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
knuxify committed Nov 18, 2024
1 parent e142144 commit a7635e5
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions code/mobile/android/PhoneVR/app/src/main/cpp/alvr_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const int MAXIMUM_TRACKING_FRAMES = 360;
struct NativeContext {
JavaVM *javaVm = nullptr;
jobject javaContext = nullptr;
EGLContext eglContext = nullptr;

CardboardHeadTracker *headTracker = nullptr;
CardboardLensDistortion *lensDistortion = nullptr;
Expand Down Expand Up @@ -126,13 +125,13 @@ AlvrPose getPose(uint64_t timestampNs) {
AlvrPose pose = {};
bool returnLastPosition = false;

float pos[3];
float q[4];
CardboardHeadTracker_getPose(CTX.headTracker, (int64_t) timestampNs, kLandscapeLeft, pos, q);

auto inverseOrientation = AlvrQuat{q[0], q[1], q[2], q[3]};
pose.orientation = inverseQuat(inverseOrientation);
if (!CTX.arcoreEnabled || (CTX.arcoreEnabled && !useARCoreOrientation)) {
float pos[3];
float q[4];
CardboardHeadTracker_getPose(CTX.headTracker, (int64_t) timestampNs, kLandscapeLeft, pos, q);

auto inverseOrientation = AlvrQuat{q[0], q[1], q[2], q[3]};
pose.orientation = inverseQuat(inverseOrientation);
CTX.lastOrientation = pose.orientation;
}

Expand Down Expand Up @@ -165,25 +164,23 @@ AlvrPose getPose(uint64_t timestampNs) {
ArPose *arPose = nullptr;
ArPose_create(CTX.arSession, nullptr, &arPose);
ArCamera_getPose(CTX.arSession, arCamera, arPose);
//ArFrame_getAndroidSensorPose(CTX.arSession, CTX.arFrame, arPose);
// ArPose_getPoseRaw() returns a pose in {qx, qy, qz, qw, tx, ty, tz} format.
float arRawPose[7] = {0.f};
ArPose_getPoseRaw(CTX.arSession, arPose, arRawPose);
pose.position[0] = arRawPose[4];
pose.position[1] = arRawPose[5];
pose.position[2] = arRawPose[6];

if (useARCoreOrientation) {
auto inverseOrientation = AlvrQuat{arRawPose[0], arRawPose[1], arRawPose[2],
arRawPose[3]};
pose.orientation = inverseOrientation;
CTX.lastOrientation = pose.orientation;
}

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

if (useARCoreOrientation) {
auto orientation = AlvrQuat{arRawPose[0], arRawPose[1], arRawPose[2],
arRawPose[3]};
pose.orientation = orientation;
CTX.lastOrientation = pose.orientation;
}

ArPose_destroy(arPose);
ArCamera_release(arCamera);
}
Expand Down Expand Up @@ -338,14 +335,15 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_initia
if (CTX.arcoreEnabled) {
if (ArSession_create(env, CTX.javaContext, &CTX.arSession) != AR_SUCCESS) {
error("initializeNative: Could not create ARCore session");
CTX.arcoreEnabled = false;
return;
}

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

// Explicitly disable all unnecessary features to preserve CPU power.
ArConfig_setDepthMode(CTX.arSession, arConfig, AR_DEPTH_MODE_DISABLED);
ArConfig_setDepthMode(CTX.arSession, arConfig, AR_DEPTH_MODE_AUTOMATIC);
ArConfig_setLightEstimationMode(CTX.arSession, arConfig, AR_LIGHT_ESTIMATION_MODE_DISABLED);
ArConfig_setPlaneFindingMode(CTX.arSession, arConfig, AR_PLANE_FINDING_MODE_HORIZONTAL_AND_VERTICAL);

Expand Down Expand Up @@ -447,10 +445,6 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_sendBa
extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_renderNative(JNIEnv *,
jobject) {
try {
if (CTX.eglContext == nullptr) {
CTX.eglContext = eglGetCurrentContext();
}

if (CTX.renderingParamsChanged) {
info("renderingParamsChanged, processing new params");
uint8_t *buffer;
Expand Down

0 comments on commit a7635e5

Please sign in to comment.