Ejemplo n.º 1
0
    // SpawnPrefabAtGeoLocation(GameObject, Vector2d, Action<List<GameObject>>, Boolean, String)
    //  A Vector2d(Latitude Longitude) object
    // https://www.mapbox.com/mapbox-unity-sdk/api/unity/Mapbox.Unity.Map.AbstractMap.html
    private void AddPointToMap(BTCleanPOI bnew)
    {
        GameObject prefab = GetPrefab(bnew.POIType);

        Mapbox.Utils.Vector2d vec = new Mapbox.Utils.Vector2d(bnew.Latitude, bnew.Longitude);
        string sname = string.Format("{0} - {1}", bnew.ID, bnew.POIType);

        map.SpawnPrefabAtGeoLocation(prefab, vec, null, true, sname);

        //if (GameManager.Instance.Setting.CreateWithoutPredefined)
        //{
        //    string sname = string.Format("{0} - {1}", bnew.ID, bnew.POIType);
        //    map.SpawnPrefabAtGeoLocation(prefab, vec, null, true, sname);
        //}
        //else
        //{
        //    if (AddPrefabPOI(vec, bnew) == true)
        //    {
        //        LogManager.Instance.AddLog(string.Format("Success Added in map POI (prefabed) using coordinates - {0}", bnew.ID));
        //    }
        //    else
        //    {
        //        string sname = string.Format("{0} - {1}", bnew.ID, bnew.POIType);
        //        map.SpawnPrefabAtGeoLocation(prefab, vec, null, true, sname);
        //    }
        //}
    }
    public IEnumerator addBillboard(string text, int color, int style)
    {
        GameObject billboard     = Instantiate(GameObject.FindGameObjectWithTag("billboardObject"));
        TextMesh   billboardText = billboard.GetComponentInChildren <TextMesh> ();

        setFontAndColor(billboardText, color, style);
        billboardText.text = text;

        //Place the billboard aligned to the map in front of the player
        Vector3 correctPos         = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)).GetPoint(10);
        Vector3 billboardRayOrigin = new Vector3(correctPos.x, rayCastObject.gameObject.transform.position.y, correctPos.z);

        float height = directionsHandler.castRaycastDownAtPosition(billboardRayOrigin);

        if (height != billboardRayOrigin.y)
        {
            directionsHandler.setTotalOffset();
            height -= directionsHandler.totalOffset;
        }
        billboards.Add(billboard);
        Vector3            initPosition    = new Vector3(correctPos.x, height + 20, correctPos.z);
        Vector3            droppedPosition = new Vector3(correctPos.x, height, correctPos.z);
        TransitionalObject billboardDrop   = (TransitionalObject)billboard.GetComponent(typeof(TransitionalObject));

        while (billboard.transform.localPosition != droppedPosition)
        {
            ratio += Time.deltaTime * multiplier;
            billboard.transform.localPosition = Vector3.Lerp(initPosition, droppedPosition, ratio);
            yield return(null);
        }
        Mapbox.Utils.Vector2d billboardVec2d = directionsHandler.Vec2dFromUnityVector(billboard.transform.position);
        sendAnnotation("billboard", text, billboardVec2d.x, billboardVec2d.y, height, color, style);
    }
Ejemplo n.º 3
0
 public void UpdateMap(float currentZoom, Mapbox.Utils.Vector2d latitudeLongitude)
 {
     currentZoom = Mathf.Clamp(currentZoom, Phase1.instance.getMinZoom(), Phase1.instance.getMaxZoom());
     mapVariable.SetZoom(currentZoom);
     mapVariable.SetCenterLatitudeLongitude(latitudeLongitude);
     mapVariable.UpdateMap();
 }
Ejemplo n.º 4
0
    // Update the target position on the map
    private void UpdateTargetPosition()
    {
        var map = LocationProviderFactory.Instance.mapManager;

        Mapbox.Utils.Vector2d coord = new Mapbox.Utils.Vector2d(latitude, longitude);
        transform.localPosition = map.GeoToWorldPosition(coord);
    }
