示例#1
0
        protected override void OnUpdate(float timeStep)
        {
            if (paused)
            {
                return;
            }

            if (Camera == null)
            {
                throw new Exception("ARCore.Camera property was not set");
            }

            try
            {
                var frame = Session.Update();
                if (paused)                 //in case if Config.UpdateMode.LatestCameraImage is not used
                {
                    return;
                }

                var camera = frame.Camera;
                if (camera.TrackingState != TrackableTrackingState.Tracking)
                {
                    return;
                }

                var far  = 100f;
                var near = 0.01f;

                float[] projmx = new float[16];
                camera.GetProjectionMatrix(projmx, 0, near, far);

                var prj = new Urho.Matrix4(
                    projmx[0], projmx[4], projmx[8], projmx[12],
                    projmx[1], projmx[5], projmx[9], projmx[13],
                    projmx[2], projmx[6], projmx[10], projmx[14],
                    projmx[3], projmx[7], projmx[11], projmx[15]
                    );

                //some OGL -> DX conversion (Urho accepts DX format on all platforms)
                prj.M34 /= 2f;
                prj.M33  = far / (far - near);
                prj.M43 *= -1;
                //prj.M13 = 0; //center of projection
                //prj.M23 = 0;

                Camera.SetProjection(prj);

                float[] viewmx = new float[16];
                camera.GetViewMatrix(viewmx, 0);

                var view = new Urho.Matrix4(
                    viewmx[0], viewmx[4], viewmx[8], viewmx[12],
                    viewmx[1], viewmx[5], viewmx[9], viewmx[13],
                    viewmx[2], viewmx[6], viewmx[10], viewmx[14],
                    viewmx[3], viewmx[7], viewmx[11], viewmx[15]);

                // some magic:
                view.Invert();
                view.Transpose();

                var rot = view.Rotation;
                rot.Z *= -1;

                var cameraNode = Camera.Node;

                cameraNode.Position = new Vector3(view.Row3.X, view.Row3.Y, -view.Row3.Z);
                cameraNode.Rotation = rot;

                ARFrameUpdated?.Invoke(frame);
            }
            catch (Exception exc)
            {
                Log.Write(LogLevel.Warning, "ARCore error: " + exc);
            }
        }
示例#2
0
        protected override void OnUpdate(float timeStep)
        {
            if (paused)
            {
                return;
            }

            if (Camera == null)
            {
                throw new Exception("ARCore.Camera property was not set");
            }

            try
            {
                if (Session == null)
                {
                    return;
                }

                var frame = Session.Update();
                if (paused)                 //in case if Config.UpdateMode.LatestCameraImage is not used
                {
                    return;
                }

                var camera = frame.Camera;
                if (camera.TrackingState != TrackingState.Tracking)
                {
                    return;
                }

                var far  = 100f;
                var near = 0.01f;

                float[] projmx = new float[16];
                camera.GetProjectionMatrix(projmx, 0, near, far);

                var prj = new Urho.Matrix4(
                    projmx[0], projmx[4], projmx[8], projmx[12],
                    projmx[1], projmx[5], projmx[9], projmx[13],
                    projmx[2], projmx[6], projmx[10], projmx[14],
                    projmx[3], projmx[7], projmx[11], projmx[15]
                    );

                //some OGL -> DX conversion (Urho accepts DX format on all platforms)
                prj.M34 /= 2f;
                prj.M33  = far / (far - near);
                prj.M43 *= -1;
                //prj.M13 = 0; //center of projection
                //prj.M23 = 0;

                Camera.SetProjection(prj);

                TransformByPose(Camera.Node, camera.DisplayOrientedPose);
                ARFrameUpdated?.Invoke(frame);
            }
            catch (Exception exc)
            {
                Log.Write(LogLevel.Warning, "ARCore error: " + exc);
            }
        }