예제 #1
0
    public void OnARKitAnchorUpdated(ARPlaneAnchor planeAnchor)
    {
        if (false == this.planeAnchorDictionary.ContainsKey(planeAnchor.identifier))
        {
            return;
        }
        ARPlaneAnchorGameObject planeAnchorObject = this.planeAnchorDictionary [planeAnchor.identifier];

        planeAnchorObject.planeAnchor = planeAnchor;
        Vector3 originPosition = UnityARMatrixOps.GetPosition(planeAnchor.transform);

        this.icon.name = planeAnchor.identifier;
        this.icon.transform.position = UnityARMatrixOps.GetPosition(planeAnchor.transform);
        this.icon.transform.rotation = UnityARMatrixOps.GetRotation(planeAnchor.transform);
        return;
    }
예제 #2
0
    void UpdateImageAnchor(ARImageAnchor arImageAnchor)
    {
        Debug.Log("image anchor updated");
        if (arImageAnchor.referenceImageName == imageParsons.imageName ||
            arImageAnchor.referenceImageName == imageEcal.imageName)
        {
            imageAnchorGO.transform.position = UnityARMatrixOps.GetPosition(arImageAnchor.transform);
            imageAnchorGO.transform.rotation = UnityARMatrixOps.GetRotation(arImageAnchor.transform);
//			Debug.Log ("Y = " + imageAnchorGO.transform.position.y);

            // No need to update the origin again, ARKit seems smart.
            //updateWorldOrigin (imageAnchorGO.transform);
        }

        yPos = imageAnchorGO.transform.position.y;
        Debug.Log("imageAnchorGo y position + " + yPos);
    }
예제 #3
0
    bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes)
    {
        List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes);

        if (hitResults.Count > 0)
        {
            foreach (var hitResult in hitResults)
            {
                Debug.Log("Got hit!");
                m_HitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                m_HitTransform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform);
                Debug.Log(string.Format("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z));
                return(true);
            }
        }
        return(false);
    }
예제 #4
0
    bool HitTestWithResultType1(ARPoint point, ARHitTestResultType resultTypes)
    {
        List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes);

        if (hitResults.Count > 0)
        {
            foreach (var hitResult in hitResults)
            {
                //TODO: get the position and rotations to spawn the hat. Done:
                Vector3    pos      = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                Quaternion rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform);
                spawnedObjects.Add(Instantiate(Terrain, pos, rotation));                    // in order to use for shuffling
                return(true);
            }
        }
        return(false);
    }
예제 #5
0
    // Q1: Scan angle will lead to different generation
    void AddImageAnchor(ARImageAnchor arImageAnchor)
    {
        Debug.Log("image anchor added");
        if (arImageAnchor.referenceImageName == referenceImage.imageName)
        {
            Vector3    position    = UnityARMatrixOps.GetPosition(arImageAnchor.transform);
            Vector3    newposition = new Vector3(position.x, position.y - referenceD, position.z);
            Quaternion rotation    = UnityARMatrixOps.GetRotation(arImageAnchor.transform);
            Quaternion newrotation = Quaternion.Euler(rotation.x, rotation.y - 90, rotation.z);

            imageAnchorGO = Instantiate <GameObject> (prefabToGenerate, newposition, newrotation);
            // new edited
            Debug.Log(newposition);
            PathCoordinates.text = imageAnchorGO.transform.position.ToString();
            PathRotation.text    = rotation.ToString();
        }
    }
예제 #6
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();
            }
        }
    }