Ejemplo n.º 5
0
    public void Kokot()
    {
        Mapbox.Utils.Vector2d p = new Mapbox.Utils.Vector2d(49.227689, 16.597898);
        Vector3 j = Map.GeoToWorldPosition(new Mapbox.Utils.Vector2d(49.227689, 16.597898), false);

        Debug.Log(j);
    }
Ejemplo n.º 6
0
    private IEnumerator verifyIfMapIsLoaded()
    {
        if (this.map != null)
        {
            Mapbox.Utils.Vector2d centerMarcator = this.map.CenterMercator;
            float worldRelativeScale             = this.map.WorldRelativeScale;

            if (centerMarcator.x != 0 && centerMarcator.y != 0 && worldRelativeScale != 0)
            {
                Vector3 vector = Mapbox.Unity.Utilities.VectorExtensions.AsUnityPosition(
                    new Vector2(
                        this.latitude,
                        this.longitude
                        ),

                    centerMarcator,

                    worldRelativeScale
                    );

                this.transform.position = new Vector3(vector.x, 0, vector.z);
            }

            yield return(new WaitForSeconds(0.5f));

            StartCoroutine(this.verifyIfMapIsLoaded());
        }
    }
 public void PlayerMoved(Mapbox.Utils.Vector2d newPosition)
 {
     lock (_lockObj)
     {
         _playerLocations.Add(newPosition);
     }
 }
Ejemplo n.º 8
0
    public void saveMesh()
    {
        List <MessegeInfo> messageInfos = new List <MessegeInfo>();

        for (int i = 0; i < NumberOfClouds; i++)
        {
            messageInfos.Add(new MessegeInfo(lastMessage[i].x, lastMessage[i].y, lastMessage[i].z,
                                             lastMessage[i].rgb[0], lastMessage[i].rgb[1], lastMessage[i].rgb[2]));
        }

        MeshData message = new MeshData(messageInfos);

        Mapbox.Utils.Vector2d renderPosition = Map.WorldToGeoPosition(transform.position);
        message.latitude  = renderPosition.x;
        message.longitude = renderPosition.y;
        Debug.Log(message.latitude);
        Debug.Log(message.longitude);
        message.rotX = transform.rotation.eulerAngles.x;
        message.rotY = transform.rotation.eulerAngles.y;
        message.rotZ = transform.rotation.eulerAngles.z;
        if (saveName.text.Length != 0)
        {
            Debug.Log(saveName.text);
            string path = Application.streamingAssetsPath + "/Saves/" + saveName.text + ".json";
            File.WriteAllText(path, JsonUtility.ToJson(message));
            Debug.Log("saved");
        }
        else
        {
            Debug.Log("Zadaj heslo");
        }
    }
Ejemplo n.º 9
0
 public void updateMap()
 {
     latLong = map.CenterLatitudeLongitude;
     zoom    = map.Zoom;
     //Debug.Log(distance((float)latLong.x, (float)latLong.y, latMax, lngMin));
     //Debug.Log(Mathf.Atan(40000000.0f/ distance((float)latLong.x, (float)latLong.y, latMax, lngMin)));
     //Debug.Log(Mapbox.Utils.Vector2d.Distance(new Vector2d(latMax, lngMax), latLong) / map.WorldRelativeScale);
     //satRadius = Mathf.Atan(40000000000.0f / distance((float)latLong.x, (float)latLong.y, latMax, lngMin));
 }
Ejemplo n.º 10
0
    private Vector2 getCurrentPlayerPositionInRealWorld()
    {
        Mapbox.Utils.Vector2d playerPositionInRealWorld = this.map.WorldToGeoPosition(this.transform.position);

        return(new Vector2(
                   (float)System.Math.Round(playerPositionInRealWorld.x, POSITION_DECIMAL_FOR_COMPARISON),
                   (float)System.Math.Round(playerPositionInRealWorld.y, POSITION_DECIMAL_FOR_COMPARISON)
                   ));
    }
