예제 #1
0
    private void OnLocationUpdated(object sender, pLab_LocationUpdatedEventArgs e)
    {
        bool updatePositions = false;

        float accuracy = Mathf.Max(e.horizontalAccuracy, e.verticalAccuracy);

        float deltaAccuracy = accuracy - previousUpdateAccuracy;

        if (accuracy <= 8f || deltaAccuracy <= 5f)
        {
            updatePositions = true;
        }
        else
        {
            TimeSpan timeSinceLast = TimeSpan.FromMilliseconds(e.timestamp - previousUpdateTimestamp);
            updatePositions =
                (timeSinceLast.TotalSeconds > 10 && accuracy <= 8f) ||
                (timeSinceLast.TotalSeconds > 20 && accuracy <= 15f) ||
                (timeSinceLast.TotalSeconds > 30);
        }

        if (updatePositions)
        {
            previousUpdateAccuracy  = accuracy;
            previousUpdateTimestamp = e.timestamp;
            // CheckDistances();
            RecheckPOITrackings();
        }
    }
    private void OnLocationUpdated(object sender, pLab_LocationUpdatedEventArgs e)
    {
        if (locationText != null)
        {
            locationText.text  = string.Format("Loc: {0},{1}", e.location.Lat, e.location.Lon);
            locationText.color = Color.red;
            StartCoroutine(LocationTextToDefault());
        }

        if (locationAccuracyText != null)
        {
            locationAccuracyText.text = string.Format("Loc. acc H:{0} V:{0}", e.horizontalAccuracy, e.verticalAccuracy);
        }

        if (locationDistanceChangeText != null)
        {
            float locationChange = 0f;

            if (previousLocation != null)
            {
                locationChange = pLab_GeoTools.DistanceBetweenPoints(previousLocation, e.location);
            }
            else
            {
                previousLocation = new pLab_LatLon();
            }

            locationDistanceChangeText.text = string.Format("Loc. distance change: {0}m", locationChange);
            previousLocation.Lat            = e.location.Lat;
            previousLocation.Lon            = e.location.Lon;
        }
    }
예제 #3
0
 /// <summary>
 /// Event handler for OnLocationUpdatedEvent. Tries to calculate new GPS-AR -heading if functionality enabled
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnLocationUpdated(object sender, pLab_LocationUpdatedEventArgs e)
 {
     if (calculationMode == CalculationMode.GPSAndARMovement || calculationMode == CalculationMode.Both)
     {
         CalculateGPSARHeadings(e);
     }
 }
예제 #4
0
    /// <summary>
    /// Calculates GPS-AR Mode headings
    /// </summary>
    /// <param name="e"></param>
    private void CalculateGPSARHeadings(pLab_LocationUpdatedEventArgs e)
    {
        if (previousGPSCoordinates == null)
        {
            previousGPSCoordinates   = e.location;
            previousARCameraPosition = arCameraTransform.position;
            return;
        }

        bool  isHeadingUsable    = false;
        bool  isGPSHeadingUsable = false;
        float newARHeading       = 0;
        float newGPSHeading      = 0;

        Vector3 newPosition = arCameraTransform.position;

        Vector3 positionDeltaVector = newPosition - previousARCameraPosition;

        distance = positionDeltaVector.magnitude;

        if (distance > minDistanceBeforeUpdate)
        {
            newARHeading    = Vector3.SignedAngle(Vector3.forward, positionDeltaVector, Vector3.up);
            newARHeading    = pLab_MathConversions.DegAngleToPositive(newARHeading);
            isHeadingUsable = true;
        }

        pLab_LatLon newGpsCoordinates = e.location;
        float       deltaAccuracy     = e.horizontalAccuracy - previousGPSAccuracy;

        if (e.horizontalAccuracy < movementMinimumGPSAccuracy || deltaAccuracy <= 5f)
        {
            double distanceBetween = pLab_GeoTools.DistanceBetweenPointsPythagoras(previousGPSCoordinates, newGpsCoordinates);

            if (distanceBetween > minDistanceBeforeUpdate)
            {
                newGPSHeading = pLab_GeoTools.BearingFromPointAToBInDegrees(previousGPSCoordinates, newGpsCoordinates);
                //Convert to 0 - 360
                newGPSHeading      = pLab_MathConversions.DegAngle0To360(newGPSHeading);
                isGPSHeadingUsable = true;
            }
        }

        if (isHeadingUsable && isGPSHeadingUsable)
        {
            arHeading                = newARHeading;
            gpsHeading               = newGPSHeading;
            previousGPSCoordinates   = newGpsCoordinates;
            previousARCameraPosition = newPosition;
            previousGPSAccuracy      = e.horizontalAccuracy;

            float diff = CalculateGPSARHeadingDifference(arHeading, gpsHeading);

            if (lastGPSARHeadingDeltas.Count == 0)
            {
                initialGPSARDifference = diff;
                lastGPSARHeadingDeltas.Add(0);
            }
            else
            {
                if (lastGPSARHeadingDeltas.Count >= maxLastMovementHeadings)
                {
                    lastGPSARHeadingDeltas.RemoveAt(0);
                }

                float readingDelta = diff - initialGPSARDifference;

                if (readingDelta > 180)
                {
                    readingDelta -= 360;
                }
                else if (readingDelta < -180)
                {
                    readingDelta += 360;
                }

                lastGPSARHeadingDeltas.Add(readingDelta);
            }

            medianGPSARHeadingDifference  = pLab_MathTools.GetMedian(lastGPSARHeadingDeltas) + initialGPSARDifference;
            averageGPSARHeadingDifference = lastGPSARHeadingDeltas.Average() + initialGPSARDifference;

            hasGPSARHeading = true;

            RecalculateHeading();
            RotateGPSARHeadingObject();
            TriggerNorthHeadingUpdatedEvent(false);


            if (OnHeadingFromMovementUpdated != null)
            {
                pLab_HeadingFromMovementUpdatedEventArgs eventArgs = new pLab_HeadingFromMovementUpdatedEventArgs()
                {
                    arHeading                = arHeading,
                    gpsHeading               = gpsHeading,
                    headingDifference        = diff,
                    medianHeadingDifference  = medianGPSARHeadingDifference,
                    averageHeadingDifference = averageGPSARHeadingDifference
                };

                OnHeadingFromMovementUpdated(this, eventArgs);
            }
        }
    }