예제 #7
0
    public void PlaceOnCamera(Camera camera)
    {
        Vector3 viewPortPos = Vector3.zero;

        switch (_component)
        {
        case ARKitOriginComponent.Origin:
            viewPortPos = Camera.main.ScreenToViewportPoint(Vector3.forward);
            break;

        case ARKitOriginComponent.Right:
            viewPortPos = Camera.main.ScreenToViewportPoint(new Vector3(0.5f, 0.0f, 1.0f));
            break;

        case ARKitOriginComponent.Forward:
            viewPortPos = Camera.main.ScreenToViewportPoint(new Vector3(0.0f, 0.5f, 1.0f));
            break;
        }
        Vector3 screenPosition = Camera.main.ScreenToViewportPoint(viewPortPos);
        ARPoint point          = new ARPoint
        {
            x = screenPosition.x,
            y = screenPosition.y
        };

        // prioritize reults types
        ARHitTestResultType[] resultTypes =
        {
            ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent,
            ARHitTestResultType.ARHitTestResultTypeHorizontalPlane,
            ARHitTestResultType.ARHitTestResultTypeFeaturePoint
        };
        foreach (ARHitTestResultType resultType in resultTypes)
        {
            UnityARSessionNativeInterface session    = UnityARSessionNativeInterface.GetARSessionNativeInterface();
            List <ARHitTestResult>        hitResults = session.HitTest(point, resultType);
            if (hitResults.Count > 0)
            {
                foreach (var hitResult in hitResults)
                {
                    m_HitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                    m_HitTransform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform);
                }
            }
        }
    }
예제 #8
0
        void AddImageAnchor(ARImageAnchor arImageAnchor)
        {
            if (imageAnchorGO != null)
            {
                return;
            }

            Debug.Log("image anchor added");
            if (arImageAnchor.referenceImageName == referenceImage.imageName)
            {
                Vector3    position = UnityARMatrixOps.GetPosition(arImageAnchor.transform);
                Quaternion rotation = UnityARMatrixOps.GetRotation(arImageAnchor.transform);

                imageAnchorGO = Instantiate <GameObject> (prefabToGenerate, position, rotation);
                imageAnchorGO.gameObject.SetActive(true);
            }
        }
예제 #9
0
    bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes)
    {
        List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes);

        if (hitResults.Count > 0)
        {
            foreach (var hitResult in hitResults)
            {
                foundReticle.transform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform); // + new Vector3(0f, 0.05f, 0f);
                foundReticle.transform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform);
                foundReticle.transform.LookAt(new Vector3(Camera.main.transform.position.x, foundReticle.transform.position.y, Camera.main.transform.position.z));
                Debug.Log(string.Format("x:{0:0.######} y:{1:0.######} z:{2:0.######}", foundReticle.transform.position.x, foundReticle.transform.position.y, foundReticle.transform.position.z));
                return(true);
            }
        }
        return(false);
    }
예제 #10
0
    bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes)
    {
        List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes);

        if (hitResults.Count > 0)
        {
            foreach (var hitResult in hitResults)
            {
                hitTransform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                hitTransform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform);
                catControl.MoveTo(hitTransform.position, -0.15f);
                Show();
                return(true);
            }
        }
        return(false);
    }
예제 #11
0
        void FaceUpdated(ARFaceAnchor anchorData)
        {
            if (_displayMesh == null)
            {
                return;
            }

            transform.localPosition = UnityARMatrixOps.GetPosition(anchorData.transform);
            transform.localRotation = UnityARMatrixOps.GetRotation(anchorData.transform);

            _displayMesh.vertices  = anchorData.faceGeometry.vertices;
            _displayMesh.uv        = anchorData.faceGeometry.textureCoordinates;
            _displayMesh.triangles = anchorData.faceGeometry.triangleIndices;

            _displayMesh.RecalculateBounds();
            _displayMesh.RecalculateNormals();
        }
예제 #12
0
    void FaceAdded(ARFaceAnchor anchorData)
    {
        gameObject.transform.localPosition = UnityARMatrixOps.GetPosition(anchorData.transform);
        gameObject.transform.localRotation = UnityARMatrixOps.GetRotation(anchorData.transform);



        faceMesh           = new Mesh();
        faceMesh.vertices  = anchorData.faceGeometry.vertices;
        faceMesh.uv        = anchorData.faceGeometry.textureCoordinates;
        faceMesh.triangles = anchorData.faceGeometry.triangleIndices;

        // Assign the mesh object and update it.
        faceMesh.RecalculateBounds();
        faceMesh.RecalculateNormals();
        meshFilter.mesh = faceMesh;
    }
