protected override void DefaultValues()
        {
            base.DefaultValues();

            this.currentAnimationState = AnimationStates.Idle;
            this.HitType = ARMobileHitType.ExistingPlane;
        }
Exemple #2
0
        /// <inheritdoc />
        public override bool HitTest(Vector2 screenPosition, ARMobileHitType hitType, out ARMobileHitTestResult[] results)
        {
            if (this.currentFrame?.Camera == null ||
                this.currentFrame.Camera.TrackingState != Google.AR.Core.TrackingState.Tracking)
            {
                results = null;
                return(false);
            }

            var resultAnchors = new List <ARMobileHitTestResult>();

            foreach (var hit in this.currentFrame.HitTest(screenPosition.X, screenPosition.Y))
            {
                ARMobileHitType?currentHitType = null;
                var             trackable      = hit.Trackable;

                if ((hitType & ARMobileHitType.FeaturePoint) != 0 &&
                    trackable is ARCore.Point)
                {
                    currentHitType = ARMobileHitType.FeaturePoint;
                }
                else if (trackable is ARCore.Plane)
                {
                    if ((hitType & ARMobileHitType.ExistingPlaneUsingExtent) != 0 &&
                        ((ARCore.Plane)trackable).IsPoseInExtents(hit.HitPose))
                    {
                        currentHitType = ARMobileHitType.ExistingPlaneUsingExtent;
                    }
                    else if ((hitType & ARMobileHitType.ExistingPlaneUsingGeometry) != 0 &&
                             ((ARCore.Plane)trackable).IsPoseInPolygon(hit.HitPose))
                    {
                        currentHitType = ARMobileHitType.ExistingPlaneUsingGeometry;
                    }
                    else if ((hitType & ARMobileHitType.ExistingPlane) != 0 ||
                             (hitType & ARMobileHitType.EstimatedHorizontalPlane) != 0)
                    {
                        currentHitType = ARMobileHitType.ExistingPlane;
                    }
                }

                if (currentHitType.HasValue)
                {
                    var trackableId = trackable.GetGuid();
                    var hitResult   = new ARMobileHitTestResult()
                    {
                        Distance = hit.Distance,
                        HitType  = currentHitType.Value,
                        Anchor   = this.FindAnchor(trackableId)
                    };
                    hit.HitPose.ToWave(out hitResult.WorldTransform);

                    resultAnchors.Add(hitResult);
                }
            }

            results = resultAnchors.ToArray();
            return(resultAnchors.Count > 0);
        }
        /// <summary>
        /// Performs a ray cast from the user's device in the direction of the given location in the camera view.
        /// Intersections with detected scene geometry are returned, sorted by distance from the device; the nearest intersection is returned first.
        /// </summary>
        /// <param name="screenPosition">The position coordinates of the screen.</param>
        /// <param name="hitType">The types of hit-test result to search for.</param>
        /// <param name="results">The list of results, sorted from nearest to farthest (in distance from the camera).</param>
        /// <returns><c>true</c> if any hit-test has been found; otherwise, <c>false</c>.</returns>
        public bool HitTest(Vector2 screenPosition, ARMobileHitType hitType, out ARMobileHitTestResult[] results)
        {
            if (this.service == null)
            {
                results = null;
                return(false);
            }

            return(this.service.HitTest(screenPosition, hitType, out results));
        }
        /// <inheritdoc />
        public override bool HitTest(Vector2 screenPosition, ARMobileHitType hitType, out ARMobileHitTestResult[] results)
        {
            var point = new CGPoint(screenPosition.X / this.platform.ScreenWidth, screenPosition.Y / this.platform.ScreenHeight);
            var arHitTestResultType = hitType.ToARKit();

            var arKitResults = this.arkitSession.CurrentFrame?.HitTest(point, arHitTestResultType);

            if (arKitResults != null)
            {
                results = new ARMobileHitTestResult[arKitResults.Length];

                for (int i = 0; i < arKitResults.Length; i++)
                {
                    var arkitResult = arKitResults[i];

                    var hitResult = new ARMobileHitTestResult()
                    {
                        Distance = (float)arkitResult.Distance,
                        HitType  = arkitResult.Type.ToWave(),
                    };

                    arkitResult.WorldTransform.ToWave(out hitResult.WorldTransform);

                    var anchor = arkitResult.Anchor;
                    if (anchor != null)
                    {
                        var anchorId = anchor.Identifier.ToWave();
                        hitResult.Anchor = this.FindAnchor(anchorId);
                    }

                    results[i] = hitResult;
                }

                return(arKitResults.Length > 0);
            }

            results = null;

            return(false);
        }
Exemple #5
0
 /// <summary>
 /// Converts an <see cref="ARMobileHitType"/> into a <see cref="ARHitTestResultType"/>.
 /// </summary>
 /// <param name="hitType">The hit type value to be converted</param>
 /// <returns>Returns an <see cref="ARHitTestResultType"/></returns>
 internal static ARHitTestResultType ToARKit(this ARMobileHitType hitType)
 {
     return((ARHitTestResultType)hitType);
 }
 protected override void DefaultValues()
 {
     base.DefaultValues();
     this.HitType = ARMobileHitType.ExistingPlane;
 }
Exemple #7
0
 /// <summary>
 /// Performs a ray cast from the user's device in the direction of the given location in the camera view.
 /// Intersections with detected scene geometry are returned, sorted by distance from the device; the nearest intersection is returned first.
 /// </summary>
 /// <param name="screenPosition">The position coordinates of the screen.</param>
 /// <param name="hitType">The types of hit-test result to search for.</param>
 /// <param name="results">The list of results, sorted from nearest to farthest (in distance from the camera).</param>
 /// <returns><c>true</c> if any hit-test has been found; otherwise, <c>false</c>.</returns>
 public abstract bool HitTest(Vector2 screenPosition, ARMobileHitType hitType, out ARMobileHitTestResult[] results);