Ejemplo n.º 11
0
 // Start is called before the first frame update
 void Start()
 {
     mapOptions             = map.GetComponent <AbstractMap>();
     map.transform.position = new Vector3(0, 0, 0);
     miami   = new Mapbox.Utils.Vector2d(25.761681f, -80.191788f);
     newYork = new Mapbox.Utils.Vector2d(40.785091f, -73.968285f);
     chicago = new Mapbox.Utils.Vector2d(41.881832f, -87.623177f);
     paris   = new Mapbox.Utils.Vector2d(48.864716f, 2.349014f);
 }
Ejemplo n.º 12
0
    public void ResetMap()
    {
        SpawnOnMapController.RefreshDungeons(DungeonHandler.GetDungeonsList());

        Mapbox.Utils.Vector2d centerLatLon = _map.CenterLatitudeLongitude;

        _map.ResetMap();
        _map.Initialize(centerLatLon, 14);
    }
    public void initiliazeMap(Vector2 latLong, int zoomFactor)
    {
        //convert Vector2 to proper format
        Mapbox.Utils.Vector2d MBLatLong = new Mapbox.Utils.Vector2d((double)latLong.x, (double)latLong.y);
        Debug.Log(MBLatLong);

        //initialize map at location
        basicMap = (Mapbox.Unity.Map.AbstractMap)GetComponent(typeof(Mapbox.Unity.Map.AbstractMap));
        basicMap.Initialize(MBLatLong, zoomFactor);
    }
Ejemplo n.º 14
0
    public void searchForLocation(Mapbox.Utils.Vector2d location, bool displayTrail)
    {
        Debug.Log("Searching for Map at: " + location);
        searchCamera.transform.position = cameraPosition;
        map.UpdateMap(location, 16);

        if (displayTrail == true)
        {
            directions.getDirectionsFromLatLngs(waypointList);
        }
    }
Ejemplo n.º 15
0
    // Update distance on each call
    public IEnumerator UpdateDistance(Location deviceLocation)
    {
        yield return(null);

        // PLACES
        Mapbox.Utils.Vector2d placePosition;
        if (utdData != null || utdData.places.Count > 0)
        {
            int count = utdData.places.Count; // must be same as place data
            for (int i = 0; i < count; i++)
            {
                //Debug.Log(i);
                if (gameObject.transform.childCount > 0 && gameObject.transform.GetChild(0).transform.childCount > 0)
                {
                    GameObject tag   = gameObject.transform.GetChild(0).transform.GetChild(i).gameObject;
                    Place      place = utdData.places[i];
                    placePosition = new Mapbox.Utils.Vector2d(place.latitude, place.longitude);
                    // Update distance from current location
                    Mapbox.Utils.Vector2d diffInCoords   = deviceLocation.LatitudeLongitude - placePosition;
                    Mapbox.Utils.Vector2d actualDistance = Conversions.LatLonToMeters(diffInCoords);
                    int mag = (int)actualDistance.magnitude;
                    // Update cube's sides with info
                    tag.transform.GetChild(0).GetChild(4).GetComponent <TextMeshPro>().text = mag.ToString() + "m";

                    tag.transform.rotation = Camera.main.transform.rotation;
                }
            }
        }

        // EVENTS
        Mapbox.Utils.Vector2d evntPosition;
        if (utdData != null || utdData.events.Count > 0)
        {
            int count = utdData.events.Count; // must be same as evnt data
            for (int i = 0; i < count; i++)
            {
                //Debug.Log(i);
                if (gameObject.transform.childCount > 0 && gameObject.transform.GetChild(1).transform.childCount > 0)
                {
                    GameObject tag  = gameObject.transform.GetChild(1).transform.GetChild(i).gameObject;
                    Event      evnt = utdData.events[i];
                    evntPosition = new Mapbox.Utils.Vector2d(evnt.latitude, evnt.longitude);
                    // Update distance from current location
                    Mapbox.Utils.Vector2d diffInCoords   = deviceLocation.LatitudeLongitude - evntPosition;
                    Mapbox.Utils.Vector2d actualDistance = Conversions.LatLonToMeters(diffInCoords);
                    int mag = (int)actualDistance.magnitude;
                    // Update cube's sides with info
                    tag.transform.GetChild(0).GetChild(4).GetComponent <TextMeshPro>().text = mag.ToString() + "m";

                    tag.transform.rotation = Camera.main.transform.rotation;
                }
            }
        }
    }
