internal void Draw(Box box) { System.Drawing.Graphics g = Graphics; if (box is Pack) { Pack pack = box as Pack; pack.Draw(this); } else { Vector3D[] points = box.Points; Face[] faces = box.Faces; for (int i = 0; i < 6; ++i) { // Face Face face = faces[i]; // face normal Vector3D normal = face.Normal; // visible ? if (!faces[i].IsVisible(_vTarget - _vCameraPos)) { continue; } // color faces[i].ColorFill = box.Colors[i]; double cosA = System.Math.Abs(Vector3D.DotProduct(faces[i].Normal, VLight)); Color color = Color.FromArgb((int)(faces[i].ColorFill.R * cosA), (int)(faces[i].ColorFill.G * cosA), (int)(faces[i].ColorFill.B * cosA)); // points Vector3D[] points3D = faces[i].Points; Point[] pt = TransformPoint(GetCurrentTransformation(), points3D); // draw solid face Brush brush = new SolidBrush(color); g.FillPolygon(brush, pt); // draw textures if (null != face.Textures && ShowTextures) { foreach (Texture texture in face.Textures) { Point[] ptsImage = TransformPoint(GetCurrentTransformation(), box.PointsImage(i, texture)); Point[] pts = new Point[3]; pts[0] = ptsImage[3]; pts[1] = ptsImage[2]; pts[2] = ptsImage[0]; g.DrawImage(texture.Bitmap, pts); } } // draw path Brush brushPath = new SolidBrush(faces[i].ColorPath); Pen penPathThick = new Pen(brushPath, box.IsBundle ? 2.0f : 1.5f); int ptCount = pt.Length; for (int j = 1; j < ptCount; ++j) { g.DrawLine(penPathThick, pt[j - 1], pt[j]); } g.DrawLine(penPathThick, pt[ptCount - 1], pt[0]); // draw bundle lines if (box.IsBundle && i < 4) { Pen penPathThin = new Pen(brushPath, 1.5f); int noSlice = Math.Min(box.BundleFlats, 4); for (int iSlice = 0; iSlice < noSlice - 1; ++iSlice) { Vector3D[] ptSlice = new Vector3D[2]; ptSlice[0] = points3D[0] + ((double)(iSlice + 1) / (double)noSlice) * (points3D[3] - points3D[0]); ptSlice[1] = points3D[1] + ((double)(iSlice + 1) / (double)noSlice) * (points3D[2] - points3D[1]); Point[] pt2D = TransformPoint(GetCurrentTransformation(), ptSlice); g.DrawLine(penPathThin, pt2D[0], pt2D[1]); } } } // draw box tape if (box.ShowTape && faces[5].IsVisible(_vTarget - _vCameraPos)) { // get color double cosA = System.Math.Abs(Vector3D.DotProduct(faces[5].Normal, VLight)); Color color = Color.FromArgb((int)(box.TapeColor.R * cosA), (int)(box.TapeColor.G * cosA), (int)(box.TapeColor.B * cosA)); // instantiate brush Brush brushTape = new SolidBrush(color); // get tape points Point[] pts = TransformPoint(GetCurrentTransformation(), box.TapePoints); // fill polygon g.FillPolygon(brushTape, pts); // draw path Brush brushPath = new SolidBrush(faces[5].ColorPath); Pen penPathThick = new Pen(brushPath, 1.5f); int ptCount = pts.Length; for (int j = 1; j < ptCount; ++j) { g.DrawLine(penPathThick, pts[j - 1], pts[j]); } g.DrawLine(penPathThick, pts[ptCount - 1], pts[0]); } } if (_showBoxIds) { // draw box id Point ptId = TransformPoint(GetCurrentTransformation(), box.TopFace.Center); g.DrawString( box.PickId.ToString() , new Font("Arial", GridFontSize) , Brushes.Black , new Rectangle(ptId.X - 15, ptId.Y - 10, 30, 20) , StringFormat.GenericDefault); g.DrawString( _boxDrawingCounter.ToString() , new Font("Arial", GridFontSize) , Brushes.Red , new Rectangle(ptId.X + 5, ptId.Y - 10, 30, 20) , StringFormat.GenericDefault); } ++_boxDrawingCounter; }
/// <summary> /// add face /// </summary> /// <param name="face">Face item</param> public void AddFace(Face face) { _faces.Add(face); }
/// <summary> /// Background faces /// </summary> /// <param name="face">Face to be drawn before other faces</param> public void AddFaceBackground(Face face) { _facesBackground.Add(face); }
private int Split(Face f, ref List <Face> f1, ref List <Face> f2) { int[] v = new int[4]; int val = 0; int i = 0; foreach (Vector3D pt in f.Points) { v[i] = TestPoint(pt); val += v[i++]; } switch (val) { case 4: f1.Add(f); return(1); case -4: f2.Add(f); return(1); case 2: f1.Add(f); return(1); case -2: f2.Add(f); return(1); case 0: if (0 != v[0] && 0 != v[1] && 0 != v[2] && 0 != v[3]) { for (i = 0; i < 4; ++i) { if (v[i % 4] + v[(i + 1) % 4] == 2) { Vector3D ptInter1 = Vector3D.Zero, ptInter2 = Vector3D.Zero; TestLine(f.Points[(i + 1) % 4], f.Points[(i + 2) % 4], ref ptInter1); TestLine(f.Points[(i + 3) % 4], f.Points[(i + 4) % 4], ref ptInter2); Vector3D[] v1 = new Vector3D[4]; v1[0] = f.Points[i % 4]; v1[1] = f.Points[(i + 1) % 4]; v1[2] = ptInter1; v1[3] = ptInter2; f1.Add(new Face(f.PickingId, v1, f.ColorFill, f.ColorPath, f.IsSolid)); Vector3D[] v2 = new Vector3D[4]; v2[0] = ptInter2; v2[1] = ptInter1; v2[2] = f.Points[(i + 2) % 4]; v2[3] = f.Points[(i + 3) % 4]; f2.Add(new Face(f.PickingId, v2, f.ColorFill, f.ColorPath, f.IsSolid)); } } return(2); } else // triangle is inside plane, assign to positive node { f1.Add(f); return(1); } default: _log.WarnFormat("Split: val = {0}", val); throw new GraphicsException("Split failed!"); } }
// constructor public BSPNode(Face f) { Face = f; InitEquation(f, ref A, ref B, ref C, ref D); }
/// <summary> /// add face /// </summary> /// <param name="face">Face item</param> public void AddFace(Face face) => Faces.Add(face);