Beispiel #1
0
    public void UpdatePosition(Location deviceLocation)
    {
        if (!hasInitialized)
        {
            Initialize(deviceLocation);
            hasInitialized = true;
            return;
        }

        //ARLocation.Utils.Logger.LogFromMethod("WaterMesh", "UpdatePosition", $"({gameObject.name}): Received location update, location = {deviceLocation}", DebugMode);

        if (state.Paused)
        {
            //ARLocation.Utils.Logger.LogFromMethod("WaterMesh", "UpdatePosition", $"({gameObject.name}): Updates are paused; returning", DebugMode);
            return;
        }

        // If we have reached the max number of location updates, do nothing
        if (PlacementOptions.MaxNumberOfLocationUpdates > 0 &&
            state.LocationUpdatedCount >= PlacementOptions.MaxNumberOfLocationUpdates)
        {
            return;
        }

        bool isHeightRelative = false;

        foreach (GlobalLocalPosition obj in state.globalLocalPositions)
        {
            //Vector3 targetPosition = Location.GetGameObjectPositionForLocation(
            //        arLocationRoot, mainCameraTransform, deviceLocation, obj.location, isHeightRelative
            //    );
            // har ersatt koden ovan med koden under du eller han? Han när vi satt tillsammans men
            Vector3 targetPosition = arTransformationManager.GpsToArWorld(obj.location);


            // If GroundHeight is enabled, don't change the objects position
            if (UseGroundHeight)
            {
                targetPosition.y = transform.position.y;
            }

            // comment out once we just render the mesh
            //obj.gameObject.transform.position = targetPosition; // GO

            obj.localLocation = targetPosition;
        }
        PositionUpdated();
        state.LocationUpdatedCount++;
    }
Beispiel #2
0
    private void CalculateClosestPointAndGenerateMesh()
    {
        if (wallPlacement.IsGroundPlaneSet())
        {
            // get device location
            var deviceLocation = aRLocationProvider.LastLocation;
            lastScannedPosition = aRCamera.transform.position;

            // get the points around the user
            var locationsToCreateMeshWith = CSV_extended.PointsWithinRadius(entireCSVData, radius, deviceLocation.ToLocation());

            // get the closest point
            closestPoint   = CSV_extended.ClosestPointGPS(locationsToCreateMeshWith, deviceLocation.ToLocation());
            heightAtCamera = (float)closestPoint.Height;
            //lastScannedHeight = heightAtCamera;

            Debug.Log("Height at camera:" + heightAtCamera);

            // Convert GPS data to local data.
            var localPositionsToGenerate = new List <Vector3>();

            //float currentWaterHeight = 0;
            foreach (var gpsLocation in locationsToCreateMeshWith)
            {
                var unityPosition = aRTransformationManager.GpsToArWorld(gpsLocation);

                // Om detta behövs senare sätt in det i en egen funktion
                float calculatedHeight = 0;

                float height                = (float)gpsLocation.Height;
                float waterheight           = (float)gpsLocation.WaterHeight;
                bool  insidebuilding        = gpsLocation.Building;
                float nearestneighborheight = (float)gpsLocation.NearestNeighborHeight;
                float nearestneighborwater  = (float)gpsLocation.NearestNeighborWater;

                if (insidebuilding)
                {
                    if (nearestneighborheight != -9999)
                    {
                        calculatedHeight = CalculateRelativeHeight(heightAtCamera, nearestneighborheight, nearestneighborwater);
                        //currentWaterHeight = nearestneighborwater;
                    }
                }
                else
                {
                    calculatedHeight = CalculateRelativeHeight(heightAtCamera, height, waterheight);
                    //currentWaterHeight = waterheight;
                }

                Debug.Log("Calculated height: " + calculatedHeight);

                unityPosition.y = calculatedHeight;
                localPositionsToGenerate.Add(unityPosition);
            }

            meshGenerated = GenerateMesh(localPositionsToGenerate);

            if (meshGenerated)
            {
                //EnableWallPlacementAndUpdateCurrentWater(currentWaterHeight);
                //EnableWallPlacement();
                wallPlacement.WaterMeshGenerated(true);
                wallPlacement.SetWallPlacementEnabled(true);
                Debug.Log("Wallplacement enabled");
                // Send data to wallplacement class for measuring stick calculations
                wallPlacement.SetCurrentGlobalLocalPositions(locationsToCreateMeshWith, localPositionsToGenerate);
                timeSinceLastCalculation = 0;
            }
        }
    }