Ejemplo n.º 16
0
    void LateUpdate()
    {
        if (_isInitialized)
        {
            var map = LocationProviderFactory.Instance.mapManager;
            Mapbox.Utils.Vector2d location = LocationProvider.CurrentLocation.LatitudeLongitude;
            position = new Coordinate(location.x, location.y);
            transform.localPosition = map.GeoToWorldPosition(LocationProvider.CurrentLocation.LatitudeLongitude);

            serverController.position = position;
        }
    }
Ejemplo n.º 17
0
    void convertor()
    {
        api_img_mid = Icao;
        _locations  = new Mapbox.Utils.Vector2d(Lat, Long);
        gameObject.transform.localPosition = _map.GeoToWorldPosition(_locations, true);
        float a = transform.position.y + (Alt * 12);

        transform.position = new Vector3(transform.position.x, a, transform.position.z);
        transform.rotation = Quaternion.Euler(0, Trak + 180, 0);// comp_end(Trak)
        if (Lat == 0 && Long == 0)
        {
            transform.position = new Vector3(transform.position.x, -100, transform.position.z);
        }
    }
Ejemplo n.º 18
0
    public void OnSelectDistrict()
    {
        string district = districts[dropdownUI.value];

        Mapbox.Utils.Vector2d longlat = districtLongLat[dropdownUI.value];
        //double lat = longlat.x;
        //double lng = longlat.y;
        //longlat = new Mapbox.Utils.Vector2d(lng, lat);

        Debug.Log("District " + district);
        Debug.Log("District longlat " + longlat);

        selectDistrictHandler(district, longlat);
    }
Ejemplo n.º 19
0
    //Simply returns the superficial trailhead data
    public IEnumerator getTrailData(WWWHandler www, string trailName)
    {
        CoroutineWithData trailData = new CoroutineWithData(this, www.GetTrail(trailName));

        yield return(trailData.coroutine);

        JSONNode parsedTrail = JSON.Parse(trailData.result.ToString());
        //TODO: get a trailhead lat/lon
        double lat = parsedTrail["geometry"]["coordinates"][0][1].AsDouble;
        double lon = parsedTrail["geometry"]["coordinates"][0][0].AsDouble;

        Mapbox.Utils.Vector2d searchLoc = new Mapbox.Utils.Vector2d(lat, lon);
        searchForLocation(searchLoc, false);
    }
Ejemplo n.º 20
0
 private void Start()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(gameObject);
     }
     mapVariable = map.GetComponent <AbstractMap>();
     originalLatitudeLongitude = mapVariable.CenterLatitudeLongitude;
     // originalCameraHeight = focalPoint.transform.position.y;
     StartCoroutine(Transition());
 }
Ejemplo n.º 21
0
    void LateUpdate()
    {
        var map = LocationProviderFactory.Instance.mapManager;

        Mapbox.Utils.Vector2d coord = new Mapbox.Utils.Vector2d(latitude, longitude);
        transform.localPosition = map.GeoToWorldPosition(coord);

        float distance = Mathf.Sqrt(Mathf.Pow(player.transform.position.z - transform.localPosition.z, 2) + Mathf.Pow(player.transform.position.x - transform.localPosition.x, 2));

        //la distance est nulle pdt l initialisation et l on ne veut pas que ca change de target
        if (distance < distTrigger && distance != 0)
        {
            NextTarget();
        }
    }
