Here is some code that draws all the polygons in a BSP tree. I know that for the most part BSP trees are no longer used for depth sorting but I am really just experimenting to make sure I fully understand them. I am assuming that all polygons have only 2 Dimensions so when the scene is viewed from above all the polygons look like lines (so they are all perpendicular to the XZ plane).
struct BSP_Node
{
float A,B,C,D; //the plane of that polygon
char name;
BSP_Node *front_pointer;
BSP_Node *back_pointer;
};
BSP_Node *pointers[num_BSP_nodes];
void process_BSP_Node(BSP_Node cur)
{
if (cur->Acamera.xPos + cur->Bcamera.yPos + cur->Ccamera.zPos > cur->D)
{
if (cur->back_pointer != NULL) process_BSP_Node(cur->back_pointer);
display_polygon(cur->name);
if (cur->front_pointer != NULL) process_BSP_Node(cur->front_pointer);
}
else
{
if (cur->front_pointer != NULL) process_BSP_Node(cur->front_pointer);
display_polygon(cur->name);
if (cur->back_pointer != NULL) process_BSP_Node(cur->back_pointer);
}
}
As you can see the array *pointers[] holds all the BSP_Nodes. pointers[0] is the root node for the entire tree and it is the variable that is passed into the function to draw the scene.
My question is this: What if the camera’s viewpoint is on a polygon/plane instead of in front or in back? I am guessing that in that case you could go either way. So the above function should handle that case right?
Other than that can any one give a brief overview of the other uses for a BSP tree? I have heard collision detection, in order drawing of polygons, culling of large amounts of scenery. What else can they be used for? Also, would the above function handle ‘3D’ scenes also where the polygons are not all straight up and down? I think it would but creating the BSP tree would be more complex.