Exemplo n.º 1
0
    void Update()
    {
        foodAge += Time.deltaTime;

        if (trackedPlane == null)
        {
            return;
        }
        if (trackedPlane.TrackingState != TrackingState.Tracking)
        {
            return;
        }

        //Check for plane being subsumed
        //If plane has been subsumed switch attachment to the subsuming plane
        while (trackedPlane.SubsumedBy != null)
        {
            trackedPlane = trackedPlane.SubsumedBy;
        }

        //Check for food, spawns new one if needed
        if (foodInstance == null || foodInstance.activeSelf == false)
        {
            SpawnFoodInstance();
            return;
        }

        if (foodAge >= maxAge)
        {
            DestroyObject(foodInstance);
            foodInstance = null;
        }
    }
Exemplo n.º 2
0
 void SetSelectedPlane(TrackedPlane selectedPlane)
 {
     Debug.Log("Selected plane centered at " + selectedPlane.CenterPose.position);
     scoreboard.SetSelectedPlane(selectedPlane);
     snakeController.SetPlane(selectedPlane);
     GetComponent <FoodController>().SetSelectedPlane(selectedPlane);
 }
 /// <summary>
 /// Initializes the TrackedPlaneVisualizer with a TrackedPlane.
 /// </summary>
 /// <param name="plane">The plane to vizualize.</param>
 public void Initialize(TrackedPlane plane)
 {
     m_TrackedPlane = plane;
     m_MeshRenderer.material.SetColor("_GridColor", k_PlaneColors[s_PlaneCount++ % k_PlaneColors.Length]);
     m_MeshRenderer.material.SetFloat("_UvRotation", Random.Range(0.0f, 360.0f));
     Update();
 }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        // The tracking state must be FrameTrackingState.Tracking in order to access the Frame.
        if (Frame.TrackingState != FrameTrackingState.Tracking)
        {
            return;
        }

        // If there is no plane, then return
        if (trackedPlane == null)
        {
            return;
        }

        // Check for the plane being subsumed
        // If the plane has been subsumed switch attachment to the subsuming plane.
        while (trackedPlane.SubsumedBy != null)
        {
            trackedPlane = trackedPlane.SubsumedBy;
        }

        // Make the scoreboard face the viewer
        transform.LookAt(firstPersonCamera.transform);

        // Move the position to stay consistent with the plane
        if (trackedPlane.IsUpdated)
        {
            transform.position = new Vector3(transform.position.x,
                                             trackedPlane.Position.y + yOffset, transform.position.z);
        }
    }
Exemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        if (trackedPlane == null)
        {
            return;
        }

        if (!trackedPlane.IsValid)
        {
            return;
        }

        // Check for the plane being subsumed
        // If the plane has been subsumed switch attachment to the subsuming plane.
        while (trackedPlane.SubsumedBy != null)
        {
            trackedPlane = trackedPlane.SubsumedBy;
        }

        if (foodInstance == null || foodInstance.activeSelf == false)
        {
            SpawnFoodInstance();
            return;
        }

        // Increment the age and destroy if expired.
        foodAge += Time.deltaTime;
        if (foodAge >= maxAge)
        {
            DestroyObject(foodInstance);
            foodInstance = null;
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Frame.TrackingState != TrackingState.Tracking)
        {
            return;
        }

        if (trackedPlane == null)
        {
            return;
        }

        // Check for the plane being subsumed.
        // If the plane has been subsumed switch attachment to the subsuming plane.
        while (trackedPlane.SubsumedBy != null)
        {
            trackedPlane = trackedPlane.SubsumedBy;
        }

        if (trackedPlane == null)
        {
            return;
        }

        // Check for the plane being subsumed.
        // If the plane has been subsumed switch attachment to the subsuming plane.
        while (trackedPlane.SubsumedBy != null)
        {
            trackedPlane = trackedPlane.SubsumedBy;
        }
    }
