private void Grid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            double height = MainImage.Height;
            double width  = MainImage.Width;
            Point  mouse  = e.GetPosition(MainImage);

            actheight = MainImage.ActualHeight;
            actwidth  = MainImage.ActualWidth;
            mouse.X   = (mouse.X / actwidth) * 1067;
            mouse.Y   = (mouse.Y / actheight) * 657;
            Console.WriteLine("height: " + height + " width: " + width + " actual height: " + actheight + " actual width: " + actwidth);
            double wbmp = wbmap.Width;
            double hbmp = wbmap.Height;

            Console.WriteLine("bitmap height: " + hbmp + "bitmap width: " + wbmp);

            Console.WriteLine("x: " + mouse.X + " y: " + mouse.Y);

            //   double wdiff = 1067 - actwidth;
            //   double hdiff = 657 - actheight;
            Console.WriteLine("x: " + mouse.X + " y: " + mouse.Y);
            if (!polygonFinished && polygonStarted)
            {
                Vertex v = new Vertex(wbmap.DrawBresenhamCircle((int)mouse.X, (int)mouse.Y, 6), mouse);
                if (!IsDrawing)
                {
                    vm.Start  = mouse;
                    IsDrawing = true;
                }
                else
                {
                    if (vm.Polygon.IsStartPoint(mouse))
                    {
                        polygonFinished = true;
                        IsDrawing       = false;
                        wbmap.WritePixels(new Int32Rect(0, 0, wbmap.PixelWidth, wbmap.PixelHeight), vm.BitmapArraySource, wbmap.BackBufferStride, 0);
                        line = wbmap.DrawBresenhamLine((int)vm.NewLine.X, (int)vm.NewLine.Y, (int)vm.Polygon.Lines[0].Vertices[0].GetX(), (int)vm.Polygon.Lines[0].Vertices[0].GetY(), Colors.Black);
                    }
                    vm.Polygon.AddLine(new Line(Vertex.GetVertexFromMiddlePoint(line[0], 6), Vertex.GetVertexFromMiddlePoint(line[1], 6)));
                }
                vm.NewLine = mouse;
                wbmap.CopyPixels(vm.BitmapArraySource, wbmap.BackBufferStride, 0);
            }
            else
            {
                if (vm.IsPointInPolygonVertices(mouse))
                {
                    vm.DraggedVertex = vm.Polygon.GetVertexFromPoint(mouse);
                    vm.Adjacent      = vm.Polygon.GetAdjacentLines(mouse);
                    VertexDrag       = true;
                }

                else if (vm.IsPointInPolygonLines(mouse))
                {
                    PolygonDrag = true;
                    vm.Waypoint = mouse;
                }
            }
        }
示例#2
0
 public void DrawPolygon(WriteableBitmap wbm, Polygon polygon, Color color)
 {
     foreach (Edge e in polygon.Edges)
     {
         wbm.DrawBresenhamLine((int)e.Vertices[0].GetX(), (int)e.Vertices[0].GetY(), (int)e.Vertices[1].GetX(), (int)e.Vertices[1].GetY(), color);
         wbm.DrawBresenhamCircle((int)e.Vertices[0].GetX(), (int)e.Vertices[0].GetY(), 6);
     }
 }
 public void DrawPolygon(WriteableBitmap wbm, Polygon polygon)
 {
     polygon.RecalculatePolygon();
     foreach (var label in LineLabels)
     {
         label.UpdateLabel();
     }
     foreach (Line l in polygon.Lines)
     {
         wbm.DrawBresenhamLine((int)l.Vertices[0].GetX(), (int)l.Vertices[0].GetY(), (int)l.Vertices[1].GetX(), (int)l.Vertices[1].GetY(), Colors.Black);
         wbm.DrawBresenhamCircle((int)l.Vertices[0].GetX(), (int)l.Vertices[0].GetY(), 6);
     }
 }
示例#4
0
        private void FillPolygon(WriteableBitmap wbm, Polygon polygon, Color color)
        {
            List <Edge>            pixelPairs      = Scanline.GetLinesToFill(polygon);
            List <List <Color> >   colors          = polygon.GetColorLists(pixelPairs);
            List <List <Point3D> > normalMapColors = polygon.GetNormalMapLists(pixelPairs);

            for (int i = 0; i < pixelPairs.Count; i++)
            {
                int            y            = (int)pixelPairs[i].Vertices[0].GetY();
                List <Point3D> normalColors = normalMapColors?[i];
                IlluminationModel.ApplyIllumination(pixelPairs[i], colors[i], normalColors);
                wbm.DrawBresenhamLine((int)pixelPairs[i].Vertices[0].GetX(), y, (int)pixelPairs[i].Vertices[1].GetX(), y, colors[i]);
            }
        }
        private void MainBorder_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Cursor = Cursors.Arrow;
            Point  mouse     = e.GetPosition(MainImage);
            double actheight = MainImage.ActualHeight;
            double actwidth  = MainImage.ActualWidth;

            mouse.X = (mouse.X / actwidth) * 1067;
            mouse.Y = (mouse.Y / actheight) * 657;
            if (mouse.X > 1067 || mouse.X <= 0 || mouse.Y > 657 || mouse.Y <= 0)
            {
                return;
            }
            if (!polygonFinished && polygonStarted)
            {
                if (IsDrawing)
                {
                    vm.DrawPolygons(wbmap);
                    line = wbmap.DrawBresenhamLine((int)vm.NewLine.X, (int)vm.NewLine.Y, (int)mouse.X, (int)mouse.Y, Colors.Black);
                }
            }
            if (polygonFinished)
            {
                if (vm.IsPointInPolygonVertices(mouse))
                {
                    Cursor = Cursors.Hand;
                }
                else if (VertexDrag && e.LeftButton == MouseButtonState.Pressed)
                {
                    Cursor = Cursors.Hand;
                    vm.Polygon.MoveVertex(vm.DraggedVertex, mouse, out vm.DraggedVertex);
                    vm.DrawPolygons(wbmap);
                }
                else if (PolygonDrag && e.LeftButton == MouseButtonState.Pressed)
                {
                    Cursor = Cursors.Hand;
                    vm.MovePolygon(vm.Waypoint, mouse, out vm.Waypoint);
                    vm.DrawPolygons(wbmap);
                }
            }
        }
 public static void DrawLine(this WriteableBitmap wb, int x1, int y1, int x2, int y2, Color color)
 {
     wb.DrawBresenhamLine(x1, y1, x2, y2, color);
 }