11#include " alvr_client_core.h"
22#include " arcore_c_api.h"
33#include " cardboard.h"
4- #include < GLES3/gl3.h>
54#include < EGL/egl.h>
5+ #include < GLES3/gl3.h>
66#include < algorithm>
77#include < android/log.h>
88#include < deque>
@@ -131,7 +131,8 @@ AlvrPose getPose(uint64_t timestampNs) {
131131 if (!CTX .arcoreEnabled || (CTX .arcoreEnabled && !useARCoreOrientation)) {
132132 float pos[3 ];
133133 float q[4 ];
134- CardboardHeadTracker_getPose (CTX .headTracker , (int64_t ) timestampNs, kLandscapeLeft , pos, q);
134+ CardboardHeadTracker_getPose (
135+ CTX .headTracker , (int64_t ) timestampNs, kLandscapeLeft , pos, q);
135136
136137 auto inverseOrientation = AlvrQuat{q[0 ], q[1 ], q[2 ], q[3 ]};
137138 pose.orientation = inverseQuat (inverseOrientation);
@@ -171,7 +172,6 @@ AlvrPose getPose(uint64_t timestampNs) {
171172 float arRawPose[7 ] = {0 .f , 0 .f , 0 .f , 0 .f , 0 .f , 0 .f , 0 .f };
172173 ArPose_getPoseRaw (CTX .arSession , arPose, arRawPose);
173174
174-
175175 /* We use an anchor here for two things:
176176 *
177177 * 1. To determine floor position by finding the lowest detected plane. We do this by
@@ -191,9 +191,8 @@ AlvrPose getPose(uint64_t timestampNs) {
191191 ArTrackableList_getSize (CTX .arSession , trackables, &detectedPlaneCount);
192192
193193 for (int i = 0 ; i < detectedPlaneCount; i++) {
194- ArTrackable* arTrackable = nullptr ;
195- ArTrackableList_acquireItem (CTX .arSession , trackables, i,
196- &arTrackable);
194+ ArTrackable *arTrackable = nullptr ;
195+ ArTrackableList_acquireItem (CTX .arSession , trackables, i, &arTrackable);
197196 const ArPlane *plane = ArAsPlane (arTrackable);
198197 ArTrackingState planeTrackingState;
199198 ArTrackable_getTrackingState (CTX .arSession , arTrackable, &planeTrackingState);
@@ -221,7 +220,8 @@ AlvrPose getPose(uint64_t timestampNs) {
221220
222221 if (planePoseRaw[5 ] < currentFloorPoseRaw[5 ]) {
223222 info (" Found new plane lower than pose (current %f vs new %f), reanchoring" ,
224- currentFloorPoseRaw[5 ], planePoseRaw[5 ]);
223+ currentFloorPoseRaw[5 ],
224+ planePoseRaw[5 ]);
225225 reanchor = true ;
226226 }
227227 }
@@ -232,10 +232,10 @@ AlvrPose getPose(uint64_t timestampNs) {
232232 ArAnchor_release (CTX .arFloorAnchor );
233233 }
234234
235- ArPose *planePoseNoRotation = ArPose_extractTranslation ( CTX . arSession ,
236- planePose);
237- ArTrackable_acquireNewAnchor (CTX . arSession , arTrackable, planePoseNoRotation,
238- &CTX .arFloorAnchor );
235+ ArPose *planePoseNoRotation =
236+ ArPose_extractTranslation ( CTX . arSession , planePose);
237+ ArTrackable_acquireNewAnchor (
238+ CTX . arSession , arTrackable, planePoseNoRotation, &CTX .arFloorAnchor );
239239 ArPose_destroy (planePoseNoRotation);
240240 }
241241
@@ -251,10 +251,16 @@ AlvrPose getPose(uint64_t timestampNs) {
251251 ArPose_create (CTX .arSession , nullptr , &anchorPose);
252252 ArAnchor_getPose (CTX .arSession , CTX .arFloorAnchor , anchorPose);
253253 ArPose_getPoseRaw (CTX .arSession , anchorPose, anchorRawPose);
254- info (" anchor pose %f %f %f %f %f %f %f" , anchorRawPose[0 ], anchorRawPose[1 ], anchorRawPose[2 ], anchorRawPose[3 ], anchorRawPose[4 ], anchorRawPose[5 ], anchorRawPose[6 ]);
254+ info (" anchor pose %f %f %f %f %f %f %f" ,
255+ anchorRawPose[0 ],
256+ anchorRawPose[1 ],
257+ anchorRawPose[2 ],
258+ anchorRawPose[3 ],
259+ anchorRawPose[4 ],
260+ anchorRawPose[5 ],
261+ anchorRawPose[6 ]);
255262 }
256263
257-
258264 pose.position [0 ] = arRawPose[4 ];
259265 pose.position [1 ] = arRawPose[5 ] - anchorRawPose[5 ];
260266 pose.position [2 ] = arRawPose[6 ];
@@ -264,8 +270,7 @@ AlvrPose getPose(uint64_t timestampNs) {
264270 }
265271
266272 if (useARCoreOrientation) {
267- auto orientation = AlvrQuat{arRawPose[0 ], arRawPose[1 ], arRawPose[2 ],
268- arRawPose[3 ]};
273+ auto orientation = AlvrQuat{arRawPose[0 ], arRawPose[1 ], arRawPose[2 ], arRawPose[3 ]};
269274 pose.orientation = orientation;
270275 CTX .lastOrientation = pose.orientation ;
271276 }
@@ -326,15 +331,19 @@ void inputThread() {
326331 // 2. Choose EGL configuration
327332 EGLint numConfigs;
328333 EGLConfig config;
329- EGLint configAttribs[] = {
330- EGL_RENDERABLE_TYPE , EGL_OPENGL_ES3_BIT ,
331- EGL_SURFACE_TYPE , EGL_PBUFFER_BIT ,
332- EGL_BLUE_SIZE , 8 ,
333- EGL_GREEN_SIZE , 8 ,
334- EGL_RED_SIZE , 8 ,
335- EGL_ALPHA_SIZE , 8 ,
336- EGL_NONE
337- };
334+ EGLint configAttribs[] = {EGL_RENDERABLE_TYPE ,
335+ EGL_OPENGL_ES3_BIT ,
336+ EGL_SURFACE_TYPE ,
337+ EGL_PBUFFER_BIT ,
338+ EGL_BLUE_SIZE ,
339+ 8 ,
340+ EGL_GREEN_SIZE ,
341+ 8 ,
342+ EGL_RED_SIZE ,
343+ 8 ,
344+ EGL_ALPHA_SIZE ,
345+ 8 ,
346+ EGL_NONE };
338347
339348 if (!eglChooseConfig (display, configAttribs, &config, 1 , &numConfigs)) {
340349 throw std::runtime_error (" Failed to choose EGL config." );
@@ -345,22 +354,17 @@ void inputThread() {
345354 }
346355
347356 // 3. Create an offscreen (pbuffer) surface
348- EGLint pbufferAttribs[] = {
349- EGL_WIDTH , 1920 ,
350- EGL_HEIGHT , 1920 ,
351- EGL_NONE
352- };
357+ EGLint pbufferAttribs[] = {EGL_WIDTH , 1920 , EGL_HEIGHT , 1920 , EGL_NONE };
353358
354359 EGLSurface surface = eglCreatePbufferSurface (display, config, pbufferAttribs);
355360 if (surface == EGL_NO_SURFACE ) {
356361 throw std::runtime_error (" Failed to create EGL pbuffer surface." );
357362 }
358363
359364 // 4. Create an EGL context
360- EGLint contextAttribs[] = {
361- EGL_CONTEXT_CLIENT_VERSION , 3 , // OpenGL ES 3.0 context
362- EGL_NONE
363- };
365+ EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION ,
366+ 3 , // OpenGL ES 3.0 context
367+ EGL_NONE };
364368
365369 EGLContext context = eglCreateContext (display, config, EGL_NO_CONTEXT , contextAttribs);
366370 if (context == EGL_NO_CONTEXT ) {
@@ -392,8 +396,13 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *) {
392396 return JNI_VERSION_1_6 ;
393397}
394398
395- extern " C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_initializeNative (
396- JNIEnv *env, jobject obj, jint screenWidth, jint screenHeight, jfloat refreshRate, jboolean enableARCore) {
399+ extern " C" JNIEXPORT void JNICALL
400+ Java_viritualisres_phonevr_ALVRActivity_initializeNative (JNIEnv *env,
401+ jobject obj,
402+ jint screenWidth,
403+ jint screenHeight,
404+ jfloat refreshRate,
405+ jboolean enableARCore) {
397406 CTX .javaContext = env->NewGlobalRef (obj);
398407
399408 uint32_t viewWidth = std::max (screenWidth, screenHeight) / 2 ;
@@ -428,16 +437,18 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_initia
428437 return ;
429438 }
430439
431- ArConfig* arConfig = nullptr ;
440+ ArConfig * arConfig = nullptr ;
432441 ArConfig_create (CTX .arSession , &arConfig);
433442
434443 // Explicitly disable all unnecessary features to preserve CPU power.
435444 ArConfig_setDepthMode (CTX .arSession , arConfig, AR_DEPTH_MODE_DISABLED );
436445 ArConfig_setLightEstimationMode (CTX .arSession , arConfig, AR_LIGHT_ESTIMATION_MODE_DISABLED );
437- ArConfig_setPlaneFindingMode (CTX .arSession , arConfig, AR_PLANE_FINDING_MODE_HORIZONTAL_AND_VERTICAL );
446+ ArConfig_setPlaneFindingMode (
447+ CTX .arSession , arConfig, AR_PLANE_FINDING_MODE_HORIZONTAL_AND_VERTICAL );
438448 ArConfig_setCloudAnchorMode (CTX .arSession , arConfig, AR_CLOUD_ANCHOR_MODE_DISABLED );
439449
440- // Set "latest camera image" update mode (ArSession_update returns immediately without blocking)
450+ // Set "latest camera image" update mode (ArSession_update returns immediately without
451+ // blocking)
441452 ArConfig_setUpdateMode (CTX .arSession , arConfig, AR_UPDATE_MODE_LATEST_CAMERA_IMAGE );
442453
443454 // TODO: Add camera config filter:
@@ -521,8 +532,8 @@ extern "C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_setScr
521532 CTX .renderingParamsChanged = true ;
522533}
523534
524- extern " C" JNIEXPORT void JNICALL Java_viritualisres_phonevr_ALVRActivity_setScreenRotationNative (
525- JNIEnv *, jobject, jint rotation) {
535+ extern " C" JNIEXPORT void JNICALL
536+ Java_viritualisres_phonevr_ALVRActivity_setScreenRotationNative ( JNIEnv *, jobject, jint rotation) {
526537 CTX .screenRotation = rotation;
527538 CTX .renderingParamsChanged = true ;
528539}
0 commit comments