示例#1
0
        public BlobCollection(List <Blob> blobs, ISector sector)
        {
            borderWay      = new Way();
            borderWay.id   = -10;
            borderWay.refs = new List <long>()
            {
                -900, -901, -902, -903, -900
            };                                                                  // arbitrary for now, but ccw for land
            nodes.Add(-900, new Vector2d(0, 0));
            nodes.Add(-901, new Vector2d(0, 1));
            nodes.Add(-902, new Vector2d(1, 1));
            nodes.Add(-903, new Vector2d(1, 0));

            this.blobs         = blobs;
            this.sector        = sector;
            this.gridPointInfo = OSMMetaFinal.GetGridPointInfo(sector);
            // initialize
            ISector rootSector = sector.GetRoot();

            foreach (var blob in blobs)
            {
                if (blob.type != "OSMData")
                {
                    continue;
                }
                // build node data
                for (int i = 0; i < blob.pBlock.primitivegroup.Count; i++)
                {
                    var pGroup = blob.pBlock.primitivegroup[i];
                    for (int j = 0; j < pGroup.dense.Count; j++)
                    {
                        var d = pGroup.dense[j];
                        for (int k = 0; k < d.id.Count; k++)
                        {
                            double longitude = .000000001 * (blob.pBlock.lon_offset + (blob.pBlock.granularity * d.lon[k]));
                            double latitude  = .000000001 * (blob.pBlock.lat_offset + (blob.pBlock.granularity * d.lat[k]));
                            nodes[d.id[k]] = sector.ProjectToLocalCoordinates(new LongLat(longitude * Math.PI / 180, latitude * Math.PI / 180).ToSphereVector());
                        }
                    }
                }
            }
        }
示例#2
0
        private SectorBounds GetSectorBounds(GraphicsDevice graphicsDevice, ISector rootSector)
        {
            // apparently we don't want to call this after changing our render target
            double           w         = graphicsDevice.Viewport.Width;
            double           h         = graphicsDevice.Viewport.Height;
            var              leftArc   = camera.GetArc(graphicsDevice, 0, h, 0, 0);
            var              rightArc  = camera.GetArc(graphicsDevice, w, 0, w, h);
            var              topArc    = camera.GetArc(graphicsDevice, 0, 0, w, 0);
            var              bottomArc = camera.GetArc(graphicsDevice, w, h, 0, h);
            List <SphereArc> arcs      = new List <SphereArc>();

            if (leftArc != null)
            {
                arcs.Add(leftArc);
            }
            if (topArc != null)
            {
                arcs.Add(topArc);
            }
            if (rightArc != null)
            {
                arcs.Add(rightArc);
            }
            if (bottomArc != null)
            {
                arcs.Add(bottomArc);
            }
            Circle3 visible = camera.GetUnitSphereVisibleCircle(graphicsDevice);
            double  minX, maxX, minY, maxY;

            if (arcs.Count > 0)
            {
                int cnt = arcs.Count;
                // try and construct the arc segments that connect our disconnected arcs if they are
                for (int i = 0; i < cnt; i++)
                {
                    SphereArc arc1   = arcs[i];
                    SphereArc arc2   = arcs[(i + 1) % cnt];
                    Vector3d  close1 = arc1.stop;
                    Vector3d  close2 = arc2.start;
                    if ((close1 - close2).Length() > 0.01)
                    {
                        Vector3d halfway = (close1 + close2).Normalized();
                        if (close1.Cross(halfway).Dot(camera.GetPosition(graphicsDevice)) > 0)
                        {
                            halfway = -halfway;
                        }
                        arcs.Add(new SphereArc(visible, close1, halfway, true));
                        arcs.Add(new SphereArc(visible, halfway, close2, true));
                    }
                }
                minX = arcs.Min(x => x.Min(y => rootSector.ProjectToLocalCoordinates(y).X));
                maxX = arcs.Max(x => x.Max(y => rootSector.ProjectToLocalCoordinates(y).X));
                minY = arcs.Min(x => x.Min(y => rootSector.ProjectToLocalCoordinates(y).Y));
                maxY = arcs.Max(x => x.Max(y => rootSector.ProjectToLocalCoordinates(y).Y));
            }
            else
            {
                minX = visible.Min(x => rootSector.ProjectToLocalCoordinates(x).X);
                maxX = visible.Max(x => rootSector.ProjectToLocalCoordinates(x).X);
                minY = visible.Min(x => rootSector.ProjectToLocalCoordinates(x).Y);
                maxY = visible.Max(x => rootSector.ProjectToLocalCoordinates(x).Y);
            }
            if (rootSector is MercatorSector)
            {
                if (camera.IsUnitSpherePointVisible(graphicsDevice, new Vector3d(0, 0, 1)))
                {
                    minY = 0;
                    minX = 0;
                    maxX = 1;
                }
                if (camera.IsUnitSpherePointVisible(graphicsDevice, new Vector3d(0, 0, -1)))
                {
                    maxY = 1;
                    minX = 0;
                    maxX = 1;
                }
            }
            return(new SectorBounds(Math.Max(minX, 0), Math.Min(maxX, 1), Math.Max(minY, 0), Math.Min(maxY, 1)));
        }