示例#1
0
 public Triangle(Point p1, Point p2, Point p3)
 {
     points[0] = new MyPoint(p1, 0);
     points[1] = new MyPoint(p2, 1);
     points[2] = new MyPoint(p3, 2);
 }
示例#2
0
            public void Fill(Graphics graphics)
            {
                int[] indexes = GetIndexesSortedByY();
                int   yMin    = points[indexes[0]].point.Y;
                int   yMax    = points[indexes[2]].point.Y;

                if (interpolated)
                {
                    colorsInPoints[0] = CalculateColorForXandY(points[0].point.X, points[0].point.Y);
                    colorsInPoints[1] = CalculateColorForXandY(points[1].point.X, points[1].point.Y);
                    colorsInPoints[2] = CalculateColorForXandY(points[2].point.X, points[2].point.Y);
                    area = CalculateArea(points[0].point, points[1].point, points[2].point);
                }


                for (int scanY = yMin; scanY <= yMax; scanY++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        if (points[indexes[k]].point.Y == scanY)
                        {
                            MyPoint previous = points[points[indexes[k]].PreviousIndex];
                            if (previous.point.Y > scanY)
                            {
                                AET.Add(new Edge(points[indexes[k]].point, previous.point));
                            }
                            else if (previous.point.Y < scanY)
                            {
                                RemoveEdge(previous.point, points[indexes[k]].point);
                            }
                            MyPoint next = points[points[indexes[k]].NextIndex];
                            if (next.point.Y > scanY)
                            {
                                AET.Add(new Edge(points[indexes[k]].point, next.point));
                            }
                            else if (next.point.Y < scanY)
                            {
                                RemoveEdge(next.point, points[indexes[k]].point);
                            }
                        }
                    }

                    if (AET.Count < 2)
                    {
                        break;
                    }

                    AET.Sort((e1, e2) => e1.x.CompareTo(e2.x));
                    for (int x = (int)AET[0].x; x <= (int)AET[1].x; x++)
                    {
                        Color col;
                        if (interpolated)
                        {
                            (double alpha, double beta, double gamma) = CalculateAlphaBetaGammaForPoint(new Point(x, scanY));
                            double X;
                            X = colorsInPoints[0].R * alpha + colorsInPoints[1].R * beta + colorsInPoints[2].R * gamma;
                            if (X > 255)
                            {
                                X = 255;
                            }
                            if (X < 0)
                            {
                                X = 0;
                            }
                            double Y;
                            Y = colorsInPoints[0].G * alpha + colorsInPoints[1].G * beta + colorsInPoints[2].G * gamma;
                            if (Y > 255)
                            {
                                Y = 255;
                            }
                            if (Y < 0)
                            {
                                Y = 0;
                            }
                            double Z;
                            Z = colorsInPoints[0].B * alpha + colorsInPoints[1].B * beta + colorsInPoints[2].B * gamma;
                            if (Z > 255)
                            {
                                Z = 255;
                            }
                            if (Z < 0)
                            {
                                Z = 0;
                            }
                            col = Color.FromArgb((int)(X), (int)(Y), (int)(Z));
                        }
                        else
                        {
                            col = CalculateColorForXandY(x, scanY);
                        }

                        lock (Form1.bitmap)
                        {
                            bitmap.SetPixel(x, scanY, col);
                        }
                    }

                    foreach (var e in AET)
                    {
                        e.x += e.m;
                    }
                }
            }
示例#3
0
 static void CopyProperies(MyPoint replaceFrom, MyPoint replaceTo)
 {
     replaceTo.RelatedLines.AddRange(replaceFrom.RelatedLines);
 }