public void Update()
        {
            if (null == m_anchor)
            {
                gameObject.SetActive(false);
                return;
            }
            switch (m_anchor.GetTrackingState())
            {
            case ARTrackable.TrackingState.TRACKING:
                Pose p = m_anchor.GetPose();
                gameObject.transform.position = p.position;
                gameObject.transform.rotation = p.rotation;
                gameObject.transform.Rotate(0f, 225f, 0f, Space.Self);
                gameObject.SetActive(true);
                break;

            case ARTrackable.TrackingState.PAUSED:
                gameObject.SetActive(false);
                break;

            case ARTrackable.TrackingState.STOPPED:
            default:
                gameObject.SetActive(false);
                Destroy(gameObject);
                break;
            }
        }
        public void Update()
        {
            if (null == m_anchor)
            {
                m_MeshRenderer.enabled = false;
                return;
            }
            switch (m_anchor.GetTrackingState())
            {
            case ARTrackable.TrackingState.TRACKING:
                Pose p = m_anchor.GetPose();
                gameObject.transform.position = p.position;
                gameObject.transform.rotation = p.rotation;
                gameObject.transform.Rotate(0f, 225f, 0f, Space.Self);
                m_MeshRenderer.enabled = true;
                break;

            case ARTrackable.TrackingState.PAUSED:
                m_MeshRenderer.enabled = false;
                break;

            case ARTrackable.TrackingState.STOPPED:
            default:
                m_MeshRenderer.enabled = false;
                Destroy(gameObject);
                break;
            }
        }
예제 #3
0
        private void _CreateWorld(Touch touch)
        {
            List <ARHitResult> hitResults = ARFrame.HitTest(touch);

            ARDebug.LogInfo("_DrawARLogo hitResults count {0}", hitResults.Count);
            foreach (ARHitResult singleHit in hitResults)
            {
                ARTrackable trackable = singleHit.GetTrackable();
                ARDebug.LogInfo("_DrawARLogo GetTrackable {0}", singleHit.GetTrackable());
                if (trackable is ARPlane && ((ARPlane)trackable).IsPoseInPolygon(singleHit.HitPose) ||
                    trackable is ARPoint)
                {
                    ARAnchor anchor = singleHit.CreateAnchor();

                    Vector3 anchorPosition = anchor.GetPose().position;

                    if (world)
                    {
                        world.transform.position = anchorPosition;
                    }
                    else
                    {
                        world = Instantiate(worldPrefab, anchorPosition, Quaternion.identity);
                    }
                    break;
                }
            }
        }
예제 #4
0
        private void trackTest(Touch touch)
        {
            List <ARHitResult> hitResults = ARFrame.HitTest(touch);

            foreach (ARHitResult singleHit in hitResults)
            {
                ARTrackable trackable = singleHit.GetTrackable();
                if ((trackable is ARPlane && ((ARPlane)trackable).IsPoseInPolygon(singleHit.HitPose)) ||
                    (trackable is ARPoint))
                {
                    ARAnchor anchor = singleHit.CreateAnchor();
                    ARDebug.LogInfo("GridARScript:trackTest anchor world position {0}", anchor.GetPose().position);
                    Vector3 screenPos = Camera.main.WorldToScreenPoint(anchor.GetPose().position);
                    ARDebug.LogInfo("GridARScript:trackTest anchor screen position {0}", screenPos);


                    if (m_touchIndex % 2 == 0)
                    {
                        m_touchBeginModel.GetComponent <disToolLogoVisualizer>().setAnchor(anchor);

                        var script = m_grid.GetComponent <GridARScpript>();
                        if (script)
                        {
                            script.setBeginAnchor(anchor);
                        }
                    }
                    else
                    {
                        m_touchEndModel.GetComponent <disToolLogoVisualizer>().setAnchor(anchor);
                    }
                    ++m_touchIndex;
                    break;
                }
            }
        }
예제 #5
0
        private void trackTest()
        {
            if (null == m_beginAnchor)
            {
                m_MeshRenderer.enabled = false;
                return;
            }


            switch (m_beginAnchor.GetTrackingState())
            {
            case ARTrackable.TrackingState.TRACKING:
                m_MeshRenderer.enabled = true;
                break;

            case ARTrackable.TrackingState.PAUSED:
                m_MeshRenderer.enabled = false;
                return;

            case ARTrackable.TrackingState.STOPPED:
            default:
                m_MeshRenderer.enabled = false;
                m_beginAnchor          = null;
                return;
            }

            List <ARHitResult> hitResults = ARFrame.HitTest(m_touchScreenPos.x, m_touchScreenPos.y);

            ARDebug.LogInfo("GridARScript:trackTest hitResults count {0}", hitResults.Count);
            foreach (ARHitResult singleHit in hitResults)
            {
                ARTrackable trackable = singleHit.GetTrackable();
                ARDebug.LogInfo("GridARScript:trackTest GetTrackable {0}", singleHit.GetTrackable());
                if ((trackable is ARPlane && ((ARPlane)trackable).IsPoseInPolygon(singleHit.HitPose)) ||
                    (trackable is ARPoint))
                {
                    ARAnchor anchor = singleHit.CreateAnchor();
                    //ARDebug.LogInfo("GridARScript:trackTest anchor world position {0}", anchor.GetPose().position);

                    renderMesh(m_beginAnchor.GetPose().position, anchor.GetPose().position);
                    break;
                }
            }
        }
        private void _DrawARLogo(Touch touch)
        {
            List <ARHitResult> hitResults = ARFrame.HitTest(touch);

            foreach (ARHitResult singleHit in hitResults)
            {
                ARTrackable trackable = singleHit.GetTrackable();
                if (trackable is ARPlane && ((ARPlane)trackable).IsPoseInPolygon(singleHit.HitPose))
                {
                    if (addedAnchors.Count > 16)
                    {
                        ARAnchor toRemove = addedAnchors[0];
                        toRemove.Detach();
                        addedAnchors.RemoveAt(0);
                    }
                    ARAnchor anchor     = singleHit.CreateAnchor();
                    var      logoObject = Instantiate(arDiscoveryLogoPrefabs, anchor.GetPose().position, anchor.GetPose().rotation);
                    logoObject.GetComponent <ARDiscoveryLogoVisualizer>().Initialize(anchor);
                    addedAnchors.Add(anchor);
                    break;
                }
            }
        }
