public WayPoint getNextWpt(WayPoint pos) { float dist=pos.getDistance(ruta[currWptID]); if (dist <= lastdistance) lastdistance = dist; else if (dist > lastdistance && lastdistance < WptRange) { lastdistance = float.PositiveInfinity; if (currWptID < ruta.Count - 1) currWptID++; else currWptID = 0; } return ruta[currWptID]; }
public WayPoint getNextWpt(WayPoint pos) { float dist = pos.getDistance(ruta[currWptID]); if (dist <= lastdistance) { lastdistance = dist; } else if (dist > lastdistance && lastdistance < WptRange) { lastdistance = float.PositiveInfinity; if (currWptID < ruta.Count - 1) { currWptID++; } else { currWptID = 0; } } return(ruta[currWptID]); }
public float getDistance(WayPoint b) { return(WayPoint.getDistance(this, b)); }
protected override void OnPaint(PaintEventArgs e) { try { Bitmap bmp = new Bitmap(Width, Height); Graphics g = Graphics.FromImage(bmp); Bitmap home_icon = global::UAVConsole.Properties.Resources.ICO_dossier_home_ico_64x64; Point casa, avion, destino; home_icon.MakeTransparent(); map.OnPaint(g, Width, Height); PintarHistorico(g); if (!double.IsNaN(home.Latitude) && !double.IsNaN(home.Longitude)) { casa = new Point(); casa.X = (int)map.getdX(home) + Width / 2; casa.Y = (int)map.getdY(home) + Height / 2; } else { casa = Point.Empty; } if (plane != null && !double.IsNaN(plane.Latitude) && !double.IsNaN(plane.Longitude) && (plane.Latitude != 0 || plane.Longitude != 0)) { avion = new Point(); avion.X = (int)map.getdX(plane) + Width / 2; avion.Y = (int)map.getdY(plane) + Height / 2; } else { avion = Point.Empty; } if (target != null && !double.IsNaN(target.Latitude) && !double.IsNaN(target.Longitude) && (target.Latitude != 0 || target.Longitude != 0)) { destino = new Point(); destino.X = (int)map.getdX(target) + Width / 2; destino.Y = (int)map.getdY(target) + Height / 2; } else { destino = Point.Empty; } PintarOtherPlanes(g); PintarRuta(g); PintarSoftWpt(g); try { if (!casa.IsEmpty) { g.DrawImage(home_icon, casa.X - 32 / 2, casa.Y - 32 / 2, 32, 32); } } catch (Exception) { } if (!avion.IsEmpty) { DrawHome(g, avion, casa); if (!float.IsNaN(rumboHold)) { DrawRumboHold(g, avion, rumboHold); } else { DrawTarget(g, avion, destino); } } else if (!destino.IsEmpty) { DrawTarget(g, Point.Empty, destino); } if (!avion.IsEmpty) { Font mifont = new Font(Font.SystemFontName, 12.0f); String cad1; if (esta_dentro) { cad1 = "Cursor Lon: " + map.GetLongitude(x_curr - Width / 2).ToString("0.000000") + " Lat: " + map.GetLatitude(y_curr - Height / 2).ToString("0.000000") + " "; } else { cad1 = "Plane Lon: " + plane.Longitude.ToString("0.000000") + " Lat: " + plane.Latitude.ToString("0.000000") + " "; } String cad2 = "Dist: " + home.getDistance(plane).ToString("0.000") + "Km."; SizeF size1 = g.MeasureString(cad1, mifont); SizeF size2 = g.MeasureString(cad2, mifont); if (size1.Width + size2.Width > this.Width) { g.FillRectangle(Brushes.Yellow, 0, bmp.Height - 2 * mifont.Height, Math.Max(size1.Width, size2.Width), 2 * mifont.Height); g.DrawString(cad1, mifont, Brushes.Red, 0.0f, bmp.Height - mifont.Height); g.DrawString(cad2, mifont, Brushes.Red, 0.0f, bmp.Height - 2 * mifont.Height); } else { g.FillRectangle(Brushes.Yellow, 0, bmp.Height - mifont.Height, size1.Width, mifont.Height); g.DrawString(cad1, mifont, Brushes.Red, 0.0f, bmp.Height - mifont.Height); g.FillRectangle(Brushes.Yellow, this.Width - size2.Width, bmp.Height - mifont.Height, size2.Width, mifont.Height); g.DrawString(cad2, mifont, Brushes.Red, this.Width - size2.Width, bmp.Height - mifont.Height); } } else if (esta_dentro) { Font mifont = new Font(Font.SystemFontName, 12.0f); String cad1 = "Cursor Lon: " + map.GetLongitude(x_curr - Width / 2).ToString("0.000000") + " Lat: " + map.GetLatitude(y_curr - Height / 2).ToString("0.000000") + " "; SizeF size1 = g.MeasureString(cad1, mifont); g.FillRectangle(Brushes.Yellow, 0, bmp.Height - mifont.Height, size1.Width, mifont.Height); g.DrawString(cad1, mifont, Brushes.Red, 0.0f, bmp.Height - mifont.Height); } if (ruta.Count > 0 || mensaje != null) { Font mifont = new Font(Font.SystemFontName, 12.0f); String cad3 = ""; if (mensaje != null) { cad3 += mensaje; } if (ruta.Count > 0) { if (mensaje != null) { cad3 += " "; } cad3 += "Ruta: " + rutaKM.ToString("0.000") + "Km."; } SizeF size3 = g.MeasureString(cad3, mifont); g.FillRectangle(Brushes.Yellow, this.Width - size3.Width, this.Height - size3.Height, size3.Width, size3.Height); g.DrawString(cad3, mifont, Brushes.Red, this.Width - size3.Width, this.Height - size3.Height); } g.Dispose(); e.Graphics.DrawImage(bmp, 0, 0); } catch (Exception) { } }