Exemplo n.º 7
0
    /// <summary>
    /// Initializes the TrackedPlaneVisualizer with a TrackedPlane.
    /// </summary>
    /// <param name="plane">The plane to vizualize.</param>
    public void Initialize(TrackedPlane plane)
    {
        m_TrackedPlane = plane;
        m_MeshRenderer.material.SetFloat("_UvRotation", Random.Range(0.0f, 360.0f));

        Update();
    }
Exemplo n.º 8
0
        /// <summary>
        /// Unity update.
        /// </summary>
        public void Update()
        {
            if (m_AttachedPlane == null)
            {
                return;
            }
            // If the plane has been subsumed switch attachment to the subsuming plane.
            while (m_AttachedPlane.SubsumedBy != null)
            {
                m_AttachedPlane = m_AttachedPlane.SubsumedBy;
            }

            // Update visibility of the GameObject based on plane validity.
            if (!m_AttachedPlane.IsValid && m_isVisible)
            {
                for (int i = 0; i < m_meshRenderers.Length; i++)
                {
                    m_meshRenderers[i].enabled = false;
                }

                m_isVisible = false;
            }
            else if (m_AttachedPlane.IsValid && !m_isVisible)
            {
                for (int i = 0; i < m_meshRenderers.Length; i++)
                {
                    m_meshRenderers[i].enabled = true;
                }

                m_isVisible = true;
            }

            transform.position = new Vector3(transform.position.x, m_AttachedPlane.Position.y + m_planeYOffset,
                                             transform.position.z);
        }
Exemplo n.º 9
0
 public TrackedPlaneRecord(TrackedPlane plane, ApiPlaneData planeData,
                           Action <ApiPlaneData, TrackedPlane, bool> updatePlane)
 {
     m_plane       = plane;
     m_planeData   = planeData;
     m_updatePlane = updatePlane;
 }
Exemplo n.º 10
0
        /// <summary>
        /// Factory method for creating and reusing TrackedPlane references from native handles.
        /// </summary>
        /// <param name="nativeHandle">A native handle to a plane that has been acquired.  RELEASE WILL BE HANDLED BY
        /// THIS METHOD.</param>
        /// <returns>A reference to a tracked plane. </returns>
        public Trackable TrackableFactory(IntPtr nativeHandle)
        {
            if (nativeHandle == IntPtr.Zero)
            {
                return(null);
            }

            Trackable result;

            ApiTrackableType trackableType = TrackableApi.GetType(nativeHandle);

            if (trackableType == ApiTrackableType.Plane)
            {
                result = new TrackedPlane(nativeHandle, this);
            }
            else if (trackableType == ApiTrackableType.HandGesture)
            {
                result = new TrackedHandGesture(nativeHandle, this);
            }
            else if (trackableType == ApiTrackableType.Image)
            {
                result = new TrackedImage(nativeHandle, this);
            }
            else
            {
                UnityEngine.Debug.LogFormat("Cant find {0}", trackableType);
                throw new NotImplementedException("TrackableFactory:: No contructor for requested trackable type.");
            }

            return(result);
        }
Exemplo n.º 11
0
    void SpawnPieces()
    {
        // spawn pieces
        TrackedPlane trackedPlane = null;

        for (int i = 0; i < m_AllPlanes.Count; i++)
        {
            if (m_AllPlanes[i].TrackingState == TrackingState.Tracking)
            {
                trackedPlane = m_AllPlanes[i];
                break;
            }
        }

        GameSingleton.instance.Anchor(trackedPlane.CenterPose.position);

        for (int i = 0; i < piecesNum; i++)
        {
            float yRange = Random.Range(0, 3f);
            float xRange = Random.Range(-3f, 3f);
            float zRange = Random.Range(-3f, 3f);
            int   index  = i % piecesPrefab.Length;
            pieces = Instantiate(piecesPrefab[index], trackedPlane.CenterPose.position + new Vector3(xRange, yRange, zRange), Random.rotation);
            // store piece list
            GameSingleton.instance.spawnedPieces.Add(pieces);

            // locate wall
            wall.transform.position = trackedPlane.CenterPose.position + new Vector3(0f, height, 0f);
        }
        Debug.Log("spawn");
        // store piece num info
        GameSingleton.instance.PieceNum(piecesNum);
        // allow snapping interaction
        GameSingleton.instance.AllowSnap(true);
    }
