Exemple #1
0
    void Update()
    {
        if (GTW.bSphere)
        {
            mf.mesh = mesh_country_city_name_ecef;
        }
        else
        {
            mf.mesh = mesh_country_city_name_mercator;
        }

        Vector3 r = Vector3.zero;

        if (Map.projection.blend < 0.5f)
        {
            Earth_Grid.project_mercator(ref r, Map.Instance.geocam.coord);
        }
        else
        {
            Earth_Grid.project_ecef(ref r, Map.Instance.geocam.coord);
        }

        float o = Mathf.Lerp(3f, 10f, Map.projection.blend);// 相机距离参考 球面是10 平面3

        if (last_r != r || last_o != o)
        {
            countryMaterial.SetVector("_Interest", new Vector4(r.x, r.y, r.z, o));
            cityMaterial.SetVector("_Interest", new Vector4(r.x, r.y, r.z, o));
            last_r = r;
            last_o = o;
        }
    }
Exemple #2
0
 private void LanLonToV3(ref Vector3 A, Vector3 M)
 {
     if (Missile.bStaticEffect)
     {
         if (Map.projection.dir < 0f)// e.project(A, M),// this.projection.blend < 0.5 ? GTW.project_mercator(e, t) : GTW.project_ecef(e, t)
         {
             Earth_Grid.project_mercator(ref A, M);
         }
         else
         {
             Earth_Grid.project_ecef(ref A, M);
         }
     }
     else
     {
         if (Map.projection.blend < 0.5f)// e.project(A, M),// this.projection.blend < 0.5 ? GTW.project_mercator(e, t) : GTW.project_ecef(e, t)
         {
             Earth_Grid.project_mercator(ref A, M);
         }
         else
         {
             Earth_Grid.project_ecef(ref A, M);
         }
     }
 }
Exemple #3
0
    //Vector3 MIS_i = Vector3.zero;// i = vec3.create(),
    //Vector3 MIS_u = Vector3.zero;// u = vec3.create(),
    //Vector3 MIS_c = Vector3.zero;// c = vec3.create(),
    //Vector3 MIS_s = Vector3.zero;// s = vec3.create();

    public void CreateTransform(ref Vector3 position, ref Vector3 euler, Vector3 t /* float r,   */)
    {
        Matrix4x4 e = Matrix4x4.identity;
        Vector3   o = Vector3.zero; // var o = i,
        Vector3   a = Vector3.zero; // a = u,
        Vector3   l = Vector3.zero; // l = c,
        Vector3   f = Vector3.zero; // f = s;

        bool bmercator;

        //if (Missile.bStaticEffect)
        bmercator = Map.projection.dir < 0f;
        //else
        //    bmercator = Map.projection.blend < 0.5f;

        if (bmercator)// n.project(f, t),// this.projection.blend < 0.5 ? GTW.project_mercator(e, t) : GTW.project_ecef(e, t)
        {
            Earth_Grid.project_mercator(ref f, t);
        }
        else
        {
            Earth_Grid.project_ecef(ref f, t);
        }


        if (!bmercator) // n.projection.blend > 0.5 ? (vec3.normalize(l, f), vec3.set(o, 0, 1, 0), vec3.cross(o, l, o), vec3.normalize(o, o), vec3.cross(a, o, l), e[0] = o[0], e[1] = o[1], e[2] = o[2], e[4] = l[0], e[5] = l[1], e[6] = l[2], e[8] = a[0], e[9] = a[1], e[10] = a[2]) : (mat4.identity(e), mat4.rotateX(e, e, -0.5 * Math.PI)),
        {
            l = Vector3.Normalize(f);
            o = Vector3.up;
            o = Vector3.Cross(l, o);
            o.Normalize();
            a    = Vector3.Cross(o, l);
            e[0] = o[0]; e[1] = o[1]; e[2] = o[2]; e[4] = l[0]; e[5] = l[1]; e[6] = l[2]; e[8] = a[0]; e[9] = a[1]; e[10] = a[2];
        }
        else
        {
            e = Matrix4x4.identity;//mat4.identity(e), mat4.rotateX(e, e, -0.5 * Math.PI)
            labels.rotatex(ref e, e, -0.5f * Mathf.PI);
        }

        Quaternion q = Quaternion.LookRotation(e.GetColumn(2), e.GetColumn(1));

        euler = q.eulerAngles;

        // r && mat4.scale(e, e, [
        // r,
        // r,
        // r
        // ]),
        position = f;// e[12] = f[0],
        // e[13] = f[1],
        // e[14] = f[2]
    }
