Example #1
0
    void addInPlaceBars()
    {
        _meshes = new Dictionary <MeshSelection, Mesh>();
        _meshes.Add(MeshSelection.Cube, _cubeMesh);
        _meshes.Add(MeshSelection.Cylinder, _cylinderMesh);
        _meshes.Add(MeshSelection.Quad, _quadMesh);

        var points   = DataPointsManager.Instance.mapDataPoints;
        var maxValue = DataPointsManager.Instance.maxValue;

        foreach (MapDataPoint point in points)
        {
            GameObject bar = Instantiate(_framedBar, point.WorldPosition, Quaternion.identity);
            bar.transform.SetParent(_barsContainer, true);
            bar.transform.name = "Bar " + point.Name;

            FramedBarData barDataComponent = bar.GetComponent <FramedBarData>();
            barDataComponent.mapDataPoint = point;
            barDataComponent.Value        = point.Value;
            barDataComponent.LatLong      = point.GeoPosition;
            barDataComponent.Elevation    = _map.QueryElevationInUnityUnitsAt(point.GeoPosition);
            barDataComponent.MeshType     = _meshSelectionType;

            _bars.Add(bar);
        }

        foreach (GameObject bar in _bars)
        {
            FramedBarData barDataComponent = bar.GetComponent <FramedBarData>();
            barDataComponent.MaxValue = maxValue;
            barDataComponent.updateBars();
            //barDataComponent.shear();
        }
    }
Example #2
0
    void Update()
    {
        foreach (FeatureGameObject fgo in GameObjects)
        {
            Vector2d position         = new Vector2d(fgo.feature.geometry.coordinates[1], fgo.feature.geometry.coordinates[0]);
            Vector3  GeoWorldPosition = Map.GeoToWorldPosition(position, false);


            fgo.instance.transform.position       = GeoWorldPosition;
            fgo.instance.transform.localScale     = new Vector3(1000f, 1000f, 1000f);
            fgo.instance.transform.localPosition += new Vector3(0f, 10f + Map.QueryElevationInUnityUnitsAt(position), 0f);

            fgo.instance.transform.rotation = Quaternion.LookRotation(fgo.instance.transform.position - Camera.main.transform.position) * Quaternion.Euler(90, 0, 0);
        }

        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                Debug.Log(hit);
                if (hit.rigidbody != null)
                {
                    Debug.Log(hit.transform.gameObject.name);
                }
            }
        }
    }
    void SnapMapToTarget()
    {
        var h = _map.QueryElevationInUnityUnitsAt(_map.CenterLatitudeLongitude);

        _map.Root.transform.position = new Vector3(
            _map.Root.transform.position.x,
            _target.transform.position.y - h,
            _map.Root.transform.position.z);
    }
Example #4
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++;
        }
    }
Example #5
0
    //pozice se zadává v unity Units
    public void ChangeHomePosition(Vector3 position, bool onGround)
    {
        if (HomePoint.onGround)
        {
            float groundAltitude = Map.QueryElevationInUnityUnitsAt(Map.WorldToGeoPosition(position));
            HomePoint.pointObject.transform.localPosition = new Vector3(position.x, groundAltitude, position.z);
        }
        else
        {
            HomePoint.pointObject.transform.localPosition = position;
        }

        HomePoint.onGround = onGround;
    }
Example #6
0
    public Vector3 AdjustPosForDepth(Vector3 unadjustedPos)
    {
        AbstractMap map = MapStore.Instance.map;
        float       currentElevMeter = map.QueryElevationInMetersAt(this.latLon);
        float       currentElevUnity = map.QueryElevationInUnityUnitsAt(this.latLon) * map.transform.localScale.y;

        currentElevMeter = currentElevMeter == 0 ? 0.001f : currentElevMeter; // Cheat if necessary
        float ratio = currentElevUnity / currentElevMeter;
        // Convert kilometers to meters
        float depthInMeters = -this.depth * 1000;
        float adjUnityUnits = ratio * depthInMeters;
        float adjElevUnity  = unadjustedPos.y + adjUnityUnits - currentElevUnity;

        return(new Vector3(unadjustedPos.x, adjElevUnity, unadjustedPos.z));
    }
    public void ChangeHomePoint(Vector3 position, bool onGround)
    {
        if (OnGround)
        {
            float groundAltitude = Map.QueryElevationInUnityUnitsAt(Map.WorldToGeoPosition(transform.localPosition));
            Debug.Log("HomePoint altitude " + groundAltitude);
            transform.localPosition = new Vector3(transform.localPosition.x, groundAltitude, transform.localPosition.z);
        }
        else
        {
            transform.localPosition = position;
        }

        OnGround = onGround;
    }
Example #8
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);
    }
