Exemplo n.º 1
0
        public bool LocationToView(Location location, out PointF point)
        {
            // Move location to 3D earth
            var pos3d = new Vector4d (location.Position, 1);

            // Camera model
            var m = Matrix4d.Mult (modelViewMatrix, projectionMatrix);

            // Project into homogeneous 2D point
            var pos2h = Vector4d.Transform (pos3d, m);

            // Perform the perspective divide
            var pos2 = pos2h / pos2h.W;

            // Ignore points behind us
            if (pos2h.W < 0) {
                point = PointF.Empty;
                return false;
            }

            //			Console.WriteLine ("{0} = {1}", "W", pos2h.W);

            // Stretch into our view
            var fr = videoCameraView.Frame;
            point = new PointF (
                fr.X + (float)((pos2.X + 1) * 0.5) * fr.Width,
                fr.Y + (float)((-pos2.Y + 1) * 0.5) * fr.Height
            );
            return true;
        }
Exemplo n.º 2
0
		public void Start ()
		{
			if (CLLocationManager.LocationServicesEnabled) {
				lman = new CLLocationManager {
					DesiredAccuracy = CLLocation.AccuracyBest,
				};

				lman.RequestWhenInUseAuthorization ();

				lman.LocationsUpdated += (sender, e) => {
					var loc = e.Locations [0];
					Timestamp = loc.Timestamp;
					Location = new Location (loc.Coordinate.Latitude, loc.Coordinate.Longitude, loc.Altitude);
//					Console.WriteLine (Location);
					HorizontalAccuracy = loc.HorizontalAccuracy;
					VerticalAccuracy = loc.VerticalAccuracy;
					LocationReceived (this, EventArgs.Empty);
				};

				lman.UpdatedHeading += (sender, e) => {
					Heading = e.NewHeading.TrueHeading;
//					Console.WriteLine ("Heading: {0}", Heading);
				};

				lman.StartUpdatingLocation ();
				lman.StartUpdatingHeading ();
			}
		}
Exemplo n.º 3
0
 public void AddAnnotation(string title, Location location)
 {
     var a = new Annotation {
         Location = location,
     };
     a.Text = title;
     annos.Add (a);
     if (IsViewLoaded) {
         View.AddSubview (a);
     }
 }
Exemplo n.º 4
0
        public static Matrix4d GetModelView(Location location, Matrix4d orientation)
        {
            // 1. Calculate position in 3D cartesian world
            // 2. Find "up"
            // 3. Orient to face the north pole
            // 4. Apply the device orientation

            //
            // 1. Calculate position in 3D cartesian world
            //
            var pos = location.Position;

            //
            // 2. Find "up"
            //
            var up = location.OffsetAltitude (100).Position - pos;
            up.Normalize ();

            //
            // 3. Orient to face the north pole
            //
            var northPos = new Location (location.Latitude + 0.1, location.Longitude, location.Altitude).Position;

            var northZAxis = (pos - northPos);
            northZAxis.Normalize ();

            var northYAxis = up;
            var northXAxis = Vector3d.Cross (northYAxis, northZAxis);

            northXAxis.Normalize ();
            northZAxis = Vector3d.Cross (northXAxis, northYAxis);
            northZAxis.Normalize ();

            northYAxis = Vector3d.Cross (northZAxis, northXAxis);
            northYAxis.Normalize ();

            var lookNorthI = new Matrix4d (
                new Vector4d(northXAxis),
                new Vector4d(northYAxis),
                new Vector4d(northZAxis),
                Vector4d.UnitW);

            //			var lookTest = Matrix4d.LookAt (pos, new Location (47.656680, -122.365480).Position, up);

            //
            // 4. Apply the device orientation
            //
            var newOrient = new Matrix4d (
                -orientation.Column1,
                orientation.Column2,
                -orientation.Column0,
                Vector4d.UnitW);

            var newOrientI = newOrient;
            newOrientI.Transpose ();

            var modelViewI = (newOrientI * lookNorthI);
            modelViewI.Row3 = new Vector4d (pos.X, pos.Y, pos.Z, 1);
            var modelView = modelViewI;
            try {
                modelView.Invert ();
                return modelView;
            }
            catch (InvalidOperationException) {
                var lookNorth = lookNorthI;
                lookNorth.Invert ();
                return lookNorth;
            }
        }