Example #1
0
        Vector3d GetLonLatInMeters(double height = 0)
        {
            if (height == 0)
            {
                height = CurrentBody.Radius.X * 1.001;
            }
            string s   = LonLatBox.Text.Trim();
            double lat = 0;
            double lon = 0;

            if (s.Contains(','))
            {
                string[] coords = LonLatBox.Text.Split(',');
                lon = double.Parse(coords[0]);
                lat = double.Parse(coords[1]);
            }
            else
            if (s.Contains(' '))
            {
                string[] coords = LonLatBox.Text.Split(' ');
                lon = double.Parse(coords[0]);
                lat = double.Parse(coords[1]);
            }

            Vector3d d = MGISTools.LonLatMercatorToPosition(lon, lat, height) + CurrentBody.Position;

            return(d);
        }
        // coordinates are entered lat lon, so will be flipped
        bool DecodeLonLat(string sText, out Vector3d v)
        {
            Vector3d vt = Vector3d.Zero;

            string[] parts = sText.Split(',');
            if (parts.Length == 2)
            {
                MAstroBody ab     = MPlanetHandler.CurrentNear;
                double     radius = 0;
                if (ab != null)
                {
                    radius = ab.Radius.X;
                }
                if (GetNumbers(parts, out vt) == true)
                {
                    //y = lon, x = lat
                    Vector3d vr = MGISTools.LonLatMercatorToPosition(vt.Y, vt.X, radius + 1000) + ab.Position;
                    v = vr;
                    return(true);
                }
            }

            v = vt;
            return(false);
        }
Example #3
0
        //
        public MTerrainBoundary GetTileBoundaryLonLat(int TileX, int TileY, int Zoom)
        {
            MTerrainBoundary tb = new MTerrainBoundary();

            tb.LonLatTL = PixelXYToLonLat(TileX * 256, TileY * 256, Zoom);
            tb.LonLatTR = PixelXYToLonLat((TileX + 1) * 256, TileY * 256, Zoom);
            tb.LonLatBL = PixelXYToLonLat((TileX) * 256, (TileY + 1) * 256, Zoom);
            tb.LonLatBR = PixelXYToLonLat((TileX + 1) * 256, (TileY + 1) * 256, Zoom);

            tb.TL = MGISTools.LonLatMercatorToPosition(tb.LonLatTL.X, tb.LonLatTL.Y, Radius.X) + Position;
            tb.TR = MGISTools.LonLatMercatorToPosition(tb.LonLatTR.X, tb.LonLatTR.Y, Radius.X) + Position;
            tb.BL = MGISTools.LonLatMercatorToPosition(tb.LonLatBL.X, tb.LonLatBL.Y, Radius.X) + Position;
            tb.BR = MGISTools.LonLatMercatorToPosition(tb.LonLatBR.X, tb.LonLatBR.Y, Radius.X) + Position;

            return(tb);
        }
Example #4
0
        Vector3d MapTo3D(int x, int y)
        {
            //Vector3d destpos = CurrentBody.Position + CurrentBody.Radius;
            Vector3d v = MGISTools.PositionFromMap(CurrentBody, new Vector2d(x, y), new Vector2d(MapBox.Size.Width - 1, MapBox.Size.Height - 1));

            double dist = (double)DistanceVal.Value;

            if (dist == 0)
            {
                dist = 0.001;
            }

            double   d = dist / 100.0 + 2; //+2m or we are placed inside the body on the edge.);
            Vector3d P = MGISTools.PositionOnBodyFromMapPoint(v.X, v.Y, CurrentBody.Radius.X, d);

            return(CurrentBody.Position + P);
        }
Example #5
0
        void AddPOI(string sName, string sclass, double lon, double lat, MAstroBody _body)
        {
            MPOI poi = new MPOI();

            poi.sClass   = sclass;
            poi.Position = MGISTools.LonLatMercatorToPosition(lon, lat, _body.Radius.X)
                           + _body.Position;
            poi.LonLat = new Vector3d(lon, lat, 0);
            poi.Name   = sName;
            if (sclass.Equals("suburb"))
            {
                Suburbs.Add(poi);
            }
            if (sclass.Equals("minor"))
            {
                PointsOfInterest.Add(poi);
            }
            if (sclass.Equals("tertiary"))
            {
                PointsOfInterest.Add(poi);
            }
            if (sclass.Equals("major"))
            {
                PointsOfInterest.Add(poi);
            }
            if (sclass.Equals("primary"))
            {
                PointsOfInterest.Add(poi);
            }
            if (sclass.Equals("highway"))
            {
                PointsOfInterest.Add(poi);
            }
            if (sclass.Equals("stream"))
            {
                PointsOfInterest.Add(poi);
            }
        }
Example #6
0
        void InitializeTile(string TileNum, int tx, int ty, int zoom)
        {
            TileCount++;
            Console.WriteLine("Tile:" + TileCount + " Initialize " + tx + "," + ty);

            MTerrainTile tile = new MTerrainTile(tx, ty, ZoomLevel, CurrentBody.Radius.X);

            tile.SetShader(TerrainShader);
            Tiles.Add(TileNum, tile);
            MScene.Background.Add(Tiles[TileNum]);
            MTerrainBoundary tb             = CurrentBody.GetTileBoundaryLonLat(tx, ty, ZoomLevel);
            double           metersperpixel = CurrentBody.GroundResolution(tb.LonLatTL.Y, ZoomLevel);

            //Tiles[TileNum].transform.Scale = new Vector3d(256*metersperpixel, 1, 256 *metersperpixel);
            //Vector3d ll = CurrentBody.TileToLonLat(tx, ty, zoom);
            Vector3d ll = tb.LonLatTL;
            //Vector3d pos = CurrentBody.LonLatToUniPosition(ll.X, ll.Y, 0);
            Vector3d pos = MGISTools.LonLatMercatorToPosition(ll.X, ll.Y, CurrentBody.Radius.X) + CurrentBody.Position;

            Tiles[TileNum].transform.Position = pos;
            Tiles[TileNum].SetBoundary(tb);
            Tiles[TileNum].Setup(CurrentBody);
        }
Example #7
0
        public void UpdateAvatarLonLat(Vector3d LonLat)
        {
            // Console.WriteLine(TileX + " : " + DistanceFromAvatar);

            if ((IsSetup == true) && (DistanceFromAvatar < PHYSICS_ACTIVE_DISTANCE) && (_physics == null))
            {
                DoSetupPhysics = true;
            }

            if (Settings.PointsOfInterest == true)
            {
                double Distance = 9999999999999999;
                foreach (MPOI p in PointsOfInterest)
                {
                    //double d = Vector3d.Distance(LonLat, p.LonLat);
                    double d = MGISTools.GetDistance(LonLat.Y, LonLat.X, p.LonLat.Y, p.LonLat.X);
                    if (d < Distance)
                    {
                        ClosestPOI = p;
                        Distance   = d;
                    }
                }

                Distance = 9999999999999999;
                foreach (MPOI p in Suburbs)
                {
                    //double d = Vector3d.Distance(LonLat, p.LonLat);
                    double d = MGISTools.GetDistance(LonLat.Y, LonLat.X, p.LonLat.Y, p.LonLat.X);
                    if (d < Distance)
                    {
                        ClosestSuburb = p;
                        Distance      = d;
                    }
                }
            }
        }