Exemplo n.º 12
0
        /// <summary>
        /// Factory method for creating and reusing TrackedPlane references from native handles.
        /// </summary>
        /// <param name="nativeHandle">A native handle to a plane that has been acquired.  RELEASE WILL BE HANDLED BY
        /// THIS METHOD.</param>
        /// <returns>A reference to a tracked plane. </returns>
        public Trackable TrackableFactory(IntPtr nativeHandle)
        {
            if (nativeHandle == IntPtr.Zero)
            {
                return(null);
            }

            Trackable result;

            if (m_TrackableDict.TryGetValue(nativeHandle, out result))
            {
                // Release aquired handle and return cached result.
                m_NativeSession.TrackableApi.Release(nativeHandle);
                return(result);
            }

            ApiTrackableType trackableType = m_NativeSession.TrackableApi.GetType(nativeHandle);

            if (trackableType == ApiTrackableType.Plane)
            {
                result = new TrackedPlane(nativeHandle, m_NativeSession);
            }
            else if (trackableType == ApiTrackableType.Point)
            {
                result = new TrackedPoint(nativeHandle, m_NativeSession);
            }
            else
            {
                UnityEngine.Debug.LogFormat("Cant find {0}", trackableType);
                throw new NotImplementedException("TrackableFactory:: No constructor for requested trackable type.");
            }

            m_TrackableDict.Add(nativeHandle, result);
            return(result);
        }
    // Update is called once per frame
    void Update()
    {
        if (trackedPlane == null)
        {
            return;
        }

        if (trackedPlane.TrackingState != TrackingState.Tracking)
        {
            return;
        }
        while (trackedPlane.SubsumedBy != null)
        {
            trackedPlane = trackedPlane.SubsumedBy;
        }

        if (foodInstance == null || foodInstance.activeSelf == false)
        {
            SpawnFoodInstance();
            return;
        }

        foodAge += Time.deltaTime;
        if (foodAge >= maxAge)
        {
            DestroyObject(foodInstance);
            foodInstance = null;
        }
    }
Exemplo n.º 14
0
    // Update is called once per frame
    void Update()
    {
        if (trackedPlane == null)
        {
            return;
        }

        if (trackedPlane.TrackingState != TrackingState.Tracking)
        {
            return;
        }

        // Check for the plane being subsumed
        // If the plane has been subsumed switch attachment to the subsuming plane.
        while (trackedPlane.SubsumedBy != null)
        {
            trackedPlane = trackedPlane.SubsumedBy;
        }

        foodAge += Time.deltaTime;
        if (foodAge >= maxAge)
        {
            DestroyObject(foodInstance);
            foodInstance = null;
        }
    }
Exemplo n.º 15
0
    // Update is called once per frame
    void Update()
    {
        if (Session.Status != SessionStatus.Tracking)
        {
            return;
        }
        // If there is no plane, then return
        if (trackedPlane == null)
        {
            return;
        }

        // Check for the plane being subsumed.
        // If the plane has been subsumed switch attachment to the subsuming plane.
        while (trackedPlane.SubsumedBy != null)
        {
            trackedPlane = trackedPlane.SubsumedBy;
        }
        // Make the scoreboard face the viewer.
        transform.LookAt(firstPersonCamera.transform);

        // Move the position to stay consistent with the plane.

        transform.position = new Vector3(transform.position.x,
                                         trackedPlane.CenterPose.position.y + yOffset, transform.position.z);
    }
