Пример #1
0
        public Form1()
        {
            InitializeComponent();
            WorkspacePictureBox.Image = new Bitmap(WorkspacePictureBox.Width, WorkspacePictureBox.Height);
            WorkspacePictureBox.Refresh();

            GET  = new MyEdge[WorkspacePictureBox.Height];
            GET2 = new MyEdge[WorkspacePictureBox.Height];

            tri1ColText = new DirectBitmap(Properties.Resources.brick_normalmap);
            Tri1ColTextPB.BackgroundImage = tri1ColText.Bitmap;

            tri2ColText = new DirectBitmap(Properties.Resources.normal_map);
            Tri2ColTextPB.BackgroundImage = tri2ColText.Bitmap;

            normVectText = new DirectBitmap(Properties.Resources.normal_map);
            NormVectTextPB.BackgroundImage = normVectText.Bitmap;

            disturbText = new DirectBitmap(Properties.Resources.brick_normalmap);
            DisturbTextPB.BackgroundImage = disturbText.Bitmap;

            timer1.Start();

            FillScanLines();
        }
Пример #2
0
        private void WorkspacePictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            Graphics g        = Graphics.FromImage(WorkspacePictureBox.Image);
            Point    location = new Point(e.X - r / 2, e.Y - r / 2);

            if (e.Button == MouseButtons.Left)
            {
                if (Points.Length <= 0)
                {
                    return;
                }

                Rectangle circ        = new Rectangle();
                int       iClosest    = 0;
                int       closestDist = (int)(Math.Pow(Math.Abs(Points[iClosest].X + r / 2 - e.X), 2) + Math.Pow(Math.Abs(Points[iClosest].Y + r / 2 - e.Y), 2));

                circ.Size = new Size(r, r);
                using (g)
                {
                    for (int i = 0; i < Points.Length; i++)
                    {
                        if (Math.Pow(Math.Abs(Points[i].X + r / 2 - e.X), 2) + Math.Pow(Math.Abs(Points[i].Y + r / 2 - e.Y), 2) < closestDist)
                        {
                            iClosest    = i;
                            closestDist = (int)(Math.Pow(Math.Abs(Points[i].X + r / 2 - e.X), 2) + Math.Pow(Math.Abs(Points[i].Y + r / 2 - e.Y), 2));
                        }
                    }

                    iChosen      = iClosest;
                    isBeingMoved = true;

                    if (closestDist < 800)
                    {
                        isTriangleBeingMoved = false;
                        isChosen             = true;
                        //iChosen = iClosest;
                        //isBeingMoved = true;
                    }
                    else
                    {
                        isTriangleBeingMoved = true;
                        isChosen             = false;
                    }
                    WorkspacePictureBox.Refresh();
                    FillScanLines();
                }
                mousePos = e.Location;
            }
        }
Пример #3
0
        private void WorkspacePictureBox_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (isBeingMoved || isTriangleBeingMoved)   // && isChosen
                {
                    isBeingMoved         = false;
                    isTriangleBeingMoved = false;
                    float nX = Points[iChosen].X;
                    float nY = Points[iChosen].Y;
                    int   i  = iChosen;
                    if (Points[iChosen].X < 0)
                    {
                        nX = -r / 2;
                    }
                    else if (Points[iChosen].X > WorkspacePictureBox.Width)
                    {
                        nX = WorkspacePictureBox.Width - r / 2;
                    }

                    if (Points[iChosen].Y < 0)
                    {
                        nY = -r / 2;
                    }
                    else if (Points[iChosen].Y > WorkspacePictureBox.Height)
                    {
                        nY = WorkspacePictureBox.Height - r / 2;
                    }

                    Points[iChosen].X = nX;
                    Points[iChosen].Y = nY;

                    mousePos = e.Location;

                    WorkspacePictureBox.Refresh();
                    FillScanLines();
                }
            }
        }