void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args) { SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(); // From orientation quaternion, get view center in horizontal coordinates Matrix4x4 matrix = Matrix4x4.CreateFromQuaternion(orientation); HorizontalCoordinate viewCenter = HorizontalCoordinate.FromRotationMatrix(matrix); coordinateProjection.SetViewCenter(viewCenter); // Rotate for Tilt canvas.RotateDegrees((float)-viewCenter.Tilt, info.Width / 2, info.Height / 2); // Draw aximuth lines for (double azimuth = 0; azimuth < 360; azimuth += 15) { for (double altitude = -90; altitude < 90; altitude += 15) { HorizontalCoordinate coord1 = new HorizontalCoordinate(azimuth, altitude); HorizontalCoordinate coord2 = new HorizontalCoordinate(azimuth, altitude + 15); SKPoint point1 = CalculateScreenPoint(coord1, info.Width, info.Height); SKPoint point2 = CalculateScreenPoint(coord2, info.Width, info.Height); if (!double.IsNaN(point1.X) && !double.IsNaN(point2.X)) { canvas.DrawLine(point1, point2, linePaint); } } } // Draw altitude lines for (double altitude = -75; altitude < 90; altitude += 15) { for (double azimuth = 0; azimuth < 360; azimuth += 15) { HorizontalCoordinate coord1 = new HorizontalCoordinate(azimuth, altitude); HorizontalCoordinate coord2 = new HorizontalCoordinate(azimuth + 15, altitude); SKPoint point1 = CalculateScreenPoint(coord1, info.Width, info.Height); SKPoint point2 = CalculateScreenPoint(coord2, info.Width, info.Height); if (!double.IsNaN(point1.X) && !double.IsNaN(point2.X)) { canvas.DrawLine(point1, point2, linePaint); } } } // Draw text for altitude angles for (double altitude = -75; altitude < 90; altitude += 15) { HorizontalCoordinate coord = new HorizontalCoordinate(viewCenter.Azimuth, altitude); SKPoint point = CalculateScreenPoint(coord, info.Width, info.Height); textPaint.TextAlign = SKTextAlign.Center; canvas.DrawText(altitude == 0 ? "Equator" : (altitude.ToString() + '\xB0'), point, textPaint); } // Draw text for azimuth compass points for (double azimuth = 0; azimuth < 360; azimuth += 45) { double altitude = Math.Min(80, Math.Max(-80, viewCenter.Altitude)); HorizontalCoordinate coord = new HorizontalCoordinate(azimuth, altitude); SKPoint point = CalculateScreenPoint(coord, info.Width, info.Height); textPaint.TextAlign = SKTextAlign.Left; canvas.DrawText(compass[(int)(azimuth / 45)], point, textPaint); } }