public Face3D Point(int tag, float x, float y, float z) { Face3D f = new Face3D(1); f.Points[0] = new Point3D(x, y, z); f.Tag = tag; this.Add(f); return(f); }
public Face3D Point(int tag, Point3D p) { Face3D f = new Face3D(1); f.Points[0] = p; f.Tag = tag; this.Add(f); return(f); }
public Face3D Copy() { Face3D f = new Face3D(this.points.Length); for (int i = 0; i < f.points.Length; i++) f.points[i] = this.points[i]; f.tag = this.tag; f.shadow = this.shadow; return f; }
public Canvas Draw(int width, int height, float angleX, float angleY, float angleZ, Point3D camera) { if (this.faces.Count == 0) { return(null); } Space3D faces = this.Copy(); Canvas c = new Canvas(); c.Open(width, height); c.DrawBar(Brushes.White, 0, 0, c.Width, c.Height); faces.Project((int)(angleX * 10f), (int)(angleY * 10f), (int)(angleZ * 10f), camera); faces.SortDepth(); Limits2D lim = faces.Limits; double d = (double)(c.Width - 10) / (double)(lim.MaxX - lim.MinX); double scale = (double)(c.Height - 10) / (double)(lim.MaxY - lim.MinY); if (scale > d) { scale = d; } List <TopMarks> top = new List <TopMarks>(); for (int i = 0; i < faces.Count; i++) { Face3D f = faces[i]; Color clr = Color.Black; if ((f.Tag & 0xff000000) == 0x7f000000) { clr = Color.FromArgb((int)(f.Tag >> 16) & 0xff, (int)(f.Tag >> 8) & 0xff, (int)f.Tag & 0xff); } else { clr = this.GetColor(f.Tag); } int x; int y; if (f.Count > 1) { if (f.Shadow != 0) { clr = ColorUtils.DarkColor(clr, f.Shadow); } x = (int)((double)(f.Points[0].X - lim.MinX) * scale); y = (int)((double)(f.Points[0].Y - lim.MinY) * scale); Point[] plst = null; if (f.Count > 2) { plst = new Point[f.Count]; plst[0] = new Point(x, y); } for (int j = 1; j < f.Count; j++) { int x0 = (int)((double)(f.Points[j].X - lim.MinX) * scale); int y0 = (int)((double)(f.Points[j].Y - lim.MinY) * scale); if (f.Count == 2) { c.DrawLine(new Pen(clr), x, y, x0, y0); break; } else { plst[j] = new Point(x0, y0); } } if (plst != null) { c.FillPolygon(new SolidBrush(clr), plst); } } else { x = (int)((double)(f.Points[0].X - lim.MinX) * scale); y = (int)((double)(f.Points[0].Y - lim.MinY) * scale); Pen pen = null; if (((clr.R + clr.G + clr.B) / 3) > 0x7f) { pen = Pens.Black; } else { pen = Pens.White; } switch (f.Shadow) { case -1: c.TriangleMark(new SolidBrush(clr), pen, x, y, Space3D.ColorSignSize); break; case -2: c.RectangleMark(new SolidBrush(clr), pen, x, y, Space3D.ColorSignSize); break; case -3: c.PointMark(new SolidBrush(clr), x, y); break; case -101: top.Add(new TopMarks(clr, x, y, -1)); break; case -102: top.Add(new TopMarks(clr, x, y, -2)); break; case -103: top.Add(new TopMarks(clr, x, y, -3)); break; default: c.CircleMark(new SolidBrush(clr), pen, x, y, Space3D.ColorSignSize >> 1); break; } } } for (int i = 0; i < top.Count; i++) { TopMarks t = top[i]; Color clr = t.Color; Pen pen = null; if (((clr.R + clr.G + clr.B) / 3) > 0x7f) { pen = Pens.Black; } else { pen = Pens.White; } int x = t.X; int y = t.Y; switch (t.Shadow) { case -1: c.TriangleMark(new SolidBrush(clr), pen, x, y, Space3D.ColorSignSize); break; case -2: c.RectangleMark(new SolidBrush(clr), pen, x, y, Space3D.ColorSignSize); break; case -3: c.PointMark(new SolidBrush(clr), x, y); break; } } return(c); }
public void Add(Face3D face) { this.faces.Add(face); }