예제 #13
0
    void UpdateImageAnchor(ARImageAnchor arImageAnchor)
    {
        Debug.LogFormat("image anchor updated[{0}] : tracked => {1}", arImageAnchor.identifier, arImageAnchor.isTracked);
        if (arImageAnchor.referenceImageName == referenceImage.imageName)
        {
            if (arImageAnchor.isTracked)
            {
                if (!shinkawa.activeSelf)
                {
                    shinkawa.SetActive(true);
                }
                shinkawa.transform.position = UnityARMatrixOps.GetPosition(arImageAnchor.transform) + shinkawaPos;
                shinkawa.transform.rotation = UnityARMatrixOps.GetRotation(arImageAnchor.transform);
                shinkawa.transform.Rotate(new Vector3(0, 90, 90));
                shinkawa.transform.localScale = shinkawaScale;

                if (!desk.activeSelf)
                {
                    desk.SetActive(true);
                }
                desk.transform.position = UnityARMatrixOps.GetPosition(arImageAnchor.transform) + deskPos;
                desk.transform.rotation = UnityARMatrixOps.GetRotation(arImageAnchor.transform);
                desk.transform.Rotate(new Vector3(0, 0, 90));
                desk.transform.localScale = deskScale;
                deskMeshRenderer.material = material;

                if (!autd.activeSelf)
                {
                    autd.SetActive(true);
                }
                autd.transform.position = UnityARMatrixOps.GetPosition(arImageAnchor.transform) + autdPos;
                autd.transform.rotation = UnityARMatrixOps.GetRotation(arImageAnchor.transform);
                autd.transform.Rotate(new Vector3(0, 90, 90));
                autd.transform.localScale       = autdScale;
                autdChild1MeshRenderer.material = material;
                autdChild2MeshRenderer.material = material;
            }
            else if (shinkawa.activeSelf || desk.activeSelf || autd.activeSelf)
            {
                shinkawa.SetActive(false);
                desk.SetActive(false);
                autd.SetActive(false);
            }
        }
    }
예제 #14
0
    void Update()
    {
        List <ARHitTestResult> hitResults;
        ARPoint point;

        //float scale;


        if (Input.touchCount > 0 && anchor != null)
        {
            var touch = Input.GetTouch(0);
            if (touch.phase == TouchPhase.Began)
            {
                Vector2 center         = new Vector2(Screen.width / 2, Screen.height / 2);
                Vector3 screenPosition = Camera.main.ScreenToViewportPoint(center);
                point.x = screenPosition.x;
                point.y = screenPosition.y;
                //Vector2 edge = new Vector2 (Screen.width, Screen.height / 2);
                //Vector3 screenEdge = Camera.main.ScreenToViewportPoint (edge);
                //scale = screenPosition.x - screenEdge.x;

                hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point,
                                                                                                 ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent);
                if (hitResults.Count == 0)
                {
                    hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point,
                                                                                                     ARHitTestResultType.ARHitTestResultTypeHorizontalPlane);
                }
                if (hitResults.Count == 0)
                {
                    hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point,
                                                                                                     ARHitTestResultType.ARHitTestResultTypeFeaturePoint);
                }

                if (hitResults.Count > 0)
                {
                    anchor.position = UnityARMatrixOps.GetPosition(hitResults [0].worldTransform);
                    anchor.rotation = UnityARMatrixOps.GetRotation(hitResults [0].worldTransform);
                    //Debug.Log("ARHitHandler scale: " + scale);
                    //anchor.localScale = new Vector3(scale, scale, scale);
                    controller.ToggleAnchor();
                }
            }
        }
    }
