private IEnumerator FetchNearItems()
    {
        isRunningItemSerch = true;
        nearItems          = new Dictionary <string, ItemInfo>();
        while (true)
        {
            var items = AndroidMethods.GetNearItems(DeviceInstance.LastLatitude(), DeviceInstance.LastLongitude());

            foreach (ItemInfo item in items)
            {
                lock (nearItemsLock)
                {
                    try
                    {
                        if (!nearItems.ContainsKey(item.Id))
                        {
                            nearItems.Add(item.Id, item);
                        }
                    }
                    catch (Exception e)
                    {
                        UIScript.AddLog(e.Message);
                    }
                }
            }

            yield return(new WaitForSeconds(5));
        }
    }
    public void PlaceItem(ItemInfo itemInfo, Vector3 position)
    {
        UIScript.AddLog($"{itemInfo.Id} PlaceItem");
        this.ItemInfo = itemInfo;

        if (!string.IsNullOrWhiteSpace(itemInfo.Wavefront))
        {
            mesh = MeshBuilder.Instance.BuildMesh(itemInfo.Wavefront);
        }
    }
Example #3
0
    void Update()
    {
        lastNorth = compassService.magneticHeading;

        if (nextTime < Time.time)
        {
            if (locationService.status == LocationServiceStatus.Running)
            {
                lastLocationInformation = locationService.lastData;
            }

            nextTime = Time.time + 1f;
        }

        if (mainCamera.transform.rotation.eulerAngles.x > 180)
        {
            lastNorth += 180;

            if (lastNorth > 360)
            {
                lastNorth -= 360;
            }
        }

        #region Calibragem
        if (!northCalibrated)
        {
            transform.rotation = Quaternion.AngleAxis(lastNorth, Vector3.up);
            mainCamera.transform.localRotation = Quaternion.Euler(mainCamera.transform.localRotation.eulerAngles.x, 0f, mainCamera.transform.localRotation.eulerAngles.z);

            UIScript.AddLog($"New camera local rotation: {mainCamera.transform.localRotation.eulerAngles}");
            northCalibrated = lastNorth > 0;
        }

        northRotationText.text = $"Last north: {lastNorth}º \nLast coords: ({lastLocationInformation.latitude}, {lastLocationInformation.longitude})\nCamera rotation: {mainCamera.transform.rotation.eulerAngles}";
        #endregion
    }
    void Update()
    {
        if (Session.Status != SessionStatus.Tracking)
        {
            return;
        }

        if (!isRunningItemSerch)
        {
            StartCoroutine(FetchNearItems());
        }

        float latitude  = DeviceInstance.LastLatitude();
        float longitude = DeviceInstance.LastLongitude();

        List <ItemInfo> items;

        lock (nearItemsLock)
        {
            items = nearItems.Select(item => item.Value).Where(item => !item.Placed).ToList();
        }

        foreach (var itemInfo in items)
        {
            float relativeAngle = Functions.AngleBetween(latitude, longitude, itemInfo.Latitude, itemInfo.Longitude);
            float distance      = Functions.HaversineDistance(latitude, longitude, itemInfo.Latitude, itemInfo.Longitude);
            var   position      = Quaternion.AngleAxis(relativeAngle, Vector3.up) * Vector3.forward * distance;

            UIScript.AddLog($"{itemInfo.Id} - {distance}m");
            UIScript.AddLog($"{itemInfo.Id} - {relativeAngle}º");
            UIScript.AddLog($"{itemInfo.Id} - Coords: ({itemInfo.Latitude}, {itemInfo.Longitude})");

            //Pose pose = new Pose(position, Quaternion.identity);
            //Anchor anchor = Session.CreateAnchor(pose);

            var newItem = Instantiate(DefaultItemModel);
            newItem.transform.position = position;
            newItem.transform.rotation = Quaternion.identity;
            //newItem.transform.parent = anchor.transform;
            listaObjetos.Add(newItem);

            var itemScript = newItem.AddComponent <ItemScript>();

            itemScript.PlaceItem(itemInfo, position);
            itemInfo.Placed = true;
        }

        if (listarObjetos)
        {
            listarObjetos = false;
            UIScript.AddLog($"Quantidade de itens: {listaObjetos.Count}");

            foreach (GameObject o in listaObjetos)
            {
                var script = o.GetComponent <ItemScript>();


                if (o != null)
                {
                    UIScript.AddLog($"{script.ItemInfo.Id} - {o.transform.position} - Lat: {script.ItemInfo.Latitude} Long: {script.ItemInfo.Longitude}");
                }
                else
                {
                    UIScript.AddLog("nulo");
                }
            }
        }
    }