Example #1
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);
        }
Example #2
0
        private void DoWhenEventTypeSingleTap(ARHitResult hitResult)
        {
            // The hit results are sorted by distance. Only the nearest hit point is valid.
            // Set the number of stored objects to 10 to avoid the overload of rendering and AR Engine.
            if (mVirtualObjects.Count >= 16)
            {
                mVirtualObjects.ElementAt(0).GetAnchor().Detach();
                mVirtualObjects.RemoveAt(0);
            }

            IARTrackable currentTrackable = hitResult.Trackable;

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

            try
            {
                PointOrPlane   = currentTrackable.JavaCast <ARPlane>();
                isPlanHitJudge = PointOrPlane.GetType() == typeof(ARPlane);
            }
            catch (Exception e)
            {
                PointOrPlane    = currentTrackable.JavaCast <ARPoint>();
                isPointHitJudge = PointOrPlane.GetType() == typeof(ARPoint);
            };
            if (isPointHitJudge)
            {
                mVirtualObjects.Add(new VirtualObject(hitResult.CreateAnchor(), BLUE_COLORS));
            }
            else if (isPlanHitJudge)
            {
                mVirtualObjects.Add(new VirtualObject(hitResult.CreateAnchor(), GREEN_COLORS));
            }
            else
            {
                Log.Info(TAG, "Hit result is not plane or point.");
            }
        }