예제 #15
0
        /// <summary>
        /// Performs a Raycast against a plane.
        /// </summary>
        /// <param name="camera">The AR camera being used.</param>
        /// <param name="x">The x screen position.</param>
        /// <param name="y">The y screen position.</param>
        /// <param name="hitPose">The resulting hit pose if the method returns <c>true</c>.</param>
        /// <returns><c>true</c> if a plane was hit. Otherwise <c>false</c>.</returns>
        public bool RaycastPlane(Camera camera, float x, float y, out Pose hitPose)
        {
            hitPose = new Pose();
#if ARCORE_IOS_SUPPORT
            var session = UnityARSessionNativeInterface.GetARSessionNativeInterface();

            var     viewportPoint = camera.ScreenToViewportPoint(new Vector2(x, y));
            ARPoint arPoint       = new ARPoint
            {
                x = viewportPoint.x,
                y = viewportPoint.y
            };

            m_HitResultList = session.HitTest(arPoint, ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent);
            if (m_HitResultList.Count > 0)
            {
                int minDistanceIndex = 0;
                for (int i = 1; i < m_HitResultList.Count; i++)
                {
                    if (m_HitResultList[i].distance < m_HitResultList[minDistanceIndex].distance)
                    {
                        minDistanceIndex = i;
                    }
                }

                hitPose.position = UnityARMatrixOps.GetPosition(m_HitResultList[minDistanceIndex].worldTransform);

                // Original ARKit hit pose is the plane rotation.
                Quaternion planeRotation = UnityARMatrixOps.GetRotation(
                    m_HitResultList[minDistanceIndex].worldTransform);

                // Try to match the hit rotation to the one ARCore uses.
                Vector3 planeNormal     = planeRotation * Vector3.up;
                Vector3 rayDir          = camera.ViewportPointToRay(viewportPoint).direction;
                Vector3 planeProjection = Vector3.ProjectOnPlane(rayDir, planeNormal);
                Vector3 forwardDir      = -planeProjection.normalized;

                Quaternion hitRotation = Quaternion.LookRotation(forwardDir, planeNormal);
                hitPose.rotation = hitRotation;

                return(true);
            }
#endif
            return(false);
        }
예제 #16
0
    private GameObject UpdatePlaneWithAnchorTransform(GameObject plane, ARPlaneAnchor arPlaneAnchor)
    {
        // ARKit座標をUnity座標に変換
        plane.transform.position = UnityARMatrixOps.GetPosition(arPlaneAnchor.transform);
        plane.transform.rotation = UnityARMatrixOps.GetRotation(arPlaneAnchor.transform);

        MeshFilter mf = plane.GetComponentInChildren <MeshFilter> ();

        if (mf != null)
        {
            //since our plane mesh is actually 10mx10m in the world, we scale it here by 0.1f
            mf.gameObject.transform.localScale = new Vector3(arPlaneAnchor.extent.x * 0.1f, arPlaneAnchor.extent.y * 0.1f, arPlaneAnchor.extent.z * 0.1f);
            //convert our center position to unity coords
            mf.gameObject.transform.localPosition = new Vector3(arPlaneAnchor.center.x, arPlaneAnchor.center.y, -arPlaneAnchor.center.z);
        }

        return(plane);
    }
예제 #17
0
    bool HitTestWithResultType(ARPoint point, ARHitTestResultType resultTypes)
    {
        List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, resultTypes);

        if (hitResults.Count > 0)
        {
            foreach (var hitResult in hitResults)
            {
                //TODO: get the position and rotations to spawn the hat
                Vector3    pos = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                Quaternion rot = UnityARMatrixOps.GetRotation(hitResult.worldTransform);
                GameObject go  = Instantiate(hitPrefab, pos, rot);
                spawnedObjects.Add(go);
                return(true);
            }
        }
        return(false);
    }
예제 #18
0
    void UnityARSessionNativeInterface_ARUserAnchorAddedEvent(ARUserAnchor anchorData)
    {
        // TODO: FIX ALL THIS SHIT.
        AnchoringFound = true;
        moveDeviceUI.SetActive(false);

        Transform child = GetChildForAnchorId(anchorData.identifier);

        child.position   = UnityARMatrixOps.GetPosition(anchorData.transform);
        child.rotation   = UnityARMatrixOps.GetRotation(anchorData.transform);
        child.localScale = new Vector3(PlayerPrefs.GetFloat(GlobalMapManager.Instance.GetPlayerPrefScaleXKey(anchorData.identifier)), PlayerPrefs.GetFloat(GlobalMapManager.Instance.GetPlayerPrefScaleYKey(anchorData.identifier)), PlayerPrefs.GetFloat(GlobalMapManager.Instance.GetPlayerPrefScaleZKey(anchorData.identifier)));

        // Fade in newly placed model
        FadeInModel(child);
        child.gameObject.SetActive(true);

        Debug.LogFormat("Added anchor: {0} | {1}", anchorData.identifier, child.position.ToString("F2"));
    }
