First BSP Example

You'll encapsulate the BSP drawing in the SimpleBSPRenderer class, which is a subclass of ShadedSurfacePolygonRenderer. This new class has one method for drawing polygons in a tree and also is a BSPTraverseListener, as shown here:

/**
 Draws the visible polygons in a BSP tree based on
 the camera location. The polygons are drawn front to back.
*/
public void draw(Graphics2D g, BSPTree tree) {
 currentGraphics2D = g;
 traverser.traverse(tree, camera.getLocation());
}
// from the BSPTreeTraverseListener interface public boolean visitPolygon(BSPPolygon poly, boolean isBack) {
 draw(currentGraphics2D, poly);
 return !((SortedScanConverter)scanConverter).isFilled();
}

Next, create the basic demo in a class called BSPTest3D. The BSPTest3D class is similar to BSPTest2D, except that it draws polygons using the SimpleBSPRenderer:

public void draw(Graphics2D g) {
 // draw polygons
 polygonRenderer.startFrame(g);
 ((SimpleBSPRenderer)polygonRenderer).draw(g, bspTree);
 polygonRenderer.endFrame(g);
 super.drawText(g);
}

That's it for the demo. Finally, you can see your example floor plan in 3D. Check out the screenshot in .

Screenshot Screenshot of BSPTest3D.

Java graphics 10fig18

This demo works fine, but there are a couple problems:

So, let's work on solving these issues, shall we?