示例#1
0
        public Visualizer(Grid.Grid xGrid, Drone.Drone xDrone)
        {
            InitializeComponent();

            srcGrid  = xGrid;
            srcDrone = xDrone;

            flightPathOptimized = false;

            preComputeFlightPath = xDrone.preComputeFlightPath;
            currFlightPath       = null;
            calcTimer            = null;

            //set up our window to be the proper aspect ratio for our grid
            float aspectRatio  = srcGrid.width / srcGrid.height;
            float frameBufferX = 17;
            float frameBufferY = 40;

            //our maximum height should be 720 pixels (720p), but we still want to fit everything on the screen in a way that looks neat
            //if the aspect ratio is > 16:9, then we should set our width at 1280 since height will be smaller than 720 at that point

            if (aspectRatio >= 16D / 9D)
            {
                Width  = 1280;
                Height = (int)(Width / aspectRatio);
            }
            else
            {
                Height = 720;
                Width  = (int)(Height * aspectRatio);
            }

            //add the necessary height & width for our tool panel and frame buffers
            Height = Height + toolPanel.Height + (int)frameBufferY;
            Width  = Width + (int)frameBufferX;

            //create our graphics object that we will be using to draw
            g = drawPanel.CreateGraphics();

            //calculate the transform that we will need to use to display graphics objects on our form

            float panelBufferX = 1;
            float panelBufferY = 1;

            RectangleF mapFrame = new RectangleF(0, 0, srcGrid.width, srcGrid.height);

            PointF[] drawCorners = new PointF[] { new PointF(0, 0), new PointF(drawPanel.Width - panelBufferX, 0), new PointF(0, drawPanel.Height - panelBufferY) };

            //scale the transform properly
            System.Drawing.Drawing2D.Matrix tMatrix = new System.Drawing.Drawing2D.Matrix(mapFrame, drawCorners);
            g.Transform = tMatrix;

            g.ScaleTransform(1, -1);
            g.TranslateTransform(0, -1 * (drawPanel.Height) / tMatrix.Elements.ElementAt(3) + panelBufferY);

            //initialize window and draw the control
            Show();
        }
示例#2
0
        private void button2_Click(object sender, EventArgs e)
        {
            button1.Enabled        = true;
            button3.Enabled        = true;
            flightStatusLabel.Text = "Showing Pre-Computed Flight Plan";
            button2.Enabled        = false;

            if (calcTimer != null)
            {
                calcTimer.Enabled = false;
                calcTimer         = null;
            }

            srcDrone = new Drone.Drone(5, 5, srcGrid);

            flightPathOptimized = false;

            preComputeFlightPath = srcDrone.preComputeFlightPath;
            currFlightPath       = null;

            Refresh();
            Invalidate();
        }