コード例 #1
0
ファイル: GlobeLayer.Dots.cs プロジェクト: temik911/audio
        public void DotsAddGeoObject(int objectClass, DVector2 lonLat, Color color, float size)
        {
            if (geoObjectOffset >= Dots.Length) return;

            Dots[geoObjectOffset++] = new GeoVert {
                    Color		= color,
                    Lon			= DMathUtil.DegreesToRadians(lonLat.X),
                    Lat			= DMathUtil.DegreesToRadians(lonLat.Y),
                    Position	= Vector3.Zero,
                    Tex			= new Vector4(objectClass, 0, size, 0)
                };
        }
コード例 #2
0
        public void DotsAddGeoObject(int objectClass, DVector2 lonLat, Color color, float size)
        {
            if (geoObjectOffset >= Dots.Length)
            {
                return;
            }

            Dots[geoObjectOffset++] = new GeoVert {
                Color    = color,
                Lon      = DMathUtil.DegreesToRadians(lonLat.X),
                Lat      = DMathUtil.DegreesToRadians(lonLat.Y),
                Position = Vector3.Zero,
                Tex      = new Vector4(objectClass, 0, size, 0)
            };
        }
コード例 #3
0
ファイル: GlobeLayer.Grid.cs プロジェクト: temik911/audio
        void CreateSphere(int Stacks, int Slices)
        {
            //calculates the resulting number of vertices and indices
            int nVertices = (Stacks + 1) * (Slices + 1);
            int dwIndices = (3 * Stacks * (Slices + 1)) * 2;

            int[]		indices		= new int[dwIndices];
            GeoVert[]	vertices	= new GeoVert[nVertices];

            double stackAngle = Math.PI / Stacks;
            double sliceAngle = (Math.PI * 2.0) / Slices;

            int wVertexIndex = 0;
            //Generate the group of Stacks for the sphere
            int vertcount = 0;
            int indexcount = 0;

            for (int stack = 0; stack < (Stacks + 1); stack++) {

                double phi = stack * stackAngle - Math.PI / 2.0;

                //Generate the group of segments for the current Stack
                for (int slice = 0; slice < (Slices + 1); slice++) {

                    double lambda = slice * sliceAngle;

                    vertices[vertcount].Lon = lambda + Math.PI;
                    vertices[vertcount].Lat = phi;
                    vertices[vertcount].Position = new Vector3();
                    vertices[vertcount].Tex = new Vector4((float)slice / (float)Slices, 1.0f - (float)stack / (float)Stacks, 0, 0);
                    vertices[vertcount].Color = Color.White;

                    //vertices[vertcount].TextureCoordinate = new Vector2((float)slice / (float)Slices, (float)stack / (float)Stacks);
                    vertcount++;
                    if (stack != (Stacks - 1)) {
                        indices[indexcount] = wVertexIndex;
                        indexcount++;
                        indices[indexcount] = wVertexIndex + 1;
                        indexcount++;
                        indices[indexcount] = wVertexIndex + (Slices + 1);
                        indexcount++;
                        indices[indexcount] = wVertexIndex;
                        indexcount++;
                        indices[indexcount] = wVertexIndex + (Slices + 1);
                        indexcount++;
                        indices[indexcount] = wVertexIndex + (Slices);
                        indexcount++;
                        wVertexIndex++;
                    }
                }
            }

            if (gridVertexBuffer != null) gridVertexBuffer.Dispose();
            if (gridIndexBuffer != null) gridIndexBuffer.Dispose();
            if (gridTex == null) gridTex = Game.Content.Load<Texture2D>("NE2_50M_SR_W_4096.jpg");

            gridVertexBuffer	= new VertexBuffer(Game.GraphicsDevice, typeof(GeoVert), vertices.Length);
            gridIndexBuffer		= new IndexBuffer(Game.GraphicsDevice, indices.Length);

            gridVertexBuffer.SetData(vertices, 0, vertices.Length);
            gridIndexBuffer.SetData(indices, 0, indices.Length);

            return;
        }
