Original Post
I'' read in the "Combining Octrees and BSP trees_is it Possible" post , the algorithm about ABTrees by YannL and i have some questions to ask.
1. Yann L said that you don''t have to split the polygons if you grow the bounding box of the two nodes.
My approach to the ABtrees is this:
I found the root BBox of the model
I found the Larger axis
I found a Plane with "starting" Origin the center of the root BBox and normal the normal of the larger axis.
In example: if the larger axis is X then the normal is (1,0,0) , if the larger axis is Y
then the normal is (0,1,0) ...
With that plane i found the number of polygons that are front,back, or divided by the plane.
To choose the right splitter i check to see if a function ,
in example: fabs(NumOfFrontPolygons - NumOfBackPolygons) <= TotalPolygons * factor)
Where the factor is a percentance of the total polygons that each time passed.
If the above function return true then the SplitterPlane found.
If the above function return false then i move the SplitterPlane.Origin, like that:
SplitterPlane.Origin += SplitterPlane.Normal * largerAxisLength *FACTOR
Where the FACTOR i found it that way:
If (NumOfFrontPolygons > NumOfBackPolygons)
{
// I use this, because if the Numerator is zero then the FACTOR = 0 and no movement of the Origin
NumOfBAckPolygons == 0 ? NumOfBackPolygons = 10: NumOfBackPolygons;
FACTOR = NumOfBackPolygons/NumOfFrontPolygons;
}
if(NumOfBAckPolygons > NumOfFrontPolygons )
{
NumOfFrontPolygons == 0 ? NumOfFrontPolygons = 10: NumOfFrontPolygons;
FACTOR = NumOfFrontPolygons/ NumOfBackPolygons;
}
If I found polygon that divided by the plane then i add it to both Front and Back Polygons.
That way i found the best splittin Plane.
Now When i build the ABTrees I calculate the BBox for every node and the best Splitter and then i put the polygons in front and back nodes.
The problem is that i don''t want to split the polygons cause there are many polygons created and i do it that way:
When i found that a polygons is divided by the plane, i calculate polygon''s center.Then i calculate to which side of the plane that center is. If it''s in front then i put it in Front polygons, if it''s in Back of the plane i put it Back polygons.
The problem is that i don''t grow the BBox of the Node (I did''nt understood when you should do this) and i don''t spli the Polygons.
The other problem is when to stop the recursion.I stop the recursion when 5 or less polygons are in node.Is that right?
From the above approach what is wrong ? Because when i draw the BBoxes of the tree i see some gaps(Not in the polygons but in Bounding Boxes of them. The polygons are rendered correct).I don''t know how this should look like but i thinK that i do something wrong.
I test the code on a Box with 300 polygons. Maybe if anyone have any screenshot of the ABTree Bounding Boxes distribution, i would like to see it.
Another Question:
Must i build a tree per Object or one tree for the entire scene?
Thanks in advanced.
Hellraizer