// Update is called once per frame

    void Update()
    {
#if !UNITY_EDITOR
        if (m_camera != null)
        {
            // JUST WORKS!
            Matrix4x4 matrix = m_session.GetCameraPose();
            m_camera.transform.localPosition = UnityARMatrixOps.GetPosition(matrix);
            m_camera.transform.localRotation = UnityARMatrixOps.GetRotation(matrix);
            m_camera.projectionMatrix        = m_session.GetCameraProjection();
        }
        #endif
    }
Esempio n. 2
0
        // Update is called once per frame
        void Update()
        {
            Debug.Assert(_camera != null);

            // JUST WORKS!
            Matrix4x4 matrix = _session.GetCameraPose();

            _camera.transform.localPosition = UnityARMatrixOps.GetPosition(matrix);
            _camera.transform.localRotation = UnityARMatrixOps.GetRotation(matrix);

            ///...need update every frame?
            _camera.projectionMatrix = _session.GetCameraProjection();
        }
Esempio n. 3
0
    // Update is called once per frame
    void Update()
    {
        if (mFrameUpdated)
        {
            mFrameUpdated = false;
            if (mImage == null)
            {
                InitARFrameBuffer();
            }

            if (mARCamera.trackingState == ARTrackingState.ARTrackingStateNotAvailable)
            {
                // ARKit pose is not yet initialized
                return;
            }
            else if (!mARKitInit && LibPlacenote.Instance.Initialized())
            {
                mARKitInit = true;
                Debug.Log("ARKit + placenote Initialized");
                StartSavingMap();
            }

            Matrix4x4 matrix = mSession.GetCameraPose();

            Vector3    arkitPosition = PNUtility.MatrixOps.GetPosition(matrix);
            Quaternion arkitQuat     = PNUtility.MatrixOps.GetRotation(matrix);

            LibPlacenote.Instance.SendARFrame(mImage, arkitPosition, arkitQuat, mARCamera.videoParams.screenOrientation);

            if (shouldRecordWaypoints)
            {
                Transform player = Camera.main.transform;
                //create waypoints if there are none around
                Collider[] hitColliders = Physics.OverlapSphere(player.position, 1f);
                int        i            = 0;
                while (i < hitColliders.Length)   // a loop to check if there's any waypoint around in the radius of 1 meter, if there is return, doing nothing
                {
                    if (hitColliders[i].CompareTag("waypoint"))
                    {
                        return;
                    }
                    i++;
                }
                Vector3 pos = player.position; //if there are no way point add shape
                Debug.Log(player.position);
                pos.y = -.5f;
                shapeManager.AddShape(pos, Quaternion.Euler(Vector3.zero), false);
            }
        }
    }
Esempio n. 4
0
        // Update is called once per frame

        public void SetPose()
        {
            if (EnableCameraTracking)
            {
                if (m_camera != null)
                {
                    // JUST WORKS!
                    Matrix4x4 matrix = m_session.GetCameraPose();
                    m_camera.transform.localPosition = UnityARMatrixOps.GetPosition(matrix);
                    m_camera.transform.localRotation = UnityARMatrixOps.GetRotation(matrix);

                    if (!IgnoreProjectionMatrix)
                    {
                        m_camera.projectionMatrix = m_session.GetCameraProjection();
                    }
                }
            }
        }
Esempio n. 5
0
        // Update is called once per frame
        void Update()
        {
            //Debug.Log ("movementScale: " + VPETSettings.Instance.trackingScale.ToString());
            Matrix4x4 matrix = m_session.GetCameraPose();

            //transform.localPosition = UnityARMatrixOps.GetPosition (matrix) * VPETSettings.Instance.trackingScale * m_movementScale;
            transform.localPosition = UnityARMatrixOps.GetPosition(matrix) * m_movementScale;
            transform.localRotation = UnityARMatrixOps.GetRotation(matrix);
            if (m_arMode)
            {
                //for AR mode
                Camera.main.projectionMatrix = m_session.GetCameraProjection();
                foreach (Camera cam in Camera.main.transform.GetComponentsInChildren <Camera>())
                {
                    cam.projectionMatrix = Camera.main.projectionMatrix;
                }
            }
        }