コード例 #4
0
        void InitDots()
        {
            dotsBuf             = new ConstBufferGeneric <DotsConstData>(Game.GraphicsDevice);
            dotsBuf.Data.Colors = new float[16 * 4];

            //var r = new Random();

            Dots = new GeoVert[505000];

            dotsVB = new VertexBuffer(Game.GraphicsDevice, typeof(GeoVert), Dots.Length);

            for (int v = 0; v < Dots.Length; v++)
            {
                var vert = new GeoVert {
                    Lon      = 0,               //DMathUtil.DegreesToRadians(30.301419 + 0.125 * r.NextDouble()),
                    Lat      = 0,               //DMathUtil.DegreesToRadians(59.942562 + 0.125 * r.NextDouble()),
                    Position = Vector3.Zero,
                    Color    = Color.White,
                    Tex      = new Vector4(1, 0, 0, 0)
                };

                Dots[v] = vert;
            }

            //// Metro
            //DotsAddGeoObject(1, new DVector2(30.291136, 59.951796), Color.White, 0.05f); // Metro
            //DotsAddGeoObject(1, new DVector2(30.278251, 59.942602), Color.White, 0.05f); // Metro
            //DotsAddGeoObject(1, new DVector2(30.234627, 59.948470), Color.White, 0.05f); // Metro
            //
            //
            //// IO Dots
            //DotsAddGeoObject(2, new DVector2(30.286614, 59.949759), Color.White, 0.05f); // Tuchkov
            //DotsAddGeoObject(2, new DVector2(30.303522, 59.947314), Color.White, 0.05f); // Birj
            //DotsAddGeoObject(2, new DVector2(30.309391, 59.940275), Color.White, 0.05f); // Dvorc
            //DotsAddGeoObject(2, new DVector2(30.290841, 59.933460), Color.White, 0.05f); // Blago
            //
            //
            //// railroads
            //DotsAddGeoObject(3, new DVector2(30.298743, 59.906812), Color.Yellow, 0.05f); // balt
            //DotsAddGeoObject(3, new DVector2(30.356464, 59.956350), Color.Yellow, 0.05f); // fin
            //DotsAddGeoObject(3, new DVector2(30.329428, 59.919639), Color.Yellow, 0.05f); // viteb
            //DotsAddGeoObject(3, new DVector2(30.361930, 59.929369), Color.Yellow, 0.05f); // moscow
            //DotsAddGeoObject(3, new DVector2(30.440599, 59.932079), Color.Yellow, 0.05f); // ladoj



            //var balt0 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.298743), Lat = DMathUtil.DegreesToRadians(59.906812), Color = new Color(1.0f, 1.0f, 1.0f, 1.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //var balt1 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.288105), Lat = DMathUtil.DegreesToRadians(59.851217), Color = new Color(1.0f, 1.0f, 1.0f, 0.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //
            //
            //var mosc0 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.361930), Lat = DMathUtil.DegreesToRadians(59.929369), Color = new Color(1.0f, 1.0f, 1.0f, 1.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //var mosc1 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.365911), Lat = DMathUtil.DegreesToRadians(59.912719), Color = new Color(1.0f, 1.0f, 1.0f, 1.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //var mosc2 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.550232), Lat = DMathUtil.DegreesToRadians(59.781460), Color = new Color(1.0f, 1.0f, 1.0f, 0.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //
            //
            //var fin0 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.356464), Lat = DMathUtil.DegreesToRadians(59.956350), Color = new Color(1.0f, 1.0f, 1.0f, 1.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //var fin1 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.357671), Lat = DMathUtil.DegreesToRadians(59.967750), Color = new Color(1.0f, 1.0f, 1.0f, 1.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //var fin2 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.294199), Lat = DMathUtil.DegreesToRadians(60.052353), Color = new Color(1.0f, 1.0f, 1.0f, 0.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            ////var fin3 = new Vert { Lon = DMathUtil.DegreesToRadians(30.298743), Lat = DMathUtil.DegreesToRadians(59.906812), Color = new Color(1.0f, 1.0f, 1.0f, 0.0f), Position = Vector3.Zero, Tex = new Vector2(0.06f, 0.0f) };
            //
            //
            //var vit0 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.329428), Lat = DMathUtil.DegreesToRadians(59.919639), Color = new Color(1.0f, 1.0f, 1.0f, 1.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //var vit1 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.334539), Lat = DMathUtil.DegreesToRadians(59.913923), Color = new Color(1.0f, 1.0f, 1.0f, 1.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //var vit2 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.419769), Lat = DMathUtil.DegreesToRadians(59.742191), Color = new Color(1.0f, 1.0f, 1.0f, 0.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //
            //
            //var lad0 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.440599), Lat = DMathUtil.DegreesToRadians(59.932079), Color = new Color(1.0f, 1.0f, 1.0f, 1.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //var lad1 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.448480), Lat = DMathUtil.DegreesToRadians(59.936919), Color = new Color(1.0f, 1.0f, 1.0f, 1.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //var lad2 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.558472), Lat = DMathUtil.DegreesToRadians(59.929517), Color = new Color(1.0f, 1.0f, 1.0f, 0.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //
            //
            //simpleRailroadsVB = new VertexBuffer(Game.GraphicsDevice, typeof(GeoVert), 18);
            //
            //simpleRailroadsVB.SetData(new GeoVert[] { balt0, balt1, mosc0, mosc1, mosc1, mosc2, fin0, fin1, fin1, fin2, vit0, vit1, vit1, vit2, lad0, lad1, lad1, lad2 }, 0, 18);

            dotsBuf.Data.Colors[0] = 1.0f;
            dotsBuf.Data.Colors[1] = 1.0f;
            dotsBuf.Data.Colors[2] = 1.0f;
            dotsBuf.Data.Colors[3] = 1.0f;


            //dotsVB.SetData(Dots, 0, Dots.Length);

            socioClasses = Game.Content.Load <Texture2D>("Urban/SocioClasses.tga");
            geoObjects   = Game.Content.Load <Texture2D>("Urban/geoObjects.tga");
        }
