public void Insert(Plane3D p) { if (node == null) { node = new BSPTreeNode(p); } else { node.Insert(p); } }
// split both child spaces public void Insert(Plane3D p) { if (this.plane.normal == p.normal) { Vector3D point = p.normal * -p.distance; double distanceToPoint = this.plane.GetDistanceToPoint(point); if (distanceToPoint > 0) { if (left == null) { left = new BSPTreeNode(p); } else { left.Insert(p); } } else if (distanceToPoint < 0) { if (right == null) { right = new BSPTreeNode(p); } else { right.Insert(p); } } else { Debug.LogError("Splitting plane already defined"); } } else { if (left == null) { left = new BSPTreeNode(p); } else { left.Insert(p); } if (right == null) { right = new BSPTreeNode(p); } else { right.Insert(p); } } }