Ejemplo n.º 22
0
    public void AddDrone(DroneFlightData flightData)
    {
        Mapbox.Utils.Vector2d mapboxPosition = new Mapbox.Utils.Vector2d(flightData.Latitude, flightData.Longitude);
        Vector3 position3d = MapController.Instance.Map.GeoToWorldPosition(mapboxPosition, false);

        //float groundAltitude = MapController.Instance.Map.QueryElevationInUnityUnitsAt(MapController.Instance.Map.WorldToGeoPosition(position3d));
        position3d.y = (float)flightData.Altitude;

        GameObject Clone = Instantiate(newDrone, position3d, ourDrone.rotation);

        Clone.name = "DroneObject" + droneNumber.ToString();
        Drones.drones.Add(new Drone(Clone, flightData));
        Drones.DroneAdded(dronesPanelGrid, dronesPrefab, iconTransform, icon, PopUp, PopUpRenderTexture);
        droneNumber++;
        Clone.transform.SetParent(transform);
    }
Ejemplo n.º 23
0
    /// <summary>
    /// This is a hack on mapbox points of interest
    /// Scans all entries in PointsOfInterestSublayerList for the map.VectorData
    /// If Finds a List with the Prefab Type, like eg. Pole
    /// Then gets the array of POI (string) array and ads a new entry to the end
    /// </summary>
    /// <param name="vec"></param>
    /// <param name="Name"></param>
    /// <returns></returns>
    private bool AddPrefabPOI(Mapbox.Utils.Vector2d vec, BTCleanPOI bnew)
    {
        if (map.VectorData == null)
        {
            return(false);
        }
        string Name = null;

        if (string.Compare(bnew.POIType, "Pole", true) == 0)
        {
            Name = "Pole";
        }
        else if (string.Compare(bnew.POIType, "Cabinet", true) == 0)
        {
            Name = "Street Cabinet";
        }
        else if (string.Compare(bnew.POIType, "BillBoard", true) == 0)
        {
            Name = "Billboard";
        }
        else if (string.Compare(bnew.POIType, "Sign", true) == 0)
        {
            Name = "Sign";
        }
        else if (string.Compare(bnew.POIType, "Node", true) == 0)
        {
            Name = "Nodes";
        }
        else
        {
            Name = "Pole";
        }
        foreach (var ll in map.VectorData.PointsOfInterestSublayerList)
        {
            if (string.Compare(ll.prefabItemName, Name, true) == 0)
            {
                List <string> sdata = ll.coordinates.ToList();
                string        snew  = vec.x + ", " + vec.y;
                sdata.Add(snew);
                ll.coordinates = sdata.ToArray();

                return(true);
            }
        }
        return(false);
    }
Ejemplo n.º 24
0
    void SetupDrones()
    {
        int i = 0;

        foreach (var item in mission.drones)
        {
            Vector3 position3d;
            Mapbox.Utils.Vector2d mapboxPosition = new Mapbox.Utils.Vector2d(item.latitude, item.longitude);
            position3d     = Map.GeoToWorldPosition(mapboxPosition, false);
            groundAltitude = Map.QueryElevationInUnityUnitsAt(Map.WorldToGeoPosition(position3d));
            position3d.y   = groundAltitude;
            // Defaultne je prvy dron ten co uz je v scene
            if (i != activeDrone)
            {
                AddDrone(position3d);
            }
            i++;
        }
    }
Ejemplo n.º 25
0
    private void GeneratePoint(Checkpoint item)
    {
        GameObject WayPointPointerPrefab;

        WayPointPointerPrefab = Resources.Load <GameObject>("Zones/WayPointPointer");
        GameObject WayPointPointer = Instantiate(WayPointPointerPrefab);

        WayPointPointer.transform.SetParent(transform);
        // Vytvor vektor z gps
        Mapbox.Utils.Vector2d p = new Mapbox.Utils.Vector2d(item.points[0].latitude, item.points[0].longitude);
        // // Ziskaj poziciu
        Vector3 position = Map.GeoToWorldPosition(p, false);

        // Ziskaj vysku
        groundAltitude = Map.QueryElevationInUnityUnitsAt(Map.WorldToGeoPosition(position));
        position.y     = groundAltitude + (float)item.points[0].height;
        WayPointPointer.transform.position = position;
        WayPointPointer.name           = item.name;
        item.points[0].pointGameObject = WayPointPointer;
    }