コード例 #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="contour"></param>
        void AddMunicipalDivision(string name, List<DVector2> contour)
        {
            if (municipalDivisions.ContainsKey(name)) return;

            var mesh = new TriangleNet.Mesh();
            mesh.Behavior.Quality = true;
            mesh.Behavior.MinAngle = 25;
            mesh.Behavior.Convex = false;

            var ig = new InputGeometry();

            ig.AddPoint(contour[0].X, contour[0].Y);
            for (int v = 1; v < contour.Count; v++) {
                ig.AddPoint(contour[v].X, contour[v].Y);
                ig.AddSegment(v - 1, v);
            }
            ig.AddSegment(contour.Count - 1, 0);

            mesh.Triangulate(ig);

            int n = mesh.Vertices.Count;

            mesh.Renumber();

            // Vertices
            var moVerts = new GeoVert[n];
            int i = 0;
            foreach (var pt in mesh.Vertices) {
                moVerts[i] = new GeoVert {
                    Lon			= pt.X * Math.PI / 180.0,
                    Lat			= pt.Y * Math.PI / 180.0,
                    Position	= Vector3.Zero,
                    Tex			= Vector4.Zero,
                    Color		= Color.White
                };

                i++;
            }

            // Triangles
            var triangles = new int[3 * mesh.Triangles.Count];
            i = 0;
            foreach (var tri in mesh.Triangles) {
                triangles[i * 3 + 0] = tri.P0;
                triangles[i * 3 + 1] = tri.P1;
                triangles[i * 3 + 2] = tri.P2;
                i++;
            }

            // Contour vertices
            var contourVerts = new GeoVert[contour.Count*2];

            contourVerts[1] = new GeoVert {
                Lon			= contour[0].X * Math.PI / 180.0,
                Lat			= contour[0].Y * Math.PI / 180.0,
                Position	= Vector3.Zero,
                Tex			= Vector4.Zero,
                Color		= Color.Red
            };

            for (int j = 1; j < contour.Count; j++) {
                contourVerts[2*j+1] = new GeoVert {
                    Lon			= contour[j].X * Math.PI / 180.0,
                    Lat			= contour[j].Y * Math.PI / 180.0,
                    Position	= Vector3.Zero,
                    Tex			= Vector4.Zero,
                    Color		= Color.Red
                };
                contourVerts[2*j] = contourVerts[2*(j - 1) + 1];
            }

            contourVerts[0] = contourVerts[contourVerts.Length-1];

            // Create buffers
            var vb		= new VertexBuffer(Game.GraphicsDevice, typeof (GeoVert), moVerts.Length);
            var inds	= new IndexBuffer(Game.GraphicsDevice, triangles.Length);
            var cont	= new VertexBuffer(Game.GraphicsDevice, typeof (GeoVert), contourVerts.Length);

            vb.SetData(moVerts, 0, moVerts.Length);
            inds.SetData(triangles, 0, triangles.Length);
            cont.SetData(contourVerts, 0, contourVerts.Length);

            municipalDivisions.Add(name, new MD {
                    Contour		= cont,
                    Indeces		= inds,
                    Vertices	= vb,
                    Value		= r.NextFloat(0.0f, 1.0f)
                });
        }
コード例 #6
0
        void InitBuildingsOSM()
        {
            var osm = Game.GetService<LayerService>().OpenStreetMapSource;

            List<GeoVert> lines = new List<GeoVert>();
            List<GeoVert> simple = new List<GeoVert>();

            var nodes = osm.allNodes;
            int k = 0;
            foreach (var way in osm.allWays) {
                if (!way.Value.isBuilding) continue;

                var centerMerc = way.Value.BBox.Center();
                float width		= (way.Value.BBox.Maximum - way.Value.BBox.Minimum).X * 10000.0f;
                float length	= (way.Value.BBox.Maximum - way.Value.BBox.Minimum).Y * 10000.0f;
                double lon, lat;
                GeoHelper.TileToWorldPos(centerMerc.X, centerMerc.Y, 0, out lon, out lat);

                simple.Add(new GeoVert {
                        Lon			= DMathUtil.DegreesToRadians(lon),
                        Lat			= DMathUtil.DegreesToRadians(lat),
                        Color		= Color.White,
                        Position	= Vector3.Zero,
                        Tex			= new Vector4(width, length, 0, 0)
                    });

                List<DVector2> buildingVertices = new List<DVector2>();
                for (int i = 0; i < way.Value.nodeRef.Length - 1; i++) {
                    var nInds = way.Value.nodeRef;

                    lines.Add(new GeoVert {
                            Lon			= DMathUtil.DegreesToRadians(nodes[nInds[i]].Longitude),
                            Lat			= DMathUtil.DegreesToRadians(nodes[nInds[i]].Latitude),
                            Position	= new Vector3(1.0f, 0.0f, 0.0f),
                            Color		= Color.Yellow,
                            Tex			= Vector4.Zero
                        });

                    lines.Add(new GeoVert {
                            Lon			= DMathUtil.DegreesToRadians(nodes[nInds[i+1]].Longitude),
                            Lat			= DMathUtil.DegreesToRadians(nodes[nInds[i+1]].Latitude),
                            Position	= new Vector3(1.0f, 0.0f, 0.0f),
                            Color		= Color.Yellow,
                            Tex			= Vector4.Zero
                        });

                    buildingVertices.Add(new DVector2(nodes[nInds[i]].Longitude, nodes[nInds[i]].Latitude));
                }
                buildingVertices.Add(new DVector2(nodes[way.Value.nodeRef[way.Value.nodeRef.Length - 1]].Longitude, nodes[way.Value.nodeRef[way.Value.nodeRef.Length - 1]].Latitude));

                /////////////////////////////////////////

                var mesh = new Mesh();
                mesh.Behavior.Quality	= false;
                mesh.Behavior.MinAngle	= 25;
                mesh.Behavior.Convex	= false;

                var ig = new InputGeometry();

                ig.AddPoint(buildingVertices[0].X, buildingVertices[0].Y);
                for (int v = 1; v < buildingVertices.Count; v++) {
                    ig.AddPoint(buildingVertices[v].X, buildingVertices[v].Y);
                    ig.AddSegment(v - 1, v);
                }
                ig.AddSegment(buildingVertices.Count - 1, 0);

                mesh.Triangulate(ig);

                int n = mesh.Vertices.Count;

                mesh.Renumber();

                buildings = new GeoVert[mesh.Triangles.Count*3];

                int ind = 0;
                foreach (var triangle in mesh.Triangles) {
                    buildings[ind++] = new GeoVert {
                        Lon = DMathUtil.DegreesToRadians(mesh.Vertices.ElementAt(triangle.P0).X),
                        Lat = DMathUtil.DegreesToRadians(mesh.Vertices.ElementAt(triangle.P0).Y),
                        Position = new Vector3(0.1f, 0.0f, 0.0f),
                        Color = Color.Green,
                        Tex = Vector4.Zero
                    };
                    buildings[ind++] = new GeoVert {
                        Lon = DMathUtil.DegreesToRadians(mesh.Vertices.ElementAt(triangle.P1).X),
                        Lat = DMathUtil.DegreesToRadians(mesh.Vertices.ElementAt(triangle.P1).Y),
                        Position = new Vector3(0.1f, 0.0f, 0.0f),
                        Color = Color.Green,
                        Tex = Vector4.Zero
                    };
                    buildings[ind++] = new GeoVert {
                        Lon = DMathUtil.DegreesToRadians(mesh.Vertices.ElementAt(triangle.P2).X),
                        Lat = DMathUtil.DegreesToRadians(mesh.Vertices.ElementAt(triangle.P2).Y),
                        Position = new Vector3(0.1f, 0.0f, 0.0f),
                        Color = Color.Green,
                        Tex = Vector4.Zero
                    };
                }

                /////////////////////////////////////////

                k++;
                if (k >= 1) break;
            }

            simpleBuildings		= simple.ToArray();
            contourBuildings	= lines.ToArray();

            contourBuildingsVB = new VertexBuffer(Game.GraphicsDevice, typeof (GeoVert), contourBuildings.Length);
            contourBuildingsVB.SetData(contourBuildings, 0, contourBuildings.Length);

            simpleBuildingsVB = new VertexBuffer(Game.GraphicsDevice, typeof(GeoVert), simpleBuildings.Length);
            simpleBuildingsVB.SetData(simpleBuildings, 0, simpleBuildings.Length);

            buildingsVB = new VertexBuffer(Game.GraphicsDevice, typeof(GeoVert), buildings.Length);
            buildingsVB.SetData(buildings, 0, buildings.Length);
        }