Exemple #4
0
    void AddAdjustHelper(city_data cd)
    {
        if (Application.isEditor)
        {
            if (goAdjustHelper == null)
            {
                goAdjustHelper = new GameObject("AdjustHelper");
            }

            GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
            go.name             = cd.name;
            go.transform.parent = goAdjustHelper.transform;
            Vector3 pos = new Vector3(cd.coord.x, cd.coord.y);
            Earth_Grid.project_mercator(ref pos, pos);
            go.transform.localScale    = new Vector3(0.01f, 0.01f, 0.01f);
            go.transform.localPosition = new Vector3(-pos.x, pos.y, 0f);
            go.AddComponent <MercatorToLanlon>();
        }
    }
Exemple #5
0
    void Start()
    {
        MainCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();
        GameObject goStars = new GameObject("Stars");
        //goStars.transform.localScale = new Vector3(-1f, 1f, 1f);
        MeshRenderer mr_stars   = goStars.AddComponent <MeshRenderer>();
        MeshFilter   mf_stars   = goStars.AddComponent <MeshFilter>();
        Mesh         mesh_stars = new Mesh();

        mesh_stars.name = "mesh_stars";
        mf_stars.mesh   = mesh_stars;
        Material mat_stars = Resources.Load <Material>("Materials/stars");

        mr_stars.material = mat_stars;

        Stars.build_stars(mesh_stars);


        GameObject goGrid = new GameObject("EarthGrid");

        goGrid.transform.localScale = new Vector3(-1f, -1f, 1f);
        MeshRenderer mr_grid   = goGrid.AddComponent <MeshRenderer>();
        MeshFilter   mf_grid   = goGrid.AddComponent <MeshFilter>();
        Mesh         mesh_grid = new Mesh();

        mesh_grid.name = "mesh_grid";
        Earth_Grid.build_earth_grid(mesh_grid);
        mf_grid.mesh     = mesh_grid;
        mat_grid         = Resources.Load <Material>("Materials/earth_grid");
        mr_grid.material = mat_grid;



        GameObject goCoast = new GameObject("Coast");

        goCoast.transform.localScale = new Vector3(-1f, 1f, 1f);
        MeshRenderer mr_coast   = goCoast.AddComponent <MeshRenderer>();
        MeshFilter   mf_coast   = goCoast.AddComponent <MeshFilter>();
        Mesh         mesh_coast = new Mesh();

        mesh_coast.name   = "mesh_coast";
        mf_coast.mesh     = mesh_coast;
        mat_coast         = Resources.Load <Material>("Materials/coast");
        mr_coast.material = mat_coast;


        goCountry = new GameObject("Countries");
        goCountry.transform.localScale = new Vector3(-1f, 1f, 1f);
        mr_country = goCountry.AddComponent <MeshRenderer>();
        MeshFilter mf_country = goCountry.AddComponent <MeshFilter>();

        mesh_country = new Mesh();
        mesh_country.subMeshCount = 4;
        mesh_country.name         = "mesh_country";
        mf_country.mesh           = mesh_country;

        mat_country          = Resources.Load <Material>("Materials/country");
        mat_country_pick     = Resources.Load <Material>("Materials/country_pick");
        mat_country_picked   = Resources.Load <Material>("Materials/country_picked");
        mat_border_picked    = Resources.Load <Material>("Materials/border_picked");
        mat_boundary         = Resources.Load <Material>("Materials/boundary");
        CountriesMats        = new Material[4];
        CountriesMats[0]     = mat_country;
        CountriesMats[1]     = mat_boundary;
        CountriesMats[2]     = mat_country_picked;
        CountriesMats[3]     = mat_border_picked;
        mr_country.materials = CountriesMats;

        CountriesPickMats    = new Material[1];
        CountriesPickMats[0] = mat_country_pick;



        //Country.load_map_json();
        Country.build_geometry(mesh_country, mesh_coast);

        goCorona = new GameObject("Corona");
        //goCorona.transform.localScale = new Vector3(-1f, 1f, 1f);
        MeshRenderer mr_corona   = goCorona.AddComponent <MeshRenderer>();
        MeshFilter   mf_corona   = goCorona.AddComponent <MeshFilter>();
        Mesh         mesh_corona = new Mesh();

        mesh_corona.name = "mesh_corona";
        Corona.build_corona(mesh_corona);
        mf_corona.mesh     = mesh_corona;
        mat_corona         = Resources.Load <Material>("Materials/corona");
        mr_corona.material = mat_corona;


        mesh_stars.bounds   = new Bounds(mesh_stars.bounds.center, new Vector3(100f, 100f, 100f));
        mesh_grid.bounds    = new Bounds(mesh_grid.bounds.center, new Vector3(100f, 100f, 100f));
        mesh_country.bounds = new Bounds(mesh_country.bounds.center, new Vector3(100f, 100f, 100f));
        mesh_coast.bounds   = new Bounds(mesh_coast.bounds.center, new Vector3(100f, 100f, 100f));
        mesh_corona.bounds  = new Bounds(mesh_corona.bounds.center, new Vector3(100f, 100f, 100f));

        mat_corona.SetColor("_Color0", new Color(0.07f, 0.25f, 0.16f));
        bChangeColor = true;
        bDark        = true;
        bSphere      = true;
        fDeform      = 1f;
        bChangeColor = true;

        Update();
        UpdateDeform();
    }