Esempio n. 6
0
    void Update()
    {
#if UNITY_IOS
        if (sessionStarted)
        {
            Matrix4x4 matrix = m_session.GetCameraPose();
            m_camera.transform.localPosition = UnityARMatrixOps.GetPosition(matrix);
            m_camera.transform.localRotation = UnityARMatrixOps.GetRotation(matrix);

            m_camera.projectionMatrix = m_session.GetCameraProjection();
        }
#endif

#if UNITY_ANDROID
        transform.localPosition   = Frame.Pose.position;
        transform.localRotation   = Frame.Pose.rotation;
        m_camera.projectionMatrix = Frame.CameraImage.GetCameraProjectionMatrix(m_camera.nearClipPlane, m_camera.farClipPlane);
#endif
    }
Esempio n. 7
0
    // Update is called once per frame
    void Update()
    {
        if (mFrameUpdated)
        {
            mFrameUpdated = false;
            if (mImage == null)
            {
                InitARFrameBuffer();
            }

            if (mARCamera.trackingState == ARTrackingState.ARTrackingStateNotAvailable)
            {
                // ARKit pose is not yet initialized
                return;
            }
            else if (!mARKitInit)
            {
                mARKitInit      = true;
                mLabelText.text = "ARKit is ready!";
            }

            if (!LibPlacenote.Instance.Initialized())
            {
                //LibPlacenote is not ready
                return;
            }
            else if (!mPlacenoteInit)
            {
                mPlacenoteInit  = true;
                mLabelText.text = "Placenote is ready!";
                LoadMap();
            }

            Matrix4x4 matrix = mSession.GetCameraPose();

            Vector3    arkitPosition = PNUtility.MatrixOps.GetPosition(matrix);
            Quaternion arkitQuat     = PNUtility.MatrixOps.GetRotation(matrix);
            if (mARKitInit && mPlacenoteInit)
            {
                LibPlacenote.Instance.SendARFrame(mImage, arkitPosition, arkitQuat, mARCamera.videoParams.screenOrientation);
            }
        }
    }
Esempio n. 8
0
        // Update is called once per frame

        void FixedUpdate()
        {
#if !UNITY_EDITOR
            Matrix4x4 matrix = arSession.GetCameraPose();

            Vector3    pos       = UnityARMatrixOps.GetPosition(matrix);
            Vector3    worldPos  = arCameraSpace.TransformPoint(pos);
            Quaternion rot       = UnityARMatrixOps.GetRotation(matrix);
            Quaternion direction = Quaternion.Euler(0, arCameraSpace.eulerAngles.y, 0);
            Quaternion worldRot  = direction * rot;

            worldPos *= arCameraWorldScale;

            //Debug.Log("WovenARCameraManager: FixedUpdate: pos: " + pos.x + " " + pos.y + " " + pos.z + " rot: " + rot.x + " " + rot.y + " " + rot.z + " worldPos: " + worldPos.x + " " + worldPos.y + " " + worldPos.x + " worldRot: " + worldRot.x + " " + worldRot.y + " " + worldRot.z);

            arCameraHolderRigidbody.MovePosition(worldPos);
            arCameraHolderRigidbody.MoveRotation(worldRot);

            arCamera.projectionMatrix = arSession.GetCameraProjection();
#endif
        }
Esempio n. 9
0
        // Update is called once per frame
        void Update()
        {
            Matrix4x4 matrix = m_session.GetCameraPose();

            if (m_arMode)
            {
                transform.localPosition = UnityARMatrixOps.GetPosition(matrix) * 1f;
            }
            else
            {
                transform.localPosition = UnityARMatrixOps.GetPosition(matrix) * 200f; //m_movementScale;
            }
            transform.localRotation = UnityARMatrixOps.GetRotation(matrix);
            //Camera.main.projectionMatrix = m_session.GetCameraProjection();
            if (m_arMode)
            {
                //for AR mode
                Camera.main.projectionMatrix = m_session.GetCameraProjection();
                foreach (Camera cam in Camera.main.transform.GetComponentsInChildren <Camera>())
                {
                    cam.projectionMatrix = Camera.main.projectionMatrix;
                }
            }
        }