コード例 #7
0
ファイル: GlobeLayer.Dots.cs プロジェクト: temik911/audio
        void InitDots()
        {
            dotsBuf = new ConstBufferGeneric<DotsConstData>(Game.GraphicsDevice);
            dotsBuf.Data.Colors = new float[16*4];

            //var r = new Random();

            Dots = new GeoVert[505000];

            dotsVB = new VertexBuffer(Game.GraphicsDevice, typeof(GeoVert), Dots.Length);

            for (int v = 0; v < Dots.Length; v++) {
                var vert = new GeoVert {
                    Lon = 0,//DMathUtil.DegreesToRadians(30.301419 + 0.125 * r.NextDouble()),
                    Lat = 0,//DMathUtil.DegreesToRadians(59.942562 + 0.125 * r.NextDouble()),
                    Position	= Vector3.Zero,
                    Color		= Color.White,
                    Tex			= new Vector4(1, 0, 0, 0)
                };

                Dots[v] = vert;
            }

            //// Metro
            //DotsAddGeoObject(1, new DVector2(30.291136, 59.951796), Color.White, 0.05f); // Metro
            //DotsAddGeoObject(1, new DVector2(30.278251, 59.942602), Color.White, 0.05f); // Metro
            //DotsAddGeoObject(1, new DVector2(30.234627, 59.948470), Color.White, 0.05f); // Metro
            //
            //
            //// IO Dots
            //DotsAddGeoObject(2, new DVector2(30.286614, 59.949759), Color.White, 0.05f); // Tuchkov
            //DotsAddGeoObject(2, new DVector2(30.303522, 59.947314), Color.White, 0.05f); // Birj
            //DotsAddGeoObject(2, new DVector2(30.309391, 59.940275), Color.White, 0.05f); // Dvorc
            //DotsAddGeoObject(2, new DVector2(30.290841, 59.933460), Color.White, 0.05f); // Blago
            //
            //
            //// railroads
            //DotsAddGeoObject(3, new DVector2(30.298743, 59.906812), Color.Yellow, 0.05f); // balt
            //DotsAddGeoObject(3, new DVector2(30.356464, 59.956350), Color.Yellow, 0.05f); // fin
            //DotsAddGeoObject(3, new DVector2(30.329428, 59.919639), Color.Yellow, 0.05f); // viteb
            //DotsAddGeoObject(3, new DVector2(30.361930, 59.929369), Color.Yellow, 0.05f); // moscow
            //DotsAddGeoObject(3, new DVector2(30.440599, 59.932079), Color.Yellow, 0.05f); // ladoj

            //var balt0 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.298743), Lat = DMathUtil.DegreesToRadians(59.906812), Color = new Color(1.0f, 1.0f, 1.0f, 1.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //var balt1 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.288105), Lat = DMathUtil.DegreesToRadians(59.851217), Color = new Color(1.0f, 1.0f, 1.0f, 0.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //
            //
            //var mosc0 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.361930), Lat = DMathUtil.DegreesToRadians(59.929369), Color = new Color(1.0f, 1.0f, 1.0f, 1.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //var mosc1 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.365911), Lat = DMathUtil.DegreesToRadians(59.912719), Color = new Color(1.0f, 1.0f, 1.0f, 1.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //var mosc2 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.550232), Lat = DMathUtil.DegreesToRadians(59.781460), Color = new Color(1.0f, 1.0f, 1.0f, 0.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //
            //
            //var fin0 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.356464), Lat = DMathUtil.DegreesToRadians(59.956350), Color = new Color(1.0f, 1.0f, 1.0f, 1.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //var fin1 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.357671), Lat = DMathUtil.DegreesToRadians(59.967750), Color = new Color(1.0f, 1.0f, 1.0f, 1.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //var fin2 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.294199), Lat = DMathUtil.DegreesToRadians(60.052353), Color = new Color(1.0f, 1.0f, 1.0f, 0.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            ////var fin3 = new Vert { Lon = DMathUtil.DegreesToRadians(30.298743), Lat = DMathUtil.DegreesToRadians(59.906812), Color = new Color(1.0f, 1.0f, 1.0f, 0.0f), Position = Vector3.Zero, Tex = new Vector2(0.06f, 0.0f) };
            //
            //
            //var vit0 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.329428), Lat = DMathUtil.DegreesToRadians(59.919639), Color = new Color(1.0f, 1.0f, 1.0f, 1.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //var vit1 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.334539), Lat = DMathUtil.DegreesToRadians(59.913923), Color = new Color(1.0f, 1.0f, 1.0f, 1.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //var vit2 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.419769), Lat = DMathUtil.DegreesToRadians(59.742191), Color = new Color(1.0f, 1.0f, 1.0f, 0.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //
            //
            //var lad0 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.440599), Lat = DMathUtil.DegreesToRadians(59.932079), Color = new Color(1.0f, 1.0f, 1.0f, 1.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //var lad1 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.448480), Lat = DMathUtil.DegreesToRadians(59.936919), Color = new Color(1.0f, 1.0f, 1.0f, 1.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //var lad2 = new GeoVert { Lon = DMathUtil.DegreesToRadians(30.558472), Lat = DMathUtil.DegreesToRadians(59.929517), Color = new Color(1.0f, 1.0f, 1.0f, 0.0f), Position = Vector3.Zero, Tex = new Vector4(0.06f, 0.0f, 0, 0) };
            //
            //
            //simpleRailroadsVB = new VertexBuffer(Game.GraphicsDevice, typeof(GeoVert), 18);
            //
            //simpleRailroadsVB.SetData(new GeoVert[] { balt0, balt1, mosc0, mosc1, mosc1, mosc2, fin0, fin1, fin1, fin2, vit0, vit1, vit1, vit2, lad0, lad1, lad1, lad2 }, 0, 18);

            dotsBuf.Data.Colors[0] = 1.0f;
            dotsBuf.Data.Colors[1] = 1.0f;
            dotsBuf.Data.Colors[2] = 1.0f;
            dotsBuf.Data.Colors[3] = 1.0f;

            //dotsVB.SetData(Dots, 0, Dots.Length);

            socioClasses	= Game.Content.Load<Texture2D>("Urban/SocioClasses.tga");
            geoObjects		= Game.Content.Load<Texture2D>("Urban/geoObjects.tga");
        }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="contour"></param>
        void AddMunicipalDivision(string name, List <DVector2> contour)
        {
            if (municipalDivisions.ContainsKey(name))
            {
                return;
            }

            var mesh = new TriangleNet.Mesh();

            mesh.Behavior.Quality  = true;
            mesh.Behavior.MinAngle = 25;
            mesh.Behavior.Convex   = false;

            var ig = new InputGeometry();

            ig.AddPoint(contour[0].X, contour[0].Y);
            for (int v = 1; v < contour.Count; v++)
            {
                ig.AddPoint(contour[v].X, contour[v].Y);
                ig.AddSegment(v - 1, v);
            }
            ig.AddSegment(contour.Count - 1, 0);

            mesh.Triangulate(ig);

            int n = mesh.Vertices.Count;

            mesh.Renumber();

            // Vertices
            var moVerts = new GeoVert[n];
            int i       = 0;

            foreach (var pt in mesh.Vertices)
            {
                moVerts[i] = new GeoVert {
                    Lon      = pt.X * Math.PI / 180.0,
                    Lat      = pt.Y * Math.PI / 180.0,
                    Position = Vector3.Zero,
                    Tex      = Vector4.Zero,
                    Color    = Color.White
                };

                i++;
            }

            // Triangles
            var triangles = new int[3 * mesh.Triangles.Count];

            i = 0;
            foreach (var tri in mesh.Triangles)
            {
                triangles[i * 3 + 0] = tri.P0;
                triangles[i * 3 + 1] = tri.P1;
                triangles[i * 3 + 2] = tri.P2;
                i++;
            }


            // Contour vertices
            var contourVerts = new GeoVert[contour.Count * 2];

            contourVerts[1] = new GeoVert {
                Lon      = contour[0].X * Math.PI / 180.0,
                Lat      = contour[0].Y * Math.PI / 180.0,
                Position = Vector3.Zero,
                Tex      = Vector4.Zero,
                Color    = Color.Red
            };

            for (int j = 1; j < contour.Count; j++)
            {
                contourVerts[2 * j + 1] = new GeoVert {
                    Lon      = contour[j].X * Math.PI / 180.0,
                    Lat      = contour[j].Y * Math.PI / 180.0,
                    Position = Vector3.Zero,
                    Tex      = Vector4.Zero,
                    Color    = Color.Red
                };
                contourVerts[2 * j] = contourVerts[2 * (j - 1) + 1];
            }

            contourVerts[0] = contourVerts[contourVerts.Length - 1];


            // Create buffers
            var vb   = new VertexBuffer(Game.GraphicsDevice, typeof(GeoVert), moVerts.Length);
            var inds = new IndexBuffer(Game.GraphicsDevice, triangles.Length);
            var cont = new VertexBuffer(Game.GraphicsDevice, typeof(GeoVert), contourVerts.Length);

            vb.SetData(moVerts, 0, moVerts.Length);
            inds.SetData(triangles, 0, triangles.Length);
            cont.SetData(contourVerts, 0, contourVerts.Length);

            municipalDivisions.Add(name, new MD {
                Contour  = cont,
                Indeces  = inds,
                Vertices = vb,
                Value    = r.NextFloat(0.0f, 1.0f)
            });
        }