Ejemplo n.º 26
0
    public void Movement(AbstractMap mapVariable, Mapbox.Utils.Vector2d originalLatitudeLongitude)
    {
        float currentZoom    = mapVariable.Zoom;
        float zoomDifference = 1 + (15 - currentZoom);

        Mapbox.Utils.Vector2d latitudeLongitude = mapVariable.CenterLatitudeLongitude;
        if (Input.GetKey(KeyCode.E))
        {
            currentZoom += zoomRate / zoomRateScalingFactor;
            CameraMovement.instance.UpdateMap(currentZoom);
        }
        if (Input.GetKey(KeyCode.Q))
        {
            currentZoom -= zoomRate / zoomRateScalingFactor;
            CameraMovement.instance.UpdateMap(currentZoom);
        }
        if (Input.GetKey(KeyCode.W))
        {
            latitudeLongitude.x += scrollRate / scrollRateScalingFactor * Mathf.Pow(zoomDifference, 3);
            CameraMovement.instance.UpdateMap(latitudeLongitude);
        }
        if (Input.GetKey(KeyCode.S))
        {
            latitudeLongitude.x -= scrollRate / scrollRateScalingFactor * Mathf.Pow(zoomDifference, 3);
            CameraMovement.instance.UpdateMap(latitudeLongitude);
        }
        if (Input.GetKey(KeyCode.A))
        {
            latitudeLongitude.y -= scrollRate / scrollRateScalingFactor * Mathf.Pow(zoomDifference, 3);
            CameraMovement.instance.UpdateMap(latitudeLongitude);
        }
        if (Input.GetKey(KeyCode.D))
        {
            latitudeLongitude.y += scrollRate / scrollRateScalingFactor * Mathf.Pow(zoomDifference, 3);
            CameraMovement.instance.UpdateMap(latitudeLongitude);
        }
        if (Input.GetKey(KeyCode.Space))
        {
            CameraMovement.instance.UpdateMap(originalLatitudeLongitude);
        }
    }
Ejemplo n.º 27
0
 public void newMap()
 {
     if (map != null)
     {
         lats.Clear();
         longs.Clear();
         foreach (Transform tile in map.transform)
         {
             if (tile.GetComponent <UnityTile>())
             {
                 Mapbox.Utils.Vector2d latLong = tileToLatLong(tile.GetComponent <UnityTile>().UnwrappedTileId.Z, tile.GetComponent <UnityTile>().UnwrappedTileId.X, tile.GetComponent <UnityTile>().UnwrappedTileId.Y);
                 lats.Add((float)latLong.x);
                 longs.Add((float)latLong.y);
             }
         }
         lats.Sort();
         longs.Sort();
         if (lats.Count > 0 && longs.Count > 0)
         {
             //Debug.Log("Lat min:" + lats[0] + ", Lat max:" + lats[lats.Count - 1]);
             //Debug.Log("Long min:" + longs[0] + ", Long max:" + longs[longs.Count - 1]);
             if (wl != null)
             {
                 wl.latMax = lats[lats.Count - 1];
                 wl.latMin = lats[0];
                 wl.lngMax = longs[longs.Count - 1];
                 wl.lngMin = longs[0];
                 float tmp = distance((float)map.CenterLatitudeLongitude.x, (float)map.CenterLatitudeLongitude.y, wl.latMax, wl.lngMin);
                 wl.satRadius = (90 - Mathf.Atan(400000.0f / tmp) * Mathf.Rad2Deg);
                 //Debug.Log(tmp + " " + wl.satRadius + " " + (90 - Mathf.Atan(400000.0f / tmp) * Mathf.Rad2Deg));
             }
             else
             {
                 Debug.Log("No webloader");
             }
         }
     }
 }
