コード例 #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>
        /// Identify which S2Cell will be used for the root.
        /// Find the S2Cell's GPS Coordinates.
        /// </summary>
        /// <param name="latLng">
        /// the LatLng coordinates from the first scape measurement
        /// </param>
        private void FindS2CellCoordinates(LatLng latLng)
        {
            S2CellId = ScapeUtils.CellIdForWgs(latLng.Latitude, latLng.Longitude, ScapeUtils.S2CellLevel);

            S2CellCoordinates = ScapeUtils.LocalToWgs(new Vector3(0, 0, 0), S2CellId);

            ScapeLogging.LogDebug(message: "GeoAnchorManager::S2CellId = " + S2CellId.ToString("X"));
            ScapeLogging.LogDebug(message: "GeoAnchorManager::S2CellCoordinates = " + ScapeUtils.CoordinatesToString(S2CellCoordinates));
        }
コード例 #3
0
        /// <summary>
        /// The game object calculates it's position in the Unity scene by comparing its World coordinate to the center
        /// of the unique S2 cell defined in the scene's GeoAnchorManager object.
        /// </summary>
        private void CalculateLocalCoordinates()
        {
            if (!isInstantiated)
            {
                return;
            }

            ScapeLogging.LogDebug(message: "GeoAnchor::GetWorldCoordinates() WorldCoords = " + latLng.Latitude + ", " + latLng.Longitude);

            Vector3 scenePos = ScapeUtils.WgsToLocal(latLng.Latitude, latLng.Longitude, altitude, GeoAnchorManager.Instance.S2CellId);

            ScapeLogging.LogDebug(message: "GeoAnchor::GetWorldCoordinates() ScenePos = " + scenePos.ToString());

            this.gameObject.transform.localPosition = scenePos;
        }
コード例 #4
0
 /// <summary>
 /// Identify which S2Cell will be used for the root.
 /// </summary>
 /// <param name="latLng">
 /// the LatLng coordinates from the first scape measurement
 /// </param>
 private void FindS2CellId(LatLng latLng)
 {
     s2CellId = ScapeUtils.CellIdForWgs(latLng.Latitude, latLng.Longitude, ScapeUtils.S2CellLevel);
 }