/// <summary> /// Computes the BSP tree. /// </summary> /// <param name="perspectiveAngle">The Perspective Angle</param> /// <param name="depth">The Chart Depth</param> /// <param name="rotation">The Rotation Angle</param> /// <param name="tilt">The Tilt Angle</param> /// <param name="size">The Size</param> public void PrepareView(double perspectiveAngle, double depth, double rotation, double tilt, Size size) { if (this.transform == null) { this.transform = new ChartTransform.ChartTransform3D(size); } else { this.transform.mViewport = size; } this.transform.Rotation = rotation; this.transform.Tilt = tilt; this.transform.Depth = depth; this.transform.PerspectiveAngle = perspectiveAngle; this.transform.Transform(); this.tree = this.treeBuilder.Build(); }
/// <summary> /// Draws the BSP node in 3D. /// </summary> /// <param name="tree">The Tree.</param> /// <param name="eye">The Eye Position.</param> /// <param name="panel">The Panel.</param> private void DrawBspNode3D(BspNode tree, Vector3D eye, Panel panel) { if (tree == null || this.transform == null) { return; } while (true) { var r = tree.Plane.GetNormal(this.transform.Result) & eye; if (r > tree.Plane.D) { if (tree.Front != null) { this.DrawBspNode3D(tree.Front, eye, panel); } tree.Plane.Draw(panel); if (tree.Back != null) { tree = tree.Back; continue; } } else { if (tree.Back != null) { this.DrawBspNode3D(tree.Back, eye, panel); } tree.Plane.Draw(panel); if (tree.Front != null) { tree = tree.Front; continue; } } break; } }
public int GetNodeCount(BspNode el) { return((el == null) ? 0 : 1 + this.GetNodeCount(el.Back) + this.GetNodeCount(el.Front)); }
/// <summary> /// Computes the BSP tree. /// </summary> public void PrepareView() { this.tree = this.treeBuilder.Build(); }
/// <summary> /// Builds the specified collection of polygons. /// </summary> /// <param name="arlist">The collection of polygons.</param> /// <returns>Returns the built <see cref="BspNode"/>.</returns> public BspNode Build(List <Polygon3D> arlist) { if (arlist.Count < 1) { return(null); } var bspNode = new BspNode(); var plane = arlist[0]; bspNode.Plane = plane; var arleft = new List <Polygon3D>(arlist.Count); var arright = new List <Polygon3D>(arlist.Count); for (int i = 1, len = arlist.Count; i < len; i++) { var pln = arlist[i]; if (pln == plane) { continue; } var r = ClassifyPolygon(plane, pln); switch (r) { case ClassifyPolyResult.OnPlane: case ClassifyPolyResult.ToRight: arright.Add(pln); break; case ClassifyPolyResult.ToLeft: arleft.Add(pln); break; case ClassifyPolyResult.Unknown: if (pln is Line3D || pln is UIElement3D) { arleft.Add(pln); } else if (pln is PolyLine3D) { arright.Add(pln); } else { Polygon3D[] ps1, ps2; BspTreeBuilder.SplitPolygon(pln, plane, out ps1, out ps2); arleft.AddRange(ps1); arright.AddRange(ps2); } break; } } if (arleft.Count > 0) { bspNode.Back = this.Build(arleft); } if (arright.Count > 0) { bspNode.Front = this.Build(arright); } return(bspNode); }