Esempio n. 1
0
        public override void OnFrameUpdate(ARSession session, ARFrame frame)
        {
            base.OnFrameUpdate(session, frame);

            if (PlaneTrackingEnabled)
            {
                return;
            }

            var hits = frame.HitTest(new CoreGraphics.CGPoint(0.5, 0.5), ARHitTestResultType.ExistingPlaneUsingExtent);

            if (!hits?.Any() ?? true)
            {
                Crosshair.BackgroundColor = UIColor.Gray;
            }
            else
            {
                Crosshair.BackgroundColor = UIColor.Green;

                if (PlaySoundOnNodeDetection())
                {
                    SoundManager.PlaySound("text");
                }
            }
        }
Esempio n. 2
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;
                }
            }
        }
Esempio n. 3
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;
                }
            }
        }
        private void _DrawARLogo(Touch touch)
        {
            List <ARHitResult> hitResults = ARFrame.HitTest(touch);
            ARHitResult        hitResult  = null;
            ARTrackable        trackable  = null;
            Boolean            hasHitFlag = false;

            ARDebug.LogInfo("_DrawARLogo hitResults count {0}", hitResults.Count);
            foreach (ARHitResult singleHit in hitResults)
            {
                trackable = singleHit.GetTrackable();
                ARDebug.LogInfo("_DrawARLogo GetTrackable {0}", singleHit.GetTrackable());
                if ((trackable is ARPlane && ((ARPlane)trackable).IsPoseInPolygon(singleHit.HitPose)) ||
                    (trackable is ARPoint))
                {
                    hitResult  = singleHit;
                    hasHitFlag = true;
                    if (trackable is ARPlane)
                    {
                        break;
                    }
                }
            }

            if (hasHitFlag != true)
            {
                ARDebug.LogInfo("_DrawARLogo can't hit!");
                return;
            }

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

            GameObject prefab;

            trackable = hitResult.GetTrackable();
            if (trackable is ARPlane)
            {
                prefab = arDiscoveryLogoPlanePrefabs;
            }
            else
            {
                prefab = arDiscoveryLogoPointPrefabs;
            }

/*
 *          ARAnchor anchor = hitResult.CreateAnchor();
 *          var logoObject = Instantiate(prefab, anchor.GetPose().position, anchor.GetPose().rotation);
 *          logoObject.GetComponent<ARDiscoveryLogoVisualizer>().Initialize(anchor);
 *          addedAnchors.Add(anchor);
 */
        }
Esempio n. 5
0
        public Vector3?HitTest(ARFrame frame, float screenX = 0.5f, float screenY = 0.5f)
        {
            var result = frame?.HitTest(new CoreGraphics.CGPoint(screenX, screenY),
                                        ARHitTestResultType.ExistingPlaneUsingExtent)?.FirstOrDefault();

            if (result != null && result.Distance > 0.2f)
            {
                var row = result.WorldTransform.Column3;
                return(new Vector3(row.X, row.Y, -row.Z));
            }
            return(null);
        }
        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;
                }
            }
        }
Esempio n. 7
0
        private ARHitResult HitTest4Result(ARFrame frame, ARCamera camera, MotionEvent mEvent)
        {
            ARHitResult         hitResult      = null;
            IList <ARHitResult> hitTestResults = frame.HitTest(mEvent);

            for (int i = 0; i < hitTestResults.Count; i++)
            {
                // Determine whether the hit point is within the plane polygon.
                ARHitResult hitResultTemp = hitTestResults.ElementAt(i);
                if (hitResultTemp == null)
                {
                    continue;
                }
                IARTrackable trackable = hitResultTemp.Trackable;

                Java.Lang.Object PointOrPlane    = null;
                bool             isPlanHitJudge  = false;
                bool             isPointHitJudge = false;

                try
                {
                    PointOrPlane   = trackable.JavaCast <ARPlane>();
                    isPlanHitJudge =
                        PointOrPlane.GetType() == typeof(ARPlane) && ((ARPlane)PointOrPlane).IsPoseInPolygon(hitResultTemp.HitPose) &&
                        (CalculateDistanceToPlane(hitResultTemp.HitPose, camera.Pose) > 0);
                }
                catch (Exception e)
                {
                    PointOrPlane    = trackable.JavaCast <ARPoint>();
                    isPointHitJudge = PointOrPlane.GetType() == typeof(ARPoint) &&
                                      ((ARPoint)PointOrPlane).GetOrientationMode() == ARPoint.OrientationMode.EstimatedSurfaceNormal;
                };

                // Determine whether the point cloud is clicked and whether the point faces the camera.


                // Select points on the plane preferentially.
                if (isPlanHitJudge)
                {
                    hitResult = hitResultTemp;
                }
            }
            return(hitResult);
        }
        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;
                }
            }
        }
Esempio n. 9
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();
        }