コード例 #9
0
ファイル: GlobeLayer.Tile.cs プロジェクト: temik911/audio
        void CalculateVertices(out GeoVert[] vertices, out int[] indeces, int density, double left, double right, double top, double bottom, int zoom)
        {
            int RowsCount		= density + 2;
            int ColumnsCount	= RowsCount;

            var el = Game.GetService<LayerService>().ElevationLayer;
            var ms = Game.GetService<LayerService>().MapLayer.CurrentMapSource;

            var verts = new List<GeoVert>();

            float step = 1.0f / (density + 1);

            double dStep = 1.0 / (double)(density + 1);

            for (int row = 0; row < RowsCount; row++) {
                for (int col = 0; col < ColumnsCount; col++) {

                    double xx = left * (1.0 - dStep * col) + right  * dStep * col;
                    double yy = top  * (1.0 - dStep * row) + bottom * dStep * row;

                    double lon, lat;
                    //GeoHelper.TileToWorldPos(xx, yy, 0, out lon, out lat);
                    var sc = ms.Projection.TileToWorldPos(xx, yy, 0);

                    float elev = 0.0f;
                    //if (zoom > 8) elev = el.GetElevation(sc.X, sc.Y) / 1000.0f;

                    lon = sc.X * Math.PI / 180.0;
                    lat = sc.Y * Math.PI / 180.0;

                    //SphericalToCartesian(lon, lat, Config.earthRadius, out x, out y, out z);

                    verts.Add(new GeoVert {
                            Position	= new Vector3(elev),
                            Tex			= new Vector4(step * col, step * row, 0, 0),
                            Lon			= lon,
                            Lat			= lat
                        });
                }

            }

            var tindexes = new List<int>();

            for (int row = 0; row < RowsCount - 1; row++) {
                for (int col = 0; col < ColumnsCount - 1; col++) {
                    tindexes.Add(col + row * ColumnsCount);
                    tindexes.Add(col + (row + 1) * ColumnsCount);
                    tindexes.Add(col + 1 + row * ColumnsCount);

                    tindexes.Add(col + 1 + row * ColumnsCount);
                    tindexes.Add(col + (row + 1) * ColumnsCount);
                    tindexes.Add(col + 1 + (row + 1) * ColumnsCount);
                }
            }

            vertices	= verts.ToArray();
            indeces		= tindexes.ToArray();
        }