Exemple #6
0
    void UpdateCamera()
    {
        time = 1f * (Time.time - te);
        dt   = 1f / 60f;

        d();

        //         if ('geocam' == z.camera_mode) {
        bool    r = projection.dir > 0f;;     // var r = z.projection.dir > 0,
        Vector3 n = geocam.coord;             // n = z.geocam.coord,
        Vector3 o = geocam.coord_target;      // o = z.geocam.coord_target,
        Vector3 a = geocam.coord_delta;       // a = z.geocam.coord_delta;

        o   += a;                             // vec3.add(o, o, a),
        o[1] = Mathf.Clamp(o[1], -90f, 90f);  // o[1] = clamp(o[1], -80, 80);
        float[] i;                            // var i;
        i    = r ? ee.ecef : ee.mercator;     // i = r ? ee.ecef : ee.mercator,// 获取相机最大最小高度
        o[2] = Mathf.Clamp(o[2], i[0], i[1]); // o[2] = clamp(o[2], i[0], i[1]),
        float scale = Mathf.InverseLerp(i[0], i[1], o[2]);

        if (r)
        {
            if (n[0] < -180f)
            {
                n[0] += 360f;
                o[0] += 360f;
            }
            else if (n[0] > 180f)
            {
                n[0] -= 360f;
                o[0] -= 360f;
            }
        }
        else
        {
            o[0] = Mathf.Clamp(o[0], -180f, 180f);                       // r ? n[0] < -180 ? (n[0] += 360, o[0] += 360) : n[0] > 180 && (n[0] -= 360, o[0] -= 360) : o[0] = clamp(o[0], -180, 180),
        }
        n  = Vector3.Lerp(n, o, geocam.lerp_speed /* * scale*/);         // vec3.lerp(n, n, o, z.geocam.lerp_speed),
        a *= 0.9f;                                                       // vec3.scale(a, a, 0.9),
        Earth_Grid.project_mercator(ref K, new Vector3(n[0], n[1], 0f)); // GTW.project_mercator(K, [n[0], n[1], 0]),
        Earth_Grid.project_mercator(ref Q, n);                           // GTW.project_mercator(Q, n),
        //Q[1] -= 2f;// Q[1] -= 2,// 注释此行让相机始终垂直看向地面
        Z = K - Q;                                                       // vec3.sub(Z, K, Q),
        Z.Normalize();                                                   // vec3.normalize(Z, Z),
        K = Q;                                                           // vec3.copy(K, Q);

        Vector3 u = Vector3.zero;                                        // var u = [ 0, 0, 0];

        Earth_Grid.project_ecef(ref u, new Vector3(n[0], n[1], 0f));     // GTW.project_ecef(u, [ n[0], n[1], 0]),
        Earth_Grid.project_ecef(ref Q, n);                               // GTW.project_ecef(Q, n);
        //float c = Mathf.Clamp01(2f * (I - n[2]));// var c = clamp(2 * (I - n[2]), 0, 1),
        //c = Mathf.Lerp(0f, 2f, c); // c = lerp(0, 2, c);
        //Q[1] -= c;// Q[1] -= c,// 注释此行让相机始终垂直看向地面
        J = u - Q;                              // vec3.sub(J, u, Q),
        J.Normalize();                          // vec3.normalize(J, J);
        float l = smoothstep(projection.blend); // var l = smoothstep(z.projection.blend);

        K = Vector3.Lerp(K, Q, l);              // vec3.lerp(K, K, Q, l),// 相机位置
        Z = Vector3.Lerp(Z, J, l);              // vec3.lerp(Z, Z, J, l),// 相机目标
        // 坐标赋值给Unit对象时x需要反向
        K.x = -K.x;
        Z.x = -Z.x;
        goLookAt.transform.position            = K + Z;// z.camera.update(K, Z)}
        GTW.MainCamera.transform.localPosition = K;
        GTW.MainCamera.transform.LookAt(goLookAt.transform);
        projection.blend    = Mathf.Clamp01(projection.blend + projection.dir / 120f); //z.projection.blend = clamp(z.projection.blend + z.projection.dir / 120, 0, 1)
        geocam.coord        = n;
        geocam.coord_target = o;
        geocam.coord_delta  = a;
    }