Example #9
0
    public float getHeightForPosition(Mapbox.Utils.Vector2d position)
    {
        float height = _map.QueryElevationInUnityUnitsAt(position);

        return(height);
    }
 public virtual void update() //volano v každém kroku pro získání nových hodnot
 {
     groundAltitude = Map.QueryElevationInUnityUnitsAt(Map.WorldToGeoPosition(position));
 }
Example #11
0
    public void loadMesh()
    {
        float       startTime   = Time.realtimeSinceStartup;
        GameObject  MapGO       = GameObject.Find("Map");
        AbstractMap Map         = MapGO.GetComponent <AbstractMap>();
        string      path        = Application.streamingAssetsPath + "/Saves/" + transform.GetComponentInChildren <TextMeshProUGUI>().text;
        string      jsonContent = File.ReadAllText(path);
        MeshData    rosMessege  = JsonUtility.FromJson <MeshData>(jsonContent);
        int         CloudsCount = rosMessege.Messages.Count;
        int         NumberOfGO  = (CloudsCount / MaxVerts) + 1;

        Debug.Log(CloudsCount);
        List <GameObject> MeshGOList = new List <GameObject>();
        GameObject        load       = new GameObject("Loader");

        load.transform.SetParent(GameObject.Find("LoadedObjects").transform);
        load.layer = 14;
        Vector3 position3d = Map.GeoToWorldPosition(new Mapbox.Utils.Vector2d(rosMessege.latitude, rosMessege.longitude));

        position3d.y               = Map.QueryElevationInUnityUnitsAt(Map.WorldToGeoPosition(position3d));
        load.transform.position    = position3d;
        load.transform.eulerAngles = new Vector3(rosMessege.rotX, rosMessege.rotY, rosMessege.rotZ);
        // Generate GameObjects
        for (int i = 0; i < NumberOfGO; i++)
        {
            GameObject newMeshGameObject = new GameObject("MeshObject");
            newMeshGameObject.AddComponent <MeshFilter>();
            newMeshGameObject.AddComponent <MeshRenderer>();
            newMeshGameObject.AddComponent <MeshCollider>();

            // newMeshGameObject
            newMeshGameObject.transform.SetParent(load.transform);
            newMeshGameObject.transform.localPosition    = new Vector3(0, 0, 0);
            newMeshGameObject.transform.localEulerAngles = new Vector3(0, 0, 0);
            newMeshGameObject.layer = 14;
            newMeshGameObject.GetComponent <MeshRenderer>().material = GetComponent <MeshRenderer>().material;
            MeshGOList.Add(newMeshGameObject);
        }

        List <MessegeInfo> Points = rosMessege.Messages;
        long NumberOfClouds       = Points.Count;


        float inc  = 0.3f;
        int   tris = 0;
        int   vert = 0;
        long  arraySize;

        for (int l = 0; l < NumberOfGO; l++)
        {
            if (l + 1 == NumberOfGO)
            {
                arraySize = -(NumberOfGO - 1) * MaxVerts + CloudsCount;
            }
            else
            {
                arraySize = MaxVerts;
            }
            Vector3[] vertices  = new Vector3[arraySize * 8];
            int[]     triangles = new int[arraySize * 36];
            Color[]   colors    = new Color[arraySize * 8];
            for (int i = 0; i < arraySize; i++)
            {
                vertices[i * 8 + 0]    = new Vector3(Points[i + MaxVerts * l].x - inc, Points[i + MaxVerts * l].z - inc, Points[i + MaxVerts * l].y + inc);
                vertices[i * 8 + 1]    = new Vector3(Points[i + MaxVerts * l].x - inc, Points[i + MaxVerts * l].z - inc, Points[i + MaxVerts * l].y - inc);
                vertices[i * 8 + 2]    = new Vector3(Points[i + MaxVerts * l].x - inc, Points[i + MaxVerts * l].z + inc, Points[i + MaxVerts * l].y - inc);
                vertices[i * 8 + 3]    = new Vector3(Points[i + MaxVerts * l].x - inc, Points[i + MaxVerts * l].z + inc, Points[i + MaxVerts * l].y + inc);
                vertices[i * 8 + 4]    = new Vector3(Points[i + MaxVerts * l].x + inc, Points[i + MaxVerts * l].z + inc, Points[i + MaxVerts * l].y + inc);
                vertices[i * 8 + 5]    = new Vector3(Points[i + MaxVerts * l].x + inc, Points[i + MaxVerts * l].z + inc, Points[i + MaxVerts * l].y - inc);
                vertices[i * 8 + 6]    = new Vector3(Points[i + MaxVerts * l].x + inc, Points[i + MaxVerts * l].z - inc, Points[i + MaxVerts * l].y - inc);
                vertices[i * 8 + 7]    = new Vector3(Points[i + MaxVerts * l].x + inc, Points[i + MaxVerts * l].z - inc, Points[i + MaxVerts * l].y + inc);
                triangles[i * 36 + 0]  = 0 + 8 * i;
                triangles[i * 36 + 1]  = 2 + 8 * i;
                triangles[i * 36 + 2]  = 1 + 8 * i;
                triangles[i * 36 + 3]  = 0 + 8 * i;
                triangles[i * 36 + 4]  = 3 + 8 * i;
                triangles[i * 36 + 5]  = 2 + 8 * i;
                triangles[i * 36 + 6]  = 2 + 8 * i;
                triangles[i * 36 + 7]  = 3 + 8 * i;
                triangles[i * 36 + 8]  = 4 + 8 * i;
                triangles[i * 36 + 9]  = 2 + 8 * i;
                triangles[i * 36 + 10] = 4 + 8 * i;
                triangles[i * 36 + 11] = 5 + 8 * i;
                triangles[i * 36 + 12] = 1 + 8 * i;
                triangles[i * 36 + 13] = 2 + 8 * i;
                triangles[i * 36 + 14] = 5 + 8 * i;
                triangles[i * 36 + 15] = 1 + 8 * i;
                triangles[i * 36 + 16] = 5 + 8 * i;
                triangles[i * 36 + 17] = 6 + 8 * i;
                triangles[i * 36 + 18] = 0 + 8 * i;
                triangles[i * 36 + 19] = 7 + 8 * i;
                triangles[i * 36 + 20] = 4 + 8 * i;
                triangles[i * 36 + 21] = 0 + 8 * i;
                triangles[i * 36 + 22] = 4 + 8 * i;
                triangles[i * 36 + 23] = 3 + 8 * i;
                triangles[i * 36 + 24] = 5 + 8 * i;
                triangles[i * 36 + 25] = 4 + 8 * i;
                triangles[i * 36 + 26] = 7 + 8 * i;
                triangles[i * 36 + 27] = 5 + 8 * i;
                triangles[i * 36 + 28] = 7 + 8 * i;
                triangles[i * 36 + 29] = 6 + 8 * i;
                triangles[i * 36 + 30] = 0 + 8 * i;
                triangles[i * 36 + 31] = 6 + 8 * i;
                triangles[i * 36 + 32] = 7 + 8 * i;
                triangles[i * 36 + 33] = 0 + 8 * i;
                triangles[i * 36 + 34] = 1 + 8 * i;
                triangles[i * 36 + 35] = 6 + 8 * i;
                colors[8 * i + 0]      = new Color32((byte)Points[i + MaxVerts * l].r, (byte)Points[i + MaxVerts * l].g, (byte)Points[i + MaxVerts * l].b, 255);
                colors[8 * i + 1]      = new Color32((byte)Points[i + MaxVerts * l].r, (byte)Points[i + MaxVerts * l].g, (byte)Points[i + MaxVerts * l].b, 255);
                colors[8 * i + 2]      = new Color32((byte)Points[i + MaxVerts * l].r, (byte)Points[i + MaxVerts * l].g, (byte)Points[i + MaxVerts * l].b, 255);
                colors[8 * i + 3]      = new Color32((byte)Points[i + MaxVerts * l].r, (byte)Points[i + MaxVerts * l].g, (byte)Points[i + MaxVerts * l].b, 255);
                colors[8 * i + 4]      = new Color32((byte)Points[i + MaxVerts * l].r, (byte)Points[i + MaxVerts * l].g, (byte)Points[i + MaxVerts * l].b, 255);
                colors[8 * i + 5]      = new Color32((byte)Points[i + MaxVerts * l].r, (byte)Points[i + MaxVerts * l].g, (byte)Points[i + MaxVerts * l].b, 255);
                colors[8 * i + 6]      = new Color32((byte)Points[i + MaxVerts * l].r, (byte)Points[i + MaxVerts * l].g, (byte)Points[i + MaxVerts * l].b, 255);
                colors[8 * i + 7]      = new Color32((byte)Points[i + MaxVerts * l].r, (byte)Points[i + MaxVerts * l].g, (byte)Points[i + MaxVerts * l].b, 255);
            }
            Mesh mesh = new Mesh();
            mesh.vertices  = vertices;
            mesh.triangles = triangles;
            mesh.colors    = colors;
            MeshGOList[l].GetComponent <MeshFilter>().mesh         = mesh;
            MeshGOList[l].GetComponent <MeshCollider>().sharedMesh = mesh;
        }
        Debug.Log(((Time.realtimeSinceStartup - startTime) * 1000f) + "ms");
    }