Esempio n. 10
0
    void Update()
    {
        if (m_camera != null)
        {
            Matrix4x4 matrix = m_session.GetCameraPose();

            Vector3 arPos         = UnityARMatrixOps.GetPosition(matrix);
            Vector3 diff          = arPos - lastArPos;
            Vector3 correctedDiff = new Vector3(
                sin * diff.z + cos * diff.x,
                diff.y,
                cos * diff.z - sin * diff.x);
            m_camera.transform.localPosition += correctedDiff;
            lastArPos = arPos;

            Quaternion r = UnityARMatrixOps.GetRotation(matrix);
            m_camera.transform.localRotation = Quaternion.Euler(
                r.eulerAngles.x,
                r.eulerAngles.y + initRotation.eulerAngles.y,
                r.eulerAngles.z);

            m_camera.projectionMatrix = m_session.GetCameraProjection();
        }
    }
Esempio n. 11
0
    protected override void Update()
    {
        if (IsNewLayer)
        {
            _sessionStarted = false;
        }
        base.Update();

        var layerItemList = LayerItemList;

        if (MenuEnabled.HasValue && MenuEnabled.Value && layerItemList != null && layerItemList.Any())
        {
            var fitToScanOverlay = FitToScanOverlay;
            if (fitToScanOverlay != null && fitToScanOverlay.activeSelf)
            {
                long nowTicks = DateTime.Now.Ticks;
                var  second   = nowTicks / 10000000L;
                if (!_fitToScanOverlayActivationSecond.HasValue)
                {
                    _fitToScanOverlayActivationSecond = second;
                    //Debug.LogFormat("FTS value {0}", _fitToScanOverlayActivationSecond.Value);
                }
                else
                {
                    var value = _fitToScanOverlayActivationSecond.Value;
                    if (value + 30 < second)
                    {
                        //Debug.LogFormat("FTS value {0}, second {1}", _fitToScanOverlayActivationSecond.Value, second);

                        var triggerObjects = TriggerObjects;
                        if (triggerObjects != null)
                        {
                            foreach (var t in triggerObjects.Values)
                            {
                                t.isActive = false;
                            }
                        }
                        _fitToScanOverlayActivationSecond = null;
                        MenuButtonClick = new MenuButtonClickActivity {
                            ArBehaviour = this
                        };
                    }
                    else
                    {
                        SetInfoText($"Timeout in {value + 30 - second} seconds.");
                    }
                }
            }
            else
            {
                _fitToScanOverlayActivationSecond = null;
            }
        }

#if IS_SLAM_APP
#else
        if (!_sessionStarted)
        {
            if (!HasTriggerImages)
            {
                StartArSession();
                return;
            }
            var anchorManager = AnchorManager.GetComponent <ArKitAnchorManager>();
            anchorManager.ArBehaviour      = this;
            anchorManager.TriggerObjects   = TriggerObjects;
            anchorManager.FitToScanOverlay = FitToScanOverlay;
            StartArSession(anchorManager.TriggerObjects);
        }
#endif
        if (m_camera != null && _sessionStarted)
        {
            // JUST WORKS!
            Matrix4x4 matrix = m_session.GetCameraPose();
            m_camera.transform.localPosition = UnityARMatrixOps.GetPosition(matrix);
            m_camera.transform.localRotation = UnityARMatrixOps.GetRotation(matrix);

            m_camera.projectionMatrix = m_session.GetCameraProjection();
        }
    }