コード例 #10
0
ファイル: GlobeLayer.Lines.cs プロジェクト: temik911/audio
        void SetupRoads(GeoVert[] geoVerts)
        {
            if (roadsVB == null || roadsVB.Capacity != geoVerts.Length) {
                if(roadsVB != null) roadsVB.Dispose();

                roadsVB = new VertexBuffer(Game.GraphicsDevice, typeof(GeoVert), geoVerts.Length);
            }

            roadsVB.SetData(geoVerts, 0, geoVerts.Length);
        }
コード例 #11
0
ファイル: GlobeLayer.Lines.cs プロジェクト: temik911/audio
        void InitAirLines()
        {
            if (!File.Exists("Airlines.txt")) return;

            airDirections = new List<AirDirection>();

            var sr = new StreamReader("Airlines.txt");

            var dir = new AirDirection();
            while (!sr.EndOfStream) {
                var line = sr.ReadLine();
                if(line.Length == 0) continue;

                var lines = line.Split(new char[] {':', '\'', ' ', ','}, StringSplitOptions.RemoveEmptyEntries);

                switch (lines[0]) {
                    case "id": {
                            dir.Id = int.Parse(lines[1]);
                            break;
                        }
                    case "type": {
                            dir.Type = int.Parse(lines[1]);
                            break;
                        }
                    case "name": {
                            dir.Name = lines[1];
                            break;
                        }
                    case "latitude": {
                            dir.Latitude = double.Parse(lines[1]);
                            break;
                        }
                    case "longitude": {
                            dir.Longitude = double.Parse(lines[1]);

                            airDirections.Add(dir);
                            dir = new AirDirection();
                            break;
                        }
                }
            }

            sr.Close();

            airLines	= new GeoVert[2 * airDirections.Count(x => x.Type == 1)];
            airLinesVB = new VertexBuffer(Game.GraphicsDevice, typeof(GeoVert), airLines.Length);

            var saintPetersburgPos = new DVector2(DMathUtil.DegreesToRadians(30.270424), DMathUtil.DegreesToRadians(59.800073));

            var saintVert = new GeoVert {
                    Lon			= saintPetersburgPos.X,
                    Lat			= saintPetersburgPos.Y,
                    Position	= Vector3.Zero,
                    Tex			= new Vector4(1.0f, 0.0f, 0, 0),
                    Color		= new Color(0.01f, 0.01f, 0.01f, 0.01f)
                };

            int i = 0;
            foreach(var airDir in airDirections.Where(x => x.Type == 1)) {
                airLines[2*i + 0] = saintVert;
                airLines[2*i + 1] = new GeoVert {
                        Lon			= DMathUtil.DegreesToRadians(airDir.Longitude),
                        Lat			= DMathUtil.DegreesToRadians(airDir.Latitude),
                        Position	= Vector3.Zero,
                        Tex			= new Vector4(10.0f, 0.0f, 0, 0),
                        Color		= new Color(0.8f, 0.8f, 0.8f, 0.8f)
                    };
                i++;
            }

            airLinesVB.SetData(airLines, 0, airLines.Length);
        }
