Example #1
0
        public static bool Raycast(
            Vector3 origin, Vector3 direction, out TrackableHit hitResult,
            float maxDistance        = Mathf.Infinity,
            TrackableHitFlags filter = TrackableHitFlags.Default)
        {
            hitResult = new TrackableHit();
            var nativeSession = LifecycleManager.Instance.NativeSession;

            if (nativeSession == null)
            {
                return(false);
            }

            bool foundHit =
                nativeSession.HitTestApi.Raycast(
                    nativeSession.FrameHandle, origin, direction, maxDistance, filter,
                    _tmpTrackableHitList);

            if (foundHit && _tmpTrackableHitList.Count != 0)
            {
                hitResult = _tmpTrackableHitList[0];
            }

            return(foundHit);
        }
Example #2
0
        /// <summary>
        /// Performs a raycast against physical objects being tracked by ARCore.
        /// Output the closest hit from the camera.
        /// Note that the Unity's screen coordinate (0, 0)
        /// starts from bottom left.
        /// </summary>
        /// <param name="x">Horizontal touch position in Unity's screen coordiante.</param>
        /// <param name="y">Vertical touch position in Unity's screen coordiante.</param>
        /// <param name="filter">A filter bitmask where each {@link TrackableHitFlag} which is set represents a category
        /// of raycast hits the method call should consider valid.</param>
        /// <param name="hitResult">A {@link TrackableHit} that will be set if the raycast is successful.</param>
        /// <returns><c>true</c> if the raycast had a hit, otherwise <c>false</c>.</returns>
        public static bool Raycast(float x, float y, TrackableHitFlags filter,
                                   out TrackableHit hitResult)
        {
            if (SessionManager == null)
            {
                hitResult = new TrackableHit();
                return(false);
            }

            return(SessionManager.FrameManager.Raycast(x, y, filter, out hitResult));
        }
Example #3
0
        public static bool Raycast(float x, float y, TrackableHitFlags filter,
                                   out TrackableHit hitResult)
        {
            hitResult = new TrackableHit();
            var nativeSession = LifecycleManager.Instance.NativeSession;

            if (nativeSession == null)
            {
                return(false);
            }
            // Note that the Unity's screen coordinate (0, 0) starts from bottom left.
            bool foundHit = nativeSession.HitTestApi.Raycast(nativeSession.FrameHandle, x, Screen.height - y, filter,
                                                             s_TmpTrackableHitList);

            if (foundHit && s_TmpTrackableHitList.Count != 0)
            {
                hitResult = s_TmpTrackableHitList[0];
            }
            return(foundHit);
        }
Example #4
0
 /// <summary>
 /// Performs a raycast against physical objects being tracked by ARCore.
 /// </summary>
 /// <param name="ray">The starting point and direction of the ray.</param>
 /// <param name="filter">A filter bitmask where each <c>TrackableHitFlag</c> which is set represents a category
 /// of raycast hits the method call should consider valid.</param>
 /// <param name="hitResult">A <c>TrackableHit</c> that will be set if the raycast is successful.</param>
 /// <returns><c>true</c> if the raycast had a hit, otherwise <c>false</c>.</returns>
 public static bool Raycast(Ray ray, TrackableHitFlag filter, out TrackableHit hitResult)
 {
     return(SessionManager.Instance.RaycastManager.Raycast(ray, filter, out hitResult));
 }