Exemplo n.º 16
0
 public void SetTrackedPlane(TrackedPlane plane)
 {
     trackedPlane = plane;
     trackedPlane.GetBoundaryPolygon(polygonVertices);
     planeRenderer.Initialize();
     planeRenderer.UpdateMeshWithCurrentTrackedPlane(trackedPlane.CenterPose.position, polygonVertices);
 }
Exemplo n.º 17
0
        /// <summary>
        /// Factory method for creating and reusing Trackable references from native handles.
        /// </summary>
        /// <param name="nativeHandle">A native handle to a plane that has been acquired.  RELEASE
        /// WILL BE HANDLED BY THIS METHOD.</param>
        /// <returns>A reference to the Trackable. May return <c>null</c> on error or if Trackable
        /// is not handled.</returns>
        public Trackable TrackableFactory(IntPtr nativeHandle)
        {
            if (nativeHandle == IntPtr.Zero)
            {
                return(null);
            }

            Trackable result;

            if (_trackableDict.TryGetValue(nativeHandle, out result))
            {
                // Release aquired handle and return cached result.
                _nativeSession.TrackableApi.Release(nativeHandle);
                return(result);
            }

            // This block needs to construct classes marked Obsolete since those versions are always
            // the most derived type.
#pragma warning disable 618 // Obsolete warning
            ApiTrackableType trackableType = _nativeSession.TrackableApi.GetType(nativeHandle);
            if (trackableType == ApiTrackableType.Plane)
            {
                result = new TrackedPlane(nativeHandle, _nativeSession);
            }
            else if (trackableType == ApiTrackableType.Point)
            {
                result = new TrackedPoint(nativeHandle, _nativeSession);
            }
            else if (trackableType == ApiTrackableType.InstantPlacementPoint)
            {
                result = new InstantPlacementPoint(nativeHandle, _nativeSession);
            }
            else if (trackableType == ApiTrackableType.AugmentedImage)
            {
                result = new AugmentedImage(nativeHandle, _nativeSession);
            }
            else if (trackableType == ApiTrackableType.AugmentedFace)
            {
                result = new AugmentedFace(nativeHandle, _nativeSession);
            }
            else if (ExperimentManager.Instance.IsManagingTrackableType((int)trackableType))
            {
                result =
                    ExperimentManager.Instance.TrackableFactory((int)trackableType, nativeHandle);
            }
            else
            {
                Debug.LogWarning(
                    "TrackableFactory::No constructor for requested trackable type.");
            }
#pragma warning restore 618

            if (result != null)
            {
                _trackableDict.Add(nativeHandle, result);
            }

            return(result);
        }
        private bool PlaneUpdated(TrackedPlane tp, BoundedPlane bp)
        {
            var extents  = (!FloatCompare(tp.ExtentX, bp.extents.x) || !FloatCompare(tp.ExtentZ, bp.extents.y));
            var rotation = tp.Rotation != bp.rotation;
            var position = tp.Position != bp.center;

            return(extents || rotation || position);
        }
Exemplo n.º 19
0
        private bool PlaneUpdated(TrackedPlane tp, BoundedPlane bp)
        {
            var extents  = (tp.ExtentX != bp.extents.x || tp.ExtentZ != bp.extents.y);
            var rotation = tp.Rotation != bp.rotation;
            var position = tp.Position != bp.center;

            return(extents || rotation || position);
        }
Exemplo n.º 20
0
 public void InitializePlane(TrackedPlane plane)
 {
     mesh           = GetComponent <MeshFilter>().mesh;
     referencePlane = plane;
     vertices       = new List <Vector3>();
     indices        = new List <int>();
     Update();
 }
    private void SetSelectedPlane(TrackedPlane selectedPlane)
    {
        Debug.Log("Selected plane centered at " + selectedPlane.Position);

        scoreboard.SetSelectedPlane(selectedPlane);
        // Add to SetSelectedPlane()
        snakeController.SetPlane(selectedPlane);
        GetComponent <FoodController>().SetSelectedPlane(selectedPlane);
    }