コード例 #12
0
        void InitAirLines()
        {
            if (!File.Exists("Airlines.txt"))
            {
                return;
            }

            airDirections = new List <AirDirection>();

            var sr = new StreamReader("Airlines.txt");

            var dir = new AirDirection();

            while (!sr.EndOfStream)
            {
                var line = sr.ReadLine();
                if (line.Length == 0)
                {
                    continue;
                }

                var lines = line.Split(new char[] { ':', '\'', ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);

                switch (lines[0])
                {
                case "id": {
                    dir.Id = int.Parse(lines[1]);
                    break;
                }

                case "type": {
                    dir.Type = int.Parse(lines[1]);
                    break;
                }

                case "name": {
                    dir.Name = lines[1];
                    break;
                }

                case "latitude": {
                    dir.Latitude = double.Parse(lines[1]);
                    break;
                }

                case "longitude": {
                    dir.Longitude = double.Parse(lines[1]);

                    airDirections.Add(dir);
                    dir = new AirDirection();
                    break;
                }
                }
            }

            sr.Close();


            airLines   = new GeoVert[2 * airDirections.Count(x => x.Type == 1)];
            airLinesVB = new VertexBuffer(Game.GraphicsDevice, typeof(GeoVert), airLines.Length);

            var saintPetersburgPos = new DVector2(DMathUtil.DegreesToRadians(30.270424), DMathUtil.DegreesToRadians(59.800073));

            var saintVert = new GeoVert {
                Lon      = saintPetersburgPos.X,
                Lat      = saintPetersburgPos.Y,
                Position = Vector3.Zero,
                Tex      = new Vector4(1.0f, 0.0f, 0, 0),
                Color    = new Color(0.01f, 0.01f, 0.01f, 0.01f)
            };


            int i = 0;

            foreach (var airDir in airDirections.Where(x => x.Type == 1))
            {
                airLines[2 * i + 0] = saintVert;
                airLines[2 * i + 1] = new GeoVert {
                    Lon      = DMathUtil.DegreesToRadians(airDir.Longitude),
                    Lat      = DMathUtil.DegreesToRadians(airDir.Latitude),
                    Position = Vector3.Zero,
                    Tex      = new Vector4(10.0f, 0.0f, 0, 0),
                    Color    = new Color(0.8f, 0.8f, 0.8f, 0.8f)
                };
                i++;
            }

            airLinesVB.SetData(airLines, 0, airLines.Length);
        }
コード例 #13
0
        void InitBuildingsOSM()
        {
            var osm = Game.GetService <LayerService>().OpenStreetMapSource;

            List <GeoVert> lines  = new List <GeoVert>();
            List <GeoVert> simple = new List <GeoVert>();

            var nodes = osm.allNodes;
            int k     = 0;

            foreach (var way in osm.allWays)
            {
                if (!way.Value.isBuilding)
                {
                    continue;
                }

                var    centerMerc = way.Value.BBox.Center();
                float  width = (way.Value.BBox.Maximum - way.Value.BBox.Minimum).X * 10000.0f;
                float  length = (way.Value.BBox.Maximum - way.Value.BBox.Minimum).Y * 10000.0f;
                double lon, lat;
                GeoHelper.TileToWorldPos(centerMerc.X, centerMerc.Y, 0, out lon, out lat);

                simple.Add(new GeoVert {
                    Lon      = DMathUtil.DegreesToRadians(lon),
                    Lat      = DMathUtil.DegreesToRadians(lat),
                    Color    = Color.White,
                    Position = Vector3.Zero,
                    Tex      = new Vector4(width, length, 0, 0)
                });

                List <DVector2> buildingVertices = new List <DVector2>();
                for (int i = 0; i < way.Value.nodeRef.Length - 1; i++)
                {
                    var nInds = way.Value.nodeRef;

                    lines.Add(new GeoVert {
                        Lon      = DMathUtil.DegreesToRadians(nodes[nInds[i]].Longitude),
                        Lat      = DMathUtil.DegreesToRadians(nodes[nInds[i]].Latitude),
                        Position = new Vector3(1.0f, 0.0f, 0.0f),
                        Color    = Color.Yellow,
                        Tex      = Vector4.Zero
                    });

                    lines.Add(new GeoVert {
                        Lon      = DMathUtil.DegreesToRadians(nodes[nInds[i + 1]].Longitude),
                        Lat      = DMathUtil.DegreesToRadians(nodes[nInds[i + 1]].Latitude),
                        Position = new Vector3(1.0f, 0.0f, 0.0f),
                        Color    = Color.Yellow,
                        Tex      = Vector4.Zero
                    });

                    buildingVertices.Add(new DVector2(nodes[nInds[i]].Longitude, nodes[nInds[i]].Latitude));
                }
                buildingVertices.Add(new DVector2(nodes[way.Value.nodeRef[way.Value.nodeRef.Length - 1]].Longitude, nodes[way.Value.nodeRef[way.Value.nodeRef.Length - 1]].Latitude));

                /////////////////////////////////////////

                var mesh = new Mesh();
                mesh.Behavior.Quality  = false;
                mesh.Behavior.MinAngle = 25;
                mesh.Behavior.Convex   = false;

                var ig = new InputGeometry();

                ig.AddPoint(buildingVertices[0].X, buildingVertices[0].Y);
                for (int v = 1; v < buildingVertices.Count; v++)
                {
                    ig.AddPoint(buildingVertices[v].X, buildingVertices[v].Y);
                    ig.AddSegment(v - 1, v);
                }
                ig.AddSegment(buildingVertices.Count - 1, 0);

                mesh.Triangulate(ig);

                int n = mesh.Vertices.Count;

                mesh.Renumber();

                buildings = new GeoVert[mesh.Triangles.Count * 3];

                int ind = 0;
                foreach (var triangle in mesh.Triangles)
                {
                    buildings[ind++] = new GeoVert {
                        Lon      = DMathUtil.DegreesToRadians(mesh.Vertices.ElementAt(triangle.P0).X),
                        Lat      = DMathUtil.DegreesToRadians(mesh.Vertices.ElementAt(triangle.P0).Y),
                        Position = new Vector3(0.1f, 0.0f, 0.0f),
                        Color    = Color.Green,
                        Tex      = Vector4.Zero
                    };
                    buildings[ind++] = new GeoVert {
                        Lon      = DMathUtil.DegreesToRadians(mesh.Vertices.ElementAt(triangle.P1).X),
                        Lat      = DMathUtil.DegreesToRadians(mesh.Vertices.ElementAt(triangle.P1).Y),
                        Position = new Vector3(0.1f, 0.0f, 0.0f),
                        Color    = Color.Green,
                        Tex      = Vector4.Zero
                    };
                    buildings[ind++] = new GeoVert {
                        Lon      = DMathUtil.DegreesToRadians(mesh.Vertices.ElementAt(triangle.P2).X),
                        Lat      = DMathUtil.DegreesToRadians(mesh.Vertices.ElementAt(triangle.P2).Y),
                        Position = new Vector3(0.1f, 0.0f, 0.0f),
                        Color    = Color.Green,
                        Tex      = Vector4.Zero
                    };
                }

                /////////////////////////////////////////


                k++;
                if (k >= 1)
                {
                    break;
                }
            }

            simpleBuildings  = simple.ToArray();
            contourBuildings = lines.ToArray();

            contourBuildingsVB = new VertexBuffer(Game.GraphicsDevice, typeof(GeoVert), contourBuildings.Length);
            contourBuildingsVB.SetData(contourBuildings, 0, contourBuildings.Length);

            simpleBuildingsVB = new VertexBuffer(Game.GraphicsDevice, typeof(GeoVert), simpleBuildings.Length);
            simpleBuildingsVB.SetData(simpleBuildings, 0, simpleBuildings.Length);


            buildingsVB = new VertexBuffer(Game.GraphicsDevice, typeof(GeoVert), buildings.Length);
            buildingsVB.SetData(buildings, 0, buildings.Length);
        }
コード例 #14
0
        void CreateSphere(int Stacks, int Slices)
        {
            //calculates the resulting number of vertices and indices
            int nVertices = (Stacks + 1) * (Slices + 1);
            int dwIndices = (3 * Stacks * (Slices + 1)) * 2;

            int[]     indices  = new int[dwIndices];
            GeoVert[] vertices = new GeoVert[nVertices];

            double stackAngle = Math.PI / Stacks;
            double sliceAngle = (Math.PI * 2.0) / Slices;

            int wVertexIndex = 0;
            //Generate the group of Stacks for the sphere
            int vertcount  = 0;
            int indexcount = 0;

            for (int stack = 0; stack < (Stacks + 1); stack++)
            {
                double phi = stack * stackAngle - Math.PI / 2.0;

                //Generate the group of segments for the current Stack
                for (int slice = 0; slice < (Slices + 1); slice++)
                {
                    double lambda = slice * sliceAngle;

                    vertices[vertcount].Lon      = lambda + Math.PI;
                    vertices[vertcount].Lat      = phi;
                    vertices[vertcount].Position = new Vector3();
                    vertices[vertcount].Tex      = new Vector4((float)slice / (float)Slices, 1.0f - (float)stack / (float)Stacks, 0, 0);
                    vertices[vertcount].Color    = Color.White;

                    //vertices[vertcount].TextureCoordinate = new Vector2((float)slice / (float)Slices, (float)stack / (float)Stacks);
                    vertcount++;
                    if (stack != (Stacks - 1))
                    {
                        indices[indexcount] = wVertexIndex;
                        indexcount++;
                        indices[indexcount] = wVertexIndex + 1;
                        indexcount++;
                        indices[indexcount] = wVertexIndex + (Slices + 1);
                        indexcount++;
                        indices[indexcount] = wVertexIndex;
                        indexcount++;
                        indices[indexcount] = wVertexIndex + (Slices + 1);
                        indexcount++;
                        indices[indexcount] = wVertexIndex + (Slices);
                        indexcount++;
                        wVertexIndex++;
                    }
                }
            }

            if (gridVertexBuffer != null)
            {
                gridVertexBuffer.Dispose();
            }
            if (gridIndexBuffer != null)
            {
                gridIndexBuffer.Dispose();
            }
            if (gridTex == null)
            {
                gridTex = Game.Content.Load <Texture2D>("NE2_50M_SR_W_4096.jpg");
            }

            gridVertexBuffer = new VertexBuffer(Game.GraphicsDevice, typeof(GeoVert), vertices.Length);
            gridIndexBuffer  = new IndexBuffer(Game.GraphicsDevice, indices.Length);

            gridVertexBuffer.SetData(vertices, 0, vertices.Length);
            gridIndexBuffer.SetData(indices, 0, indices.Length);

            return;
        }