Example #1
0
 /// <summary>
 /// Updates the session display geometry if a change was posted by
 /// <see cref="Framework.Services.Platform.OnScreenSizeChanged"/> event.
 /// This function should be called explicitly before each call to
 /// <see cref="Google.AR.Core.Session.Update"/>. This function will also clear the 'pending update'
 /// (viewportChanged) flag.
 /// </summary>
 /// <param name="session">the <see cref="Google.AR.Core.Session"/> object to update if display geometry changed.</param>
 private void UpdateDisplayGeometryIfNeeded(Google.AR.Core.Session session)
 {
     if (this.viewportChanged)
     {
         SurfaceOrientation displayRotation;
         this.platform.DisplayOrientation.ToSurfaceOrientation(out displayRotation);
         session.SetDisplayGeometry((int)displayRotation, this.platform.ScreenWidth, this.platform.ScreenHeight);
         this.viewportChanged = false;
     }
 }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Main);

            mSurfaceView = FindViewById(Resource.Id.surfaceview) as GLSurfaceView;

            mDisplayRotationHelper = new DisplayRotationHelper(this);

            Java.Lang.Exception exception = null;
            string message = null;

            try {
                mSession = new Session(/*context=*/ this);
            } catch (UnavailableArcoreNotInstalledException e) {
                message   = "Please install ARCore";
                exception = e;
            } catch (UnavailableApkTooOldException e) {
                message   = "Please update ARCore";
                exception = e;
            } catch (UnavailableSdkTooOldException e) {
                message   = "Please update this app";
                exception = e;
            } catch (Java.Lang.Exception e) {
                exception = e;
                message   = "This device does not support AR";
            }

            if (message != null)
            {
                Toast.MakeText(this, message, ToastLength.Long).Show();
                return;
            }

            // Create default config, check is supported, create session from that config.
            var config = new Config(mSession);

            if (!mSession.IsSupported(config))
            {
                Toast.MakeText(this, "This device does not support AR", ToastLength.Long).Show();
                Finish();
                return;
            }

            mGestureDetector = new Android.Views.GestureDetector(this, new SimpleTapGestureDetector {
                SingleTapUpHandler = (MotionEvent arg) => {
                    onSingleTap(arg);
                    return(true);
                },
                DownHandler = (MotionEvent arg) => true
            });

            mSurfaceView.SetOnTouchListener(this);

            // Set up renderer.
            mSurfaceView.PreserveEGLContextOnPause = true;
            mSurfaceView.SetEGLContextClientVersion(2);
            mSurfaceView.SetEGLConfigChooser(8, 8, 8, 8, 16, 0);             // Alpha used for plane blending.
            mSurfaceView.SetRenderer(this);
            mSurfaceView.RenderMode = Rendermode.Continuously;
        }