Exemplo n.º 1
0
        private void SetYaw(double yaw)
        {
            if (Grid_YawStaff.ActualWidth == 0)
            {
                return;
            }
            yaw = yaw % 360;
            if (yaw > 180)
            {
                yaw = yaw - 360;
            }
            if (yaw < -180)
            {
                yaw = yaw + 360;
            }
            double left = Grid_YawStaff.ActualWidth / 2 - 15;

            if (yaw > 90 || yaw < -90)
            {
                TextBlock_YawStaff_Left.Text   = "E";
                TextBlock_YawStaff_Middle.Text = "S";
                TextBlock_YawStaff_Right.Text  = "W";
                if (yaw != 180 && yaw != -180)
                {
                    if (yaw > 0)
                    {
                        left = Grid_YawStaff.ActualWidth / 2 - 30 - (180 - yaw) / 90 * Canvas_YawStaff_Right.ActualWidth;
                    }
                    else if (yaw < 0)
                    {
                        left = Grid_YawStaff.ActualWidth / 2 + (180 + yaw) / 90 * Canvas_YawStaff_Right.ActualWidth;
                    }
                }
            }
            else
            {
                TextBlock_YawStaff_Left.Text   = "W";
                TextBlock_YawStaff_Middle.Text = "N";
                TextBlock_YawStaff_Right.Text  = "E";
                if (yaw == 90)
                {
                    left = Grid_YawStaff.ActualWidth - 30;
                }
                else if (yaw == -90)
                {
                    left = 0;
                }
                else if (yaw > 0)
                {
                    left = Grid_YawStaff.ActualWidth / 2 + yaw / 90 * Canvas_YawStaff_Right.ActualWidth;
                }
                else if (yaw < 0)
                {
                    left = Grid_YawStaff.ActualWidth / 2 - 30 + yaw / 90 * Canvas_YawStaff_Right.ActualWidth;
                }
            }
            Canvas_YawStaff_Value.Margin = new Thickness(left, 0, 0, 0);
            Text_YawStaff_Value.Text     = Math.Abs(yaw % 90).ToString("0.##");
            Text_YawStaff_Value.ToolTip  = "原始值:" + YawAngle.ToString("0.###");
        }
Exemplo n.º 2
0
        private void SetYaw(double yaw)
        {
            if (Grid_YawStaff.ActualWidth == 0)
            {
                return;
            }

            text_yaw_value.Text    = Math.Abs(yaw).ToString("0.");
            text_yaw_value.ToolTip = "原始值:" + YawAngle.ToString("0.###");
        }
Exemplo n.º 3
0
Arquivo: PFD.cs Projeto: l0nley/tello
        private void DrawYaw(Graphics g, RectangleF screenRect)
        {
            var middleX     = screenRect.Left + screenRect.Width / 2.0f;
            var diameter    = screenRect.Width / 2.0f;
            var normalPen   = new Pen(ScaleNormalColor);
            var normalBrush = new SolidBrush(ScaleNormalColor);
            var circleBrush = new SolidBrush(Color.FromArgb(100, 100, 100));
            var ellipseCX   = middleX;
            var ellipseCY   = screenRect.Bottom - diameter / 2.0f + 30;

            g.FillEllipse(circleBrush, ellipseCX - diameter / 2.0f, ellipseCY, diameter, diameter);
            g.DrawEllipse(normalPen, ellipseCX - diameter / 2.0f, ellipseCY, diameter, diameter);
            var size = g.MeasureString("▽", ScaleFontBig);

            g.DrawString("▽", ScaleFontBig, normalBrush, middleX - size.Width / 2.0f + 1, screenRect.Bottom - diameter / 2.0f - size.Height / 2.0f + 30);
            var value             = YawAngle + 90;
            var step              = (float)(YawStep * Math.PI / 180.0f) / 2.0f;
            var major             = true;
            var originalTransform = g.Transform.Clone();

            for (float alpha = -(float)Math.PI; alpha <= Math.PI; alpha += step)
            {
                var tx       = (float)(ellipseCX - Math.Cos(alpha) * diameter / 2.0f);
                var ty       = (float)(ellipseCY + diameter / 2.0f - Math.Sin(alpha) * diameter / 2.0f);
                var smallRad = major ? 7 : 4;
                var ttx      = (float)(smallRad * Math.Cos(alpha));
                var tty      = (float)(smallRad * Math.Sin(alpha));
                g.TranslateTransform(ellipseCX, ellipseCY + diameter / 2.0f);
                g.RotateTransform(value);
                g.TranslateTransform(-ellipseCX, -(ellipseCY + diameter / 2.0f));
                g.DrawLine(normalPen, tx, ty, tx + ttx, ty + tty);
                if (major)
                {
                    var degs = alpha * 180.0f / (float)Math.PI;
                    g.TranslateTransform(tx, ty);
                    g.RotateTransform(degs - 90);
                    var msg = (-degs).ToString(YawFormat);
                    var ss  = g.MeasureString(msg, ScaleFontSmall);
                    g.DrawString(msg, ScaleFontSmall, normalBrush, -ss.Width / 2.0f, ss.Height / 2.0f);
                }
                g.Transform = originalTransform;
                major       = !major;
            }
            g.Transform = originalTransform;
            var p = new PointF(middleX - 40, screenRect.Bottom - 30);

            g.FillRectangle(Brushes.Black, p.X, p.Y, 80, 60);
            g.DrawRectangle(normalPen, p.X, p.Y, 80, 60);
            var s = YawAngle.ToString(YawFormat) + YawUnits;

            size = g.MeasureString(s, ScaleFontBig);
            g.DrawString(s, ScaleFontBig, normalBrush, p.X + 40 - size.Width / 2.0f, p.Y + 15 - size.Height / 2.0f);
        }