예제 #19
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;
                }
            }
        }
예제 #20
0
    void UpdateImageAnchor(ARImageAnchor arImageAnchor)
    {
        Debug.LogFormat("image anchor updated[{0}] : tracked => {1}", arImageAnchor.identifier, arImageAnchor.isTracked);
        if (arImageAnchor.referenceImageName == referenceImage.imageName)
        {
            if (arImageAnchor.isTracked)
            {
                if (!imageAnchorGO.activeSelf)
                {
                    imageAnchorGO.SetActive(true);
                }

                imageAnchorGO.transform.position   = UnityARMatrixOps.GetPosition(arImageAnchor.transform) + new Vector3(0f, planetHeight, 0f);
                imageAnchorGO.transform.localScale = new Vector3(planetScale, planetScale, planetScale);
                imageAnchorGO.transform.rotation   = UnityARMatrixOps.GetRotation(arImageAnchor.transform);
            }
        }
    }
        private void OnPlaneFound(ARHitTestResult hitResult)
        {
            Debug.Log("<color=cyan>OnPlaneFound</color>");

            GameObject anchor = new GameObject("game world");

            anchor.transform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
            anchor.transform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform);

            planeFound(anchor);

            if (_previousAnchor != null)
            {
                Destroy(_previousAnchor);
            }

            _previousAnchor = anchor;
        }
예제 #22
0
 void UpdateImageAnchor(ARImageAnchor arImageAnchor)
 {
     Debug.Log("image anchor updated");
     if (arImageAnchor.referenceImageName == referenceImage.imageName)
     {
         if (scene)
         {
             Vector3 newPos = UnityARMatrixOps.GetPosition(arImageAnchor.transform);
             scene.transform.position = newPos;
             scene.transform.rotation = Quaternion.Euler(0, UnityARMatrixOps.GetRotation(arImageAnchor.transform).eulerAngles.y, 0);
             GameObject modifier = GameObject.Find("Scene/ARModifier");
             if (modifier)
             {
                 modifier.transform.localScale = Vector3.one * (Vector3.Distance(Camera.main.transform.position, newPos) / 15) * (Camera.main.fieldOfView / 30) * 2.0f;
             }
         }
     }
 }
예제 #23
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();
                    }
                }
            }
        }
예제 #24
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
    }
예제 #25
0
    void Update()
    {
        //Getting a list of all anchors
        List <ARPlaneAnchorGameObject> arpags = m_unityARAnchorManager.GetCurrentPlaneAnchors();

        //For the sake of this tutorial we will simply position our map on the first anchor that we find
        if (arpags.Count >= 1)
        {
            ARPlaneAnchor arPlaneAnchor = arpags [0].planeAnchor;

            //Setting the position of our map to match the position of anchor
            m_wrldMapParent.position = UnityARMatrixOps.GetPosition(arPlaneAnchor.transform);

            //Updating our mask according to the ARKit anchor
            m_wrldMapMask.rotation      = UnityARMatrixOps.GetRotation(arPlaneAnchor.transform);
            m_wrldMapMask.localPosition = new Vector3(arPlaneAnchor.center.x, arPlaneAnchor.center.y, -arPlaneAnchor.center.z);
            m_wrldMapMask.localScale    = new Vector3(arPlaneAnchor.extent.x, m_wrldMapMask.localScale.y, arPlaneAnchor.extent.z);
        }
    }