Ejemplo n.º 28
0
    /* 0 simulovaný vstup - náhodný pohyb
     * 1 manuální řízení ovladačem
     * 2 ROS
     */

    // Use this for initialization
    void Start()
    {
        // Prvy dron je vzdy ten defaultny
        string path        = Application.streamingAssetsPath + "/mission.json";
        string jsonContent = File.ReadAllText(path);

        Mission mission = JsonUtility.FromJson <Mission>(jsonContent);
        Vector3 pos;

        Mapbox.Utils.Vector2d p = new Mapbox.Utils.Vector2d(mission.drones[0].latitude, mission.drones[0].longitude);
        pos = Map.GeoToWorldPosition(p, false);
        Debug.Log(pos);
        float groundAltitude = Map.QueryElevationInUnityUnitsAt(Map.WorldToGeoPosition(pos));

        pos.y = groundAltitude;
        Debug.Log("thr" + pos);


        positionDataS = new DroneData(Map, pos);
        positionData  = positionDataM = new DroneDataManual(Map, pos);
        positionDataR = new DroneRosData(Map, pos);
        Drones.drones.Add(transform.gameObject);
    }
Ejemplo n.º 29
0
    public void UpdateDroneFlightData(DroneFlightData flightData)
    {
        FlightData = flightData;
        if (double.IsNaN(FlightData.Latitude) || double.IsNaN(FlightData.Longitude))
        {
            return;
        }

        Mapbox.Utils.Vector2d mapboxPosition = new Mapbox.Utils.Vector2d(FlightData.Latitude, FlightData.Longitude);
        Vector3 position3d = MapController.Instance.Map.GeoToWorldPosition(mapboxPosition, false);

        if (FlightData.DroneId == "DJI-Mavic2")
        {
            float groundAltitude = MapController.Instance.Map.QueryElevationInUnityUnitsAt(MapController.Instance.Map.WorldToGeoPosition(position3d));
            position3d.y = groundAltitude + (float)FlightData.Altitude;
        }
        else
        {
            position3d.y = (float)FlightData.Altitude;
        }
        DroneGameObject.transform.position    = position3d;
        DroneGameObject.transform.eulerAngles = new Vector3((float)FlightData.Pitch, (float)FlightData.Yaw + (float)FlightData.Compass, (float)FlightData.Roll);
    }
