Exemplo n.º 1
0
    // Update is called once per frame

    void Update()
    {
        int num = planeDetector.GetPlaneNum();

        //Debug.Log("num:" + num);
        if (configFlg && num >= 1)
        {
            StopPlaneConfig();
        }
        //}else if(num <= 1){
        //    // startのconfigを実行
        //    //configFlg = false;



        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();
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame

    void Update()
    {
        if (m_camera != null && sessionStarted)
        {
            // JUST WORKS!

            if (GhostTrackingEnabled)
            {
                Matrix4x4 matrix = m_session.GetCameraPose();

                Vector3 pos  = UnityARMatrixOps.GetPosition(matrix);
                Vector3 pos2 = pos;
                pos2.x += (pos.x - prevLocation.x) * 4.0f;
                pos2.y += (pos.y - prevLocation.y) * 4.0f;
                pos2.z += (pos.z - prevLocation.z) * 4.0f;
                Vector3 pos3 = m_camera.transform.localPosition;
                pos3.x = m_camera.transform.localPosition.x + (pos2.x - m_camera.transform.localPosition.x) * 0.8f;
                pos3.y = m_camera.transform.localPosition.y + (pos2.y - m_camera.transform.localPosition.y) * 0.8f;
                pos3.z = m_camera.transform.localPosition.z + (pos2.z - m_camera.transform.localPosition.z) * 0.8f;
                m_camera.transform.localPosition = pos;
                prevLocation = pos;

                Vector3 rot  = UnityARMatrixOps.GetRotation(matrix).eulerAngles;
                Vector3 rot2 = rot;
                rot2.x += (rot.x - prevRotation.x) * 4.0f;
                rot2.y += (rot.y - prevRotation.y) * 4.0f;
                rot2.z += (rot.z - prevRotation.z) * 4.0f;
                Vector3 rot3 = m_camera.transform.localEulerAngles;
                rot3.x = m_camera.transform.localEulerAngles.x + (rot2.x - m_camera.transform.localEulerAngles.x) * 0.8f;
                rot3.y = m_camera.transform.localEulerAngles.y + (rot2.y - m_camera.transform.localEulerAngles.y) * 0.8f;
                rot3.z = m_camera.transform.localEulerAngles.z + (rot2.z - m_camera.transform.localEulerAngles.z) * 0.8f;
                m_camera.transform.localEulerAngles = rot3;
                prevRotation = rot;

                m_camera.projectionMatrix = m_session.GetCameraProjection();
            }
            else
            {
                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();
            }
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame
    // Heavily edited from original ARKit implementation (included below, commented out)
    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();
            arkit_position = UnityARMatrixOps.GetPosition(matrix);
            arkit_rotation = UnityARMatrixOps.GetRotation(matrix);

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

            Vector4    unityCameraPosition;
            Quaternion unityCameraRotation;

            //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;
            }
            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;
            }

            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();
        }
    }
Exemplo n.º 4
0
 private void Update()
 {
     if (m_camera != null)
     {
         Matrix4x4 cameraPose = m_session.GetCameraPose();
         m_camera.transform.localPosition = UnityARMatrixOps.GetPosition(cameraPose);
         m_camera.transform.localRotation = UnityARMatrixOps.GetRotation(cameraPose);
         m_camera.projectionMatrix        = m_session.GetCameraProjection();
     }
 }
Exemplo n.º 5
0
 // Update is called once per frame
 void Update()
 {
     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();
     }
 }
Exemplo n.º 6
0
    void Update()
    {
        if (m_camera != null)
        {
            Matrix4x4 matrix = ARSessionInterface.GetCameraPose();
            m_camera.transform.localPosition = UnityARMatrixOps.GetPosition(matrix);
            m_camera.transform.localRotation = UnityARMatrixOps.GetRotation(matrix);

            m_camera.projectionMatrix = ARSessionInterface.GetCameraProjection();
        }
    }
 void Update()
 {
     m_camera.gameObject.SetActive(true);
     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();
     }
 }
Exemplo n.º 8
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();
        }
Exemplo n.º 9
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();
                    }
                }
            }
        }
Exemplo n.º 10
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;
                }
            }
        }
Exemplo n.º 11
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
    }
Exemplo n.º 12
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
        }
Exemplo n.º 13
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;
                }
            }
        }
Exemplo n.º 14
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();
        }
    }
Exemplo n.º 15
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();
        }
    }
Exemplo n.º 16
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();
        }
    }