Exemplo n.º 1
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);
         }
     }
 }
Exemplo n.º 2
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;
        }
    }
Exemplo n.º 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]
    }
Exemplo n.º 4
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;
    }
Exemplo n.º 5
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);
    }
Exemplo n.º 6
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;
    }