Exemple #7
0
    void BuildLabelMesh(Mesh mesh_ecef, Mesh mesh_mercator)
    {
        CharacterInfo ch;

        labelFont.GetCharacterInfo('西', out ch);
        float      fBaseX   = ch.uvTopRight.x == ch.uvTopLeft.x ? Mathf.Abs(ch.uvTopRight.y - ch.uvTopLeft.y) : Mathf.Abs(ch.uvTopRight.x - ch.uvTopLeft.x);
        Matrix4x4  mm       = Matrix4x4.identity;
        Quaternion rotation = Quaternion.Euler(90f, 0f, 0f);
        Vector3    sc       = Vector3.one;
        Vector3    tr       = new Vector3(0f, 0f, 0f);

        mm.SetTRS(tr, rotation, sc);
        List <Vector3> label_vertex_ecef        = new List <Vector3>();
        List <Vector4> label_uv_ecef            = new List <Vector4>();
        List <int>     label_index_ecef_country = new List <int>();
        List <int>     label_index_ecef_city    = new List <int>();

        List <Vector3> label_vertex_mercator        = new List <Vector3>();
        List <Vector4> label_uv_mercator            = new List <Vector4>();
        List <int>     label_index_mercator_country = new List <int>();
        List <int>     label_index_mercator_city    = new List <int>();

        int[]   c           = { -1, -1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1 };
        int     idx         = 0;
        bool    bCountry    = true;
        int     iCountryCnt = 0;
        Vector2 tmpUV       = Vector2.zero;
        Vector4 tmpTex      = Vector4.zero;

        foreach (label_data ld in labels_data_list)
        {
            ld.coord[2] = 0.0002f;
            Earth_Grid.project_ecef(ref ld.pos, ld.coord);
            float n     = 1f * ld.font_size;
            int   ldLen = ld.name.Length;

            bCountry = iCountryCnt <= country_count;
            ++iCountryCnt;
            float fHalfLen = ldLen * 0.5f;
            for (int ic = 0; ic < ldLen; ++ic)
            {
                float fOffset = ((float)ic - fHalfLen) * 2f + 1f;

                labelFont.GetCharacterInfo(ld.name[ic], out ch);
                ld.box[0] = ch.uvTopLeft.x; ld.box[1] = ch.uvTopLeft.y; ld.box[2] = ch.uvBottomRight.x; ld.box[3] = ch.uvBottomRight.y;
                t(ref ld.mat, ld.pos, n * fBaseX * LabelSizeTexScale.x, n * Mathf.Abs(ld.box[3] - ld.box[1]) * LabelSizeTexScale.y, true);

                for (int o = 0; o < c.Length; o += 2)//             for (var o = 0; o < c.length; o += 2) u[0] = c[o + 0],
                {
                    Vector3 u = Vector3.zero;
                    u[0] = ((float)c[o] - fOffset);
                    u[1] = c[o + 1];                // u[1] = c[o + 1],
                    u[2] = 0;                       // u[2] = 0,
                    u    = ld.mat.MultiplyPoint(u); // vec3.transformMat4(u, u, e.mat),
                    label_vertex_ecef.Add(u);       // i.push(u[0], u[1], u[2]),
                    if (bCountry)
                    {
                        label_index_ecef_country.Add(idx++);
                    }
                    else
                    {
                        label_index_ecef_city.Add(idx++);
                    }
                    tmpUV = GetUV(c[o], c[o + 1], ch);
                    tmpTex.Set(tmpUV.x, tmpUV.y, ld.font_size, ld.pick_uid);
                    label_uv_ecef.Add(tmpTex); // i.push(u[0], u[1])
                }
            }
        }

        mesh_ecef.SetVertices(label_vertex_ecef);
        mesh_ecef.SetIndices(label_index_ecef_country.ToArray(), MeshTopology.Triangles, 0);
        mesh_ecef.SetIndices(label_index_ecef_city.ToArray(), MeshTopology.Triangles, 1);
        mesh_ecef.SetUVs(0, label_uv_ecef);

        idx         = 0;
        bCountry    = true;
        iCountryCnt = 0;
        foreach (label_data ld in labels_data_list)
        {
            ld.coord[2] = 0.001f;
            Earth_Grid.project_mercator(ref ld.pos, ld.coord);
            float n     = 1f * ld.font_size;
            int   ldLen = ld.name.Length;

            bCountry = iCountryCnt <= country_count;
            ++iCountryCnt;
            float fHalfLen = ldLen * 0.5f;
            for (int ic = 0; ic < ldLen; ++ic)
            {
                float fOffset = ((float)ic - fHalfLen) * 2f + 1f;

                labelFont.GetCharacterInfo(ld.name[ic], out ch);
                ld.box[0] = ch.uvTopLeft.x; ld.box[1] = ch.uvTopLeft.y; ld.box[2] = ch.uvBottomRight.x; ld.box[3] = ch.uvBottomRight.y;
                t(ref ld.mat, ld.pos, n * fBaseX * LabelSizeTexScale.x * 0.3f, n * Mathf.Abs(ld.box[3] - ld.box[1]) * LabelSizeTexScale.y * 0.3f, false);

                for (int o = 0; o < c.Length; o += 2)//             for (var o = 0; o < c.length; o += 2) u[0] = c[o + 0],
                {
                    Vector3 u = Vector3.zero;
                    u[0] = ((float)c[o] - fOffset);
                    u[1] = c[o + 1];                // u[1] = c[o + 1],
                    u[2] = 0;                       // u[2] = 0,
                    u    = ld.mat.MultiplyPoint(u); // vec3.transformMat4(u, u, e.mat),
                    label_vertex_mercator.Add(u);   // i.push(u[0], u[1], u[2]),
                    if (bCountry)
                    {
                        label_index_mercator_country.Add(idx++);
                    }
                    else
                    {
                        label_index_mercator_city.Add(idx++);
                    }
                    tmpUV = GetUV(c[o], c[o + 1], ch);
                    tmpTex.Set(tmpUV.x, tmpUV.y, ld.font_size, ld.pick_uid);
                    label_uv_mercator.Add(tmpTex); // i.push(u[0], u[1])
                }
            }
        }

        mesh_mercator.SetVertices(label_vertex_mercator);
        mesh_mercator.SetIndices(label_index_mercator_country.ToArray(), MeshTopology.Triangles, 0);
        mesh_mercator.SetIndices(label_index_mercator_city.ToArray(), MeshTopology.Triangles, 1);
        mesh_mercator.SetUVs(0, label_uv_mercator);
    }