예제 #7
0
        private void _DrawARLogo(Touch touch)
        {
            List <ARHitResult> hitResults = ARFrame.HitTest(touch);

            ARDebug.LogInfo("_DrawARLogo hitResults count {0}", hitResults.Count);
            foreach (ARHitResult singleHit in hitResults)
            {
                ARTrackable trackable = singleHit.GetTrackable();
                ARDebug.LogInfo("_DrawARLogo GetTrackable {0}", singleHit.GetTrackable());
                if ((trackable is ARPlane && ((ARPlane)trackable).IsPoseInPolygon(singleHit.HitPose)) ||
                    (trackable is ARPoint))
                {
                    GameObject prefab;
                    if (trackable is ARPlane)
                    {
                        prefab = arDiscoveryLogoPlanePrefabs;
                    }
                    else
                    {
                        prefab = arDiscoveryLogoPointPrefabs;
                    }

                    if (addedAnchors.Count > 16)
                    {
                        ARAnchor toRemove = addedAnchors[0];
                        toRemove.Detach();
                        addedAnchors.RemoveAt(0);
                    }

                    ARAnchor anchor     = singleHit.CreateAnchor();
                    var      logoObject = Instantiate(prefab, anchor.GetPose().position, anchor.GetPose().rotation);
                    logoObject.GetComponent <ARDiscoveryLogoVisualizer>().Initialize(anchor);
                    addedAnchors.Add(anchor);
                    break;
                }
            }
        }
        public void Update()
        {
            if (startgame == 1)
            {
                timer += Time.deltaTime;

                if (timer % 3.0f < 0.1)
                {
                    hit    = 1;
                    endhit = 0;

                    if (((int)timer / 3) % 2 > 0.5f)
                    {
                        temp1 = Lshoulder;
                        temp2 = Larm;
                        arm   = "Left";
                    }
                    else
                    {
                        temp1 = Rshoulder;
                        temp2 = Rarm;
                        arm   = "Right";
                    }
                }

                if (hit == 1)
                {
                    if (temp1.transform.localRotation.eulerAngles.z > 77)
                    {
                        directionL  = -1.0f;
                        directionL1 = 1.8f;
                        endhit      = 1;
                    }

                    if (temp1.transform.localRotation.eulerAngles.z < 10)
                    {
                        directionL  = 1.0f;
                        directionL1 = -1.8f;
                        if (endhit == 1)
                        {
                            hit = 0;
                        }
                    }

                    temp1.transform.Rotate(new Vector3(0, 0, Time.deltaTime * V * directionL), Space.Self);
                    temp2.transform.Rotate(new Vector3(0, 0, Time.deltaTime * V * directionL1), Space.Self);
                }
            }

            if (Input.touchCount > 0 && startgame == 0)
            {
                newPoints = ARFrame.HitTest(Screen.width / 2, Screen.height / 2);
                anchor    = newPoints[0].CreateAnchor();
                enemyPose = anchor.GetPose();
                m_hwCube.transform.position = new Vector3(enemyPose.position.x, enemyPose.position.y, enemyPose.position.z);
                startgame = 1;
            }


            if (m_trackedPlane == null)
            {
                return;
            }
            else if (m_trackedPlane.GetSubsumedBy() != null ||
                     m_trackedPlane.GetTrackingState() == ARTrackable.TrackingState.STOPPED)
            {
                Destroy(gameObject);
                return;
            }
            else if (m_trackedPlane.GetTrackingState() == ARTrackable.TrackingState.PAUSED) // whether to destory gameobject if not tracking
            {
                m_meshRenderer.enabled = false;
                return;
            }

            m_meshRenderer.enabled = true;
            _UpdateMeshIfNeeded();
        }
예제 #9
0
 public void setBeginAnchor(ARAnchor ch)
 {
     m_beginAnchor    = ch;
     m_touchScreenPos = Camera.main.WorldToScreenPoint(ch.GetPose().position);
     ARDebug.LogInfo("GridARScript:m_touchScreenPos {0}", m_touchScreenPos);
 }