Exemplo n.º 22
0
 public override void Update()
 {
     while (m_AttachedPlane.SubsumedBy != null)
     {
         m_AttachedPlane = m_AttachedPlane.SubsumedBy;
     }
     base.Update();
     controller.transform.position = new Vector3(controller.transform.position.x, m_AttachedPlane.Position.y + m_planeYOffset, controller.transform.position.z);
 }
        private bool PlaneUpdated(TrackedPlane tp, BoundedPlane bp)
        {
            var tpExtents = new Vector2(tp.ExtentX, tp.ExtentZ);
            var extents   = Vector2.Distance(tpExtents, bp.extents) > 0.005f;
            var rotation  = tp.Rotation != bp.rotation;
            var position  = Vector2.Distance(tp.Position, bp.center) > 0.005f;

            return(extents || rotation || position);
        }
Exemplo n.º 24
0
    void SetSelectedPlane(TrackedPlane selectedPlane)
    {
        Debug.Log("Selected plane centered at " + selectedPlane.CenterPose.position);
        // Add to the end of SetSelectedPlane.
        scoreboard.SetSelectedPlane(selectedPlane);
        // Add to SetSelectedPlane()
        snakeController.SetPlane(selectedPlane);

        // Add to the bottom of SetSelectedPlane()
        GetComponent <FoodController>().SetSelectedPlane(selectedPlane);
    }