Esempio n. 12
0
    void Update()
    {
        if (m_camera != null && sessionStarted)
        {
            // Positional information of AR camera
            Matrix4x4 matrix = m_session.GetCameraPose();
            Vector3   newPos = UnityARMatrixOps.GetPosition(matrix);

            passedTime += Time.deltaTime;

            // Get accelerometer difference (experimental)
            double acc = Input.acceleration.z - lastAcc.z;      //Changed from Float to double on 6 Apr to try and get Acc data to show
            if (acc > 0)
            {
                dir = Direction.backward;
            }
            else if (acc < 0)
            {
                dir = Direction.forward;
            }

            // Do speed calculation and update UI
            if (frames % speedFrames == 0)
            {
                double dist = Vector3.Distance(newPos, lastPos);        //Changed from Float to double on 6 Apr to try and get Acc data to show | Added 6 Apr
                speed          = dist / passedTime;
                speedText.text = "Speed " + speed.ToString();
                if (speed > 1)
                {
                    warningText.text = "Slow down!";
                    if (dir == Direction.forward)
                    {
                        directionText.text = "Forwards";
                    }
                    else
                    {
                        directionText.text = "Backwards";
                    }
                }
                else
                {
                    warningText.text   = "";
                    directionText.text = "";
                }
                // Reset counters and update last recorded info
                frames     = 0;
                passedTime = 0;
                lastPos    = m_camera.transform.localPosition;
                lastAcc    = Input.acceleration;
                // Debug text
                posText.text          = "Pos: " + m_camera.transform.localPosition;
                accText.text          = "Acc: " + (string.Format("{0:0.000000000000}", (Input.acceleration - lastAcc))); //Ensure it's formatting value to 12 places after the decimal point so that it's clear whether there's any value in there.
                debugAccText.text     = "Acc Debug: " + (Input.acceleration);                                            //Display Current Acceleration to debug the Acceleration bug: Added 6 Apr
                debugAccTypeText.text = "Acc Type: " + (Input.acceleration.GetType());                                   //Added 6 Apr: Should Display type of the Input.accleration val to determine if it's an int
            }
            frames++;
            // Move game camera to new position/rotation sensed
            m_camera.transform.localPosition = UnityARMatrixOps.GetPosition(matrix);
            m_camera.transform.localRotation = UnityARMatrixOps.GetRotation(matrix);
            m_camera.projectionMatrix        = m_session.GetCameraProjection();
        }
    }
Esempio n. 13
0
    // Update is called once per frame


    //Edited by Chris 21/01/2018
    void Update()
    {
        if (m_camera != null)
        {
            //This is the original way of retrieving position and rotation from UnityARSessionNativeInterface
            //m_session.GetCameraPose(); retrieves the unaltered pose as estimated by ARKit.
            //Altering the pose here, in UnityARCameraManager, is simpler than attempting to do so in
            //UnityARSessionNativeInterface, as it does not require the position and rotation information to
            //be injected into the world transform matrix.

            Matrix4x4 matrix = m_session.GetCameraPose();
            //#if !UNITY_EDITOR
            arkit_position = UnityARMatrixOps.GetPosition(matrix);
            arkit_rotation = UnityARMatrixOps.GetRotation(matrix);
            //#endif

            //It is instead possible to attempt to perform all camera adjustments below:

            Vector4    unityCameraPosition;
            Quaternion unityCameraRotation;

            //Debug.Log(tracking);

            if (tracking == TrackingType.TrackerRelay)
            {
                resetCameraParent();
                unityCameraPosition = tracker_position;
                unityCameraRotation = tracker_rotation;
            }
            else if (tracking == TrackingType.HeadsetRelay)
            {
                resetCameraParent();

                unityCameraPosition = headset_position;
                unityCameraRotation = headset_rotation;

                //Spectating mode - AR camera behind and above VR, looking down at scene
                CalculateSpectatePose(headset_position, headset_rotation, spectateCameraDistance, spectateCameraAngle,
                                      out unityCameraPosition, out unityCameraRotation);
            }
            else if (tracking == TrackingType.ARKit)
            {
                //Setting the Unity camera pose to purely ARKit's pose estimation
                resetCameraParent();
                unityCameraPosition = arkit_position;
                unityCameraRotation = arkit_rotation;
            }
            else
            {
                //NEW CALIBRATION
                //do not reset camera parent
                unityCameraPosition = arkit_position;
                unityCameraRotation = arkit_rotation;

                // OR TRY THIS
                // resetCameraParent();
                // unityCameraPosition = arkit_position + offset_position;
                // unityCameraRotation = arkit_rotation * offset_rotation;
            }

            m_camera.transform.localPosition = unityCameraPosition;
            m_camera.transform.localRotation = unityCameraRotation;

            //TODO: Check whether the projectionMatrix is influenced by localposition and rotation
            //(But it shouldn't be, and we should not need to alter it)
            m_camera.projectionMatrix = m_session.GetCameraProjection();
        }
    }