Ejemplo n.º 30
0
    void GrabAction()
    {
        //Debug.Log ("grabbing");
        //attachment.transform.position += new Vector3(gestureRecognitionController.GetDominantVelocity (isLeftHanded).x, 0.0f, gestureRecognitionController.GetDominantVelocity(isLeftHanded).z);



        //Debug.Log (gestureRecognitionController.GetDominantHand (false).PalmPosition.ToVector3 ());
        //if (!(gestureRecognitionController.GetHandPinchStartPosition (gestureRecognitionController.GetDominantHand (false)) == Vector3.negativeInfinity))

        GameObject mainCamera          = GameObject.FindWithTag("MainCamera");
        Vector3    startPinch          = gestureRecognitionController.GetHandPinchStartPosition(gestureRecognitionController.GetDominantHand(false)) - mainCamera.transform.position;
        Vector3    currentHandPosition = gestureRecognitionController.GetDominantHand(false).PalmPosition.ToVector3() - mainCamera.transform.position;

        if (!float.IsNegativeInfinity(startPinch.x))
        {
            if (actionType == 0)
            {
                //Vector3 velocity = Quaternion.AngleAxis((mainCamera.transform.position), Vector3.up) * gestureRecognitionController.GetDominantVelocity(isLeftHanded);
                //float angle = Quaternion.Angle (mainCamera.transform.rotation, attachment.transform.rotation);
                //if (mainCamera.transform.rotation > attachment.transform.rotation)
                //{
                //	angle = -angle;
                //}

                float angle = mainCamera.transform.localEulerAngles.y - attachment.transform.localEulerAngles.y;
                Debug.Log("" + mainCamera.transform.localEulerAngles.y + " : " + attachment.transform.localEulerAngles.y + " : " + angle);

                Vector3 movement = Quaternion.AngleAxis(angle, Vector3.up) * gestureRecognitionController.GetDominantVelocity(isLeftHanded);
                Mapbox.Utils.Vector2d mapboxMovement = new Mapbox.Utils.Vector2d(movement.z, movement.x);
                attachment.UpdateMap(attachment.CenterLatitudeLongitude - (mapboxMovement * 0.0005f), attachment.Zoom);
            }
            else if (actionType == 1)
            {
            }
            else if (actionType == 2)
            {
                float   direction      = startPinch.x - currentHandPosition.x;
                float   angle          = Vector2.SignedAngle(new Vector2(currentHandPosition.x, currentHandPosition.z), new Vector2(startPinch.x, startPinch.z));
                float   currentAngle   = attachment.transform.eulerAngles.y;
                Vector3 targetLocation = (Quaternion.Euler(0, startAngle + angle - currentAngle, 0) * (attachment.transform.position - mainCamera.transform.position)) + mainCamera.transform.position;
                attachment.transform.SetPositionAndRotation(targetLocation, Quaternion.Euler(0, (startAngle + angle), 0));
            }

            //Debug.Log (direction);

            //if (attachment.transform.eulerAngles.y / 180 < 1) {
            //	currentAngle = attachment.transform.eulerAngles.y % 180;
            //} else {
            //	currentAngle = -attachment.transform.eulerAngles.y % 180;
            //}
            //Vector3 targetLocation = attachment.transform.position;

            //attachment.transform.rotation = Quaternion.Euler(0, (startAngle + angle), 0);

            //Debug.Log ((startAngle + angle - currentAngle));
            //Debug.Log ("" + startAngle + " + " + angle + " - " + currentAngle);

            /*/if (direction <= 0)
             * {
             *      attachment.transform.rotation = Quaternion.Euler(0, (startAngle + angle - currentAngle) % 180, 0);
             *      //Vector3 targetLocation = (Quaternion.Euler (0, startAngle - angle - currentAngle, 0) * (attachment.transform.position - cameraPosition))  + cameraPosition - attachment.transform.position;
             *      //attachment.transform.SetPositionAndRotation(targetLocation , Quaternion.Euler(0, (startAngle + angle - currentAngle) % 180, 0));
             *
             *      Debug.Log ((startAngle + angle - currentAngle) % 180);
             *      //attachment.transform.RotateAround (cameraPosition, Vector3.up, startAngle - angle - currentAngle);
             *      Debug.Log ("" + startAngle + " + " + angle + " - " + currentAngle);
             * }
             * else
             * {
             *      attachment.transform.rotation = Quaternion.Euler(0, (startAngle - angle - currentAngle) % 180, 0);
             *      //Vector3 targetLocation = (Quaternion.Euler (0, startAngle + angle - currentAngle, 0) * (attachment.transform.position - cameraPosition)) + cameraPosition - attachment.transform.position;
             *      //attachment.transform.SetPositionAndRotation(targetLocation , Quaternion.Euler(0, (startAngle - angle - currentAngle) % 180, 0));
             *      Debug.Log ((startAngle - angle - currentAngle) % 180);
             *      //attachment.transform.RotateAround (cameraPosition, Vector3.up, startAngle + angle - currentAngle);
             *      Debug.Log ("" + startAngle + " - " + angle + " - " + currentAngle);
             * }/*/
        }

        //Vector2 startPinch = (Vector2)gestureRecognitionController.GetHandPinchStartPosition (gestureRecognitionController.GetDominantHand (false));
        //if (!float.IsNegativeInfinity (startPinch.x))
        //{

        //}
    }