Exemplo n.º 25
0
        /// <summary>
        /// Check if a point is within a TrackedPlane bounding box.
        /// </summary>
        /// <param name="point">3D point in world space.</param>
        /// <param name="plane">A TrackedPlane reference detected by ARCore.</param>
        private bool _IsPointInBoundingBox(Vector3 point, TrackedPlane plane)
        {
            Matrix4x4 world_T_plane = Matrix4x4.TRS(plane.Position, plane.Rotation, Vector3.one);
            Vector3   pointInPlane  = world_T_plane.inverse.MultiplyPoint3x4(point);

            if (-0.5f * plane.Bounds.x <= pointInPlane.x && pointInPlane.x <= 0.5f * plane.Bounds.x &&
                -0.5f * plane.Bounds.y <= pointInPlane.z && pointInPlane.z <= 0.5f * plane.Bounds.y)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 26
0
    void FindCenterAnchor()
    {
        TrackedPlane trackedPlane = null;

        for (int i = 0; i < m_AllPlanes.Count; i++)
        {
            if (m_AllPlanes[i].TrackingState == TrackingState.Tracking)
            {
                trackedPlane = m_AllPlanes[i];
                break;
            }
        }
        GameSingleton.instance.Anchor(trackedPlane.CenterPose.position);
    }
Exemplo n.º 27
0
 void SetSelectedPlane(TrackedPlane selectedPlane)
 {
     Debug.Log("selected plane centered at " + selectedPlane.CenterPose.position);
     //scoreboard.SetSelectedPlane(selectedPlane);
     //snakeController.SetPlane (selectedPlane);
     //GetComponent<FoodController> ().SetSelectedPlane (selectedPlane);
     //Instantiate(boundingbox,selectedPlane.CenterPose.position,transform.rotation * Quaternion.Euler(0.0f,180.0f,0.0f));
     if (!isBoundingBoxPlaced)
     {
         boundingbox.SetActive(true);
         boundingbox.transform.position = selectedPlane.CenterPose.position;
         boundingbox.transform.rotation = selectedPlane.CenterPose.rotation;
         isBoundingBoxPlaced            = true;
     }
 }
Exemplo n.º 28
0
        /// <summary>
        /// Check if a point is within a TrackedPlane polygon's boundary. This function assume the polygon
        /// to be convex.
        /// </summary>
        /// <param name="point">3D point in world space.</param>
        /// <param name="plane">A TrackedPlane reference detected by ARCore.</param>
        private bool _IsPointInPolygon(Vector3 point, TrackedPlane plane)
        {
            List <Vector3> polygonPoints = m_tmpPolygonPoints;

            plane.GetBoundaryPolygon(ref m_tmpPolygonPoints);

            int count = polygonPoints.Count;

            if (count < 3)
            {
                return(false);
            }

            Vector3 lastUp = Vector3.zero;

            for (int i = 0; i < count; ++i)
            {
                Vector3 v0 = point - polygonPoints[i];
                Vector3 v1;
                if (i == count - 1)
                {
                    v1 = polygonPoints[0] - polygonPoints[i];
                }
                else
                {
                    v1 = polygonPoints[i + 1] - polygonPoints[i];
                }

                Vector3 up = Vector3.Cross(v0, v1);
                if (i != 0)
                {
                    float sign = Vector3.Dot(up, lastUp);
                    if (sign < 0)
                    {
                        return(false);
                    }
                }

                lastUp = up;
            }
            return(true);
        }
        public void Update()
        {
            // Please import Google ARCore plugin if you are seeing a compiler error here.
            if (Session.Status != SessionStatus.Tracking)
            {
                const int LOST_TRACKING_SLEEP_TIMEOUT = 15;
                Screen.sleepTimeout = LOST_TRACKING_SLEEP_TIMEOUT;
                return;
            }

            Screen.sleepTimeout = SleepTimeout.NeverSleep;

            // Please import Google ARCore plugin if you are seeing a compiler error here.
            Session.GetTrackables(m_allPlanes);

            // Please import Google ARCore plugin if you are seeing a compiler error here.
            TrackedPlane firstValidPlane = null;

            for (int i = 0; i < m_allPlanes.Count; i++)
            {
                // Please import Google ARCore plugin if you are seeing a compiler error here.
                if (m_allPlanes[i].TrackingState == TrackingState.Tracking)
                {
                    firstValidPlane = m_allPlanes [i];
                    break;
                }
            }

            if (firstValidPlane == null)
            {
                if (m_trackedPlane != null)
                {
                    m_trackedPlane = null;
                    m_wrldMapARCorePositioner.CurrentTrackedPlane = null;
                }
            }
            else if (m_trackedPlane == null)
            {
                m_trackedPlane = firstValidPlane;
                m_wrldMapARCorePositioner.CurrentTrackedPlane = m_trackedPlane;
            }
        }
Exemplo n.º 30
0
        public void Update()
        {
            if (m_AttachedPlane == null)
            {
                return;
            }

            // Please import Google ARCore plugin if you are seeing a compiler error here.
            while (m_AttachedPlane.SubsumedBy != null)
            {
                // Please import Google ARCore plugin if you are seeing a compiler error here.
                m_AttachedPlane = m_AttachedPlane.SubsumedBy;
            }

            // Please import Google ARCore plugin if you are seeing a compiler error here.
            if (m_AttachedPlane.TrackingState != TrackingState.Tracking)
            {
                wrldMapMask.localScale = Vector3.zero;
            }

            // Please import Google ARCore plugin if you are seeing a compiler error here.
            Vector3 difference = transform.position - m_AttachedPlane.CenterPose.position;

            wrldMapMask.transform.localPosition = new Vector3(difference.x, wrldMapMask.localPosition.y, difference.z);

            // Please import Google ARCore plugin if you are seeing a compiler error here.
            wrldMapMask.transform.localScale = new Vector3(m_AttachedPlane.ExtentX, 1f, m_AttachedPlane.ExtentZ);

            // Please import Google ARCore plugin if you are seeing a compiler error here.
            wrldMapMask.transform.rotation = m_AttachedPlane.CenterPose.rotation;

            if (!m_isActive)
            {
                wrldMapMask.transform.localScale = Vector3.zero;
            }

            if ((Input.touches.Length > 0 && Input.touches[0].phase == TouchPhase.Began))
            {
                m_isActive = !m_isActive;
            }
        }