public void Draw(Graphics gr, double distance, Face whichFace, Point3D lightSource) { Polygon2D polyProjected = Projection(distance); if (polyProjected != null) { if (polyProjected.Face != whichFace) { return; } Color tempColor = (whichFace == Face.front) ? frontColor : backColor; int reflectivity = Reflectivity(lightSource); int alpha = (whichFace == Face.front) ? alpha = reflectivity : 255 - reflectivity; alpha = 255; Brush brush = new SolidBrush(Color.FromArgb(alpha, tempColor)); double z = 0; foreach (Point3D p in vertices) { if (p.Z > z) { z = p.Z; } } if (polyProjected.IsInScreen(clientSize) && z < distance) { //polyProjected.Fill(gr, Brushes.Black); if (this.frontColor != Color.Transparent) { polyProjected.Fill(gr, brush); } polyProjected.Draw(gr, Pens.Gray); } } }
/// <summary> /// FIll the polygon on the display device /// </summary> /// <param name="gr"></param> /// <param name="distance"></param> /// <param name="whichFace">The face which is to be drawn</param> public void Fill(Graphics gr, double distance, Face whichFace, Point3D lightSrc) { Polygon2D poly2D = ToPolygon2D(distance); Face face = poly2D.Face; if (face != whichFace) { return; } // define new burshes based on the reflectitvity and the face being drawn Brush brush = new SolidBrush(Color.White); if (poly2D.Face == Face.foreground) { brush = new SolidBrush(Color.FromArgb(Reflectivity(lightSrc), fgColor)); } else if (poly2D.Face == Face.background) { brush = new SolidBrush(Color.FromArgb(255 - Reflectivity(lightSrc), bgColor)); } poly2D.Fill(gr, Brushes.Black); poly2D.Fill(gr, brush); }
public bool Contains(Point2D p, double distance) { Polygon2D poly2D = ToPolygon2D(distance); return(poly2D.Contains((int)p.X, (int)p.Y)); }