Exemple #8
0
//    IEnumerator GetData()
    public void UpdateData(string str_data)
    {
//         bUpdating = true;
//         WWW www = new WWW(strRequestDataUrl);
//         yield return www;
//
//         if (www.error != null)
//         {
//             JSInterface.Instance.ShowLog("Request Hotspot Data Error");
//         }
//         else
//         {
        bool ok = true;
//            Hashtable data = (Hashtable)JSON.JsonDecode(www.text, ref ok);

        Hashtable data = (Hashtable)JSON.JsonDecode(str_data, ref ok);

        if (ok)
        {
            idx0.Clear();
            idx1.Clear();
            idx2.Clear();
            int       curVerIdx = 0;
            Matrix4x4 matEcef   = Matrix4x4.identity;
            Matrix4x4 matMct    = Matrix4x4.identity;

            ArrayList al = (ArrayList)data["data"];
            ArrayList val;
            for (int i = 0; i < al.Count && i < TotalCount; ++i)
            {
                val = (ArrayList)al[i];
                int iType = (int)(double)val[1];
                if (iType == 1)
                {
                    idx0.Add(curVerIdx);
                    idx0.Add(curVerIdx + 1);
                    idx0.Add(curVerIdx + 2);
                    idx0.Add(curVerIdx);
                    idx0.Add(curVerIdx + 2);
                    idx0.Add(curVerIdx + 3);
                }
                else if (iType == 2)
                {
                    idx1.Add(curVerIdx);
                    idx1.Add(curVerIdx + 1);
                    idx1.Add(curVerIdx + 2);
                    idx1.Add(curVerIdx);
                    idx1.Add(curVerIdx + 2);
                    idx1.Add(curVerIdx + 3);
                }
                else if (iType == 3)
                {
                    idx2.Add(curVerIdx);
                    idx2.Add(curVerIdx + 1);
                    idx2.Add(curVerIdx + 2);
                    idx2.Add(curVerIdx);
                    idx2.Add(curVerIdx + 2);
                    idx2.Add(curVerIdx + 3);
                }
                Vector3 posEcef = Vector3.zero, posMct = Vector3.zero;
                Earth_Grid.project_ecef(ref posEcef, new Vector3((float)(double)val[2], (float)(double)val[3], fHeight));
                Earth_Grid.project_mercator(ref posMct, new Vector3((float)(double)val[2], (float)(double)val[3], fHeight));
                labels.t(ref matEcef, posEcef, fSize, fSize, true);
                labels.t(ref matMct, posMct, fSize, fSize, false);
                for (int j = 0; j < c.Length; j += 2, ++curVerIdx)
                {
                    vxEcef[curVerIdx] = matEcef.MultiplyPoint(new Vector3(c[j], c[j + 1], 0f));
                    vxMct[curVerIdx]  = matMct.MultiplyPoint(new Vector3(c[j], c[j + 1], 0f));
                }
            }

            meshHotspot.vertices = vxMct;
            meshHotspot.SetUVs(0, new List <Vector4>(texs));
            meshHotspot.SetUVs(1, new List <Vector3>(vxEcef));
            meshHotspot.SetIndices(idx0.ToArray(), MeshTopology.Triangles, 0);
            meshHotspot.SetIndices(idx1.ToArray(), MeshTopology.Triangles, 1);
            meshHotspot.SetIndices(idx2.ToArray(), MeshTopology.Triangles, 2);
        }
//        }
//        bUpdating = false;
//        yield return null;
    }