예제 #26
0
    private void UpdatePositionAndRotation(ARFaceAnchor anchorData)
    {
        if (headPrefab != null)
        {
            // head position and rotation
            headGameObject.transform.position = UnityARMatrixOps.GetPosition(anchorData.transform);
            headGameObject.transform.rotation = UnityARMatrixOps.GetRotation(anchorData.transform);
        }

        if (eyePrefab != null)
        {
            // eyes position and rotation
            eyeLeft.transform.position = anchorData.leftEyePose.position;
            eyeLeft.transform.rotation = anchorData.leftEyePose.rotation;

            eyeRight.transform.position = anchorData.rightEyePose.position;
            eyeRight.transform.rotation = anchorData.rightEyePose.rotation;
        }
    }
    private IEnumerator ResetOrientation()
    {
        Matrix4x4 matrix = UnityARSessionNativeInterface.GetARSessionNativeInterface().GetCameraPose();

        var orientation = UnityARMatrixOps.GetRotation(matrix);

        while
        (
            orientation == Quaternion.identity ||
            (
                orientation.x == 0 &&
                orientation.y == 0 &&
                orientation.z == 0 &&
                orientation.w == -1
            )
        )
        {
            yield return(null);
        }

        yield return(new WaitForEndOfFrame());

        _orientation = _resetOffset * orientation;

        var orientationHelper = new GameObject();

        orientationHelper.name = "_OnAppFocusOrientationHelper";

        orientationHelper.transform.rotation = _lastOrientation;
        var oldForward = orientationHelper.transform.forward;

        orientationHelper.transform.rotation = _orientation;
        var newForward = orientationHelper.transform.forward;

        var angle = Quaternion.Angle(_lastOrientation, _orientation);

        //        Debug.Log(" [IOSTrackingProvider] : Angle is : " + angle);

        if (Mathf.Abs(angle) <= 30)
        {
            _resetOffset = Quaternion.FromToRotation(oldForward, newForward);
        }
    }
예제 #28
0
    private bool HitTestWithResultType(ARPoint point, ARHitTestResultType arHitTestResultTypes)
    {
        List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(point, arHitTestResultTypes);

        if (hitResults.Count > 0)
        {
            anchorSet = true;

            ChildrenSetActive(parentGameObject, true);

            parentGameObject.transform.position = UnityARMatrixOps.GetPosition(hitResults[0].worldTransform);
            parentGameObject.transform.rotation = UnityARMatrixOps.GetRotation(hitResults[0].worldTransform);
            parentGameObject.transform.LookAt(new Vector3(mainCamera.transform.position.x, parentGameObject.transform.position.y, mainCamera.transform.position.z));

            return(true);
        }

        return(false);
    }
예제 #29
0
        public static Vector3 GetRealPosition(ARPlaneAnchor planeAnchor)
        {
            GameObject anchor = new GameObject("Anchor");
            GameObject parent = new GameObject("AnchorParent");

            anchor.transform.SetParent(parent.transform);

            parent.transform.position      = UnityARMatrixOps.GetPosition(planeAnchor.transform);
            parent.transform.rotation      = UnityARMatrixOps.GetRotation(planeAnchor.transform);
            anchor.transform.localPosition = new Vector3(planeAnchor.center.x, planeAnchor.center.y, -planeAnchor.center.z);
            Vector3 result = anchor.transform.position;

            Destroy(anchor);
            Destroy(parent);
            return(result);
            // Vector3 fix = planeAnchor.center;
            // fix = new Vector3(fix.x, fix.y, -fix.z);
            // return UnityARMatrixOps.GetPosition(planeAnchor.transform) + fix;
        }
예제 #30
0
 /// <summary>
 /// checks hits in order of priority
 /// returns true on first valid hit and saves in out variables
 /// </summary>
 /// <param name="viewportPoint"></param>
 /// <param name="resultTypesPrioriy"></param>
 /// <param name="hitPos"></param>
 /// <param name="hitRotaion"></param>
 /// <returns></returns>
 public static bool getHitData(ARPoint viewportPoint, ARHitTestResultType[] resultTypesPrioriy, out Vector3 hitPos, out Quaternion hitRotaion)
 {
     foreach (var resultType in resultTypesPrioriy)
     {
         List <ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface().HitTest(viewportPoint, resultType);
         if (hitResults.Count > 0)
         {
             foreach (var hitResult in hitResults)
             {
                 hitPos     = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
                 hitRotaion = UnityARMatrixOps.GetRotation(hitResult.worldTransform);
                 return(true);
             }
         }
     }
     hitRotaion = Quaternion.identity;
     hitPos     = Vector3.zero;
     return(false);
 }