예제 #1
0
        /// <summary>
        /// called by ScapeSessionComponent.
        /// Here the scape measurement is used to update the world transform object
        /// in order to position and orient the camera with respect to the scene's origin.
        /// </summary>
        /// <param name="coordinates">
        /// GPS Coordinates given by scape measurements
        /// </param>
        /// <param name="heading">
        /// The compass heading given by scape measurements
        /// </param>
        /// <param name="altitude">
        /// The the altitude from the ground the camera is at. This is currently supplied by
        /// ARKit/Core using the GroundTracker
        /// </param>
        public void SynchronizeARCamera(LatLng coordinates, float heading, float altitude)
        {
            if (groundTracker)
            {
                bool  success = false;
                float height  = groundTracker.GetGroundHeight(out success);
                if (success)
                {
                    altitude = -height;
                }
                else
                {
                    ScapeLogging.LogError(message: "groundTracker.getHeight not found before ScapeMeasurement, falling back to Scape's RawMeasurementEstimate");
                }
            }

            ScapeLogging.LogDebug(message: "SynchronizeARCamera() LatLngCoordinates = " + ScapeUtils.CoordinatesToString(coordinates));

            ScapeLogging.LogDebug(message: "SynchronizeARCamera() ARHeading = " + rotationAtScapeMeasurements.y);
            ScapeLogging.LogDebug(message: "SynchronizeARCamera() ARPosition = " + positionAtScapeMeasurements.ToString());

            if (s2CellId == 0)
            {
                FindS2CellId(coordinates);
            }

            // the Unity position the camera should be in, that is it's position relative to the S2 cell based on it's
            // gps coordinates
            cameraS2Position = ScapeUtils.WgsToLocal(
                coordinates.Latitude,
                coordinates.Longitude,
                altitude,
                s2CellId);

            // the world transform direction corrects the camera's Heading to be relative to North.
            worldTransformDirection = heading - rotationAtScapeMeasurements.y;

            if (worldTransformDirection < 0.0)
            {
                worldTransformDirection += 360.0f;
            }

            ScapeLogging.LogDebug(message: "SynchronizeARCamera() worldTransformDirectionYAngle = " + worldTransformDirection);

            Vector3 positionAtScapeMeasurementsRotated = Quaternion.AngleAxis(worldTransformDirection, Vector3.up) * positionAtScapeMeasurements;

            // the world transform position corrects the camera's final position after applying the direction correction
            worldTransformPosition = cameraS2Position - positionAtScapeMeasurementsRotated;
            ScapeLogging.LogDebug(message: "SynchronizeARCamera() worldTransformPosition = " + worldTransformPosition.ToString());

            if (updateWorldTransform)
            {
                previousYDirection = lerpDirection;
                previousPosition   = lerpPosition;
            }

            updateWorldTransform = true;

            updateStartTime = Time.time;
        }
예제 #2
0
        /// <summary>
        /// Initializes the GeoAnchorManager, should only happen once
        /// Sets the S2Cell if the user has given GPS coordinates, other wise that is done later
        /// when the ScapeMeasurement comes in.
        /// </summary>
        private void StaticInit()
        {
            ScapeLogging.LogDebug(message: "GeoAnchorManager::StaticInit()");

            if (geoAnchorManager != null)
            {
                ScapeLogging.LogError(message: "Error: more than one GeoAnchorManager detected in scene!");
            }
            else
            {
                geoAnchorManager = this;
            }
        }
        static void onAquireLocationMeasurements(ref ScapeNative.location_measurements lm)
        {
            if (haveLocation)
            {
                lm.longitude = lastInfo.longitude;
                lm.latitude  = lastInfo.latitude;
            }
            else
            {
                ScapeLogging.LogError("ScapeClientNative::onAquireLocationMeasurements called but Unity has not retrieved location measurements from device yet. Have Location Permissions been allowed?");

                lm.longitude = 0.0;
                lm.latitude  = 0.0;
            }
        }
        /// <summary>
        /// The public function to request a ScapeMeasurement.
        /// </summary>
        public void GetMeasurements()
        {
            if (this.scapeMeasurementInProgress)
            {
                ScapeLogging.LogError("GetMeasuremnts ignored, scapeMeasurements already in progress");
                return;
            }

            if (this.scapeSessionNative != null)
            {
                this.scapeMeasurementInProgress = true;
                this.scapeSessionNative.GetMeasurements();
            }
            else
            {
                ScapeLogging.LogError("GetMeasurements called before scapeSessionNative initialized");
            }
        }
예제 #5
0
        /// <summary>
        /// used at runtime to retrieve the api key for the ScapeClient
        /// </summary>
        /// <returns>
        /// returns the apikey if found
        /// </returns>
        public static string RetrieveKeyFromResources()
        {
            try
            {
            #if UNITY_EDITOR
                using (StreamReader streamReader = new StreamReader(resPath + apikeyFileName + ".txt"))
                {
                    string apiKey = streamReader.ReadLine();

                    return(apiKey);
                }
            #else
                string apiKey = Resources.Load <TextAsset>(apikeyFileName).ToString();

                return(apiKey);
            #endif
            }
            catch (Exception ex)
            {
                ScapeLogging.LogError("Exception retrieving apikey: " + ex.ToString());
                return(string.Empty);
            }
        }
예제 #6
0
        /// <summary>
        /// save the api key to the specific file in resources folder
        /// </summary>
        /// <param name="apiKey">
        /// the apikey as string
        /// </param>
        public static void SaveApiKeyToResource(string apiKey)
        {
            try
            {
                if (apiKey.Length == 0)
                {
                    return;
                }

                if (!Directory.Exists(resPath))
                {
                    Directory.CreateDirectory(resPath);
                }

                using (StreamWriter writer = new StreamWriter(resPath + apikeyFileName + ".txt", false))
                {
                    writer.WriteLine(apiKey.Trim());
                }
            }
            catch (Exception e)
            {
                ScapeLogging.LogError(message: "Failed to save apikey to '" + resPath + "'");
            }
        }