diff --git a/src/lol/algorithm/aabb_tree.h b/src/lol/algorithm/aabb_tree.h index ec0076e8..313308c1 100644 --- a/src/lol/algorithm/aabb_tree.h +++ b/src/lol/algorithm/aabb_tree.h @@ -26,37 +26,43 @@ template class OcTree; //-- namespace Debug { //-- -#define GET_DRAW_DATA(DEF_TREE, DEF_BOXES, DEF_ELEM, CHILD_NB, TBB) \ -boxes.Push(tree->GetAABB(), vec4::one); \ -leaves.Push(0, boxes.Last().m1); \ -while (leaves.Count() > 0) \ -{ \ - for (int j = 0; j < tree->GetTree()[leaves[0].m1].m_elements.Count(); j++) \ - { \ - bool done = false; \ - for (int k = 0; k < elements.Count(); k++) \ - { \ - if (elements[k].m1 == tree->GetElements()[tree->GetTree()[leaves[0].m1].m_elements[j]].m_element) \ - { \ - elements[k].m2++; \ - done = true; \ - break; \ - } \ - } \ - if (!done) \ - elements.Push(tree->GetElements()[tree->GetTree()[leaves[0].m1].m_elements[j]].m_element, 1, vec4::v1001); \ - } \ - \ - for (int i = 0; i < CHILD_NB; i++) \ - { \ - if (tree->GetTree()[leaves[0].m1].m_children[i] != 0) \ - { \ - TBB bbox = tree->GetSubAABB(leaves[0].m2, i); \ - leaves.Push(tree->GetTree()[leaves[0].m1].m_children[i], bbox); \ - boxes.Push(bbox, color); \ - } \ - } \ - leaves.Remove(0); \ + +template +void DrawInner(TREE *tree, Array &boxes, + Array &elements, + Array &leaves, int children, vec4 color) +{ + boxes.Push(tree->GetAABB(), vec4::one); + leaves.Push(0, boxes.Last().m1); + while (leaves.Count() > 0) + { + for (int j = 0; j < tree->GetTree()[leaves[0].m1].m_elements.Count(); j++) + { + bool done = false; + for (int k = 0; k < elements.Count(); k++) + { + if (elements[k].m1 == tree->GetElements()[tree->GetTree()[leaves[0].m1].m_elements[j]].m_element) + { + elements[k].m2++; + done = true; + break; + } + } + if (!done) + elements.Push(tree->GetElements()[tree->GetTree()[leaves[0].m1].m_elements[j]].m_element, 1, vec4::v1001); + } + + for (int i = 0; i < children; i++) + { + if (tree->GetTree()[leaves[0].m1].m_children[i] != 0) + { + TBB bbox = tree->GetSubAABB(leaves[0].m2, i); + leaves.Push(tree->GetTree()[leaves[0].m1].m_children[i], bbox); + boxes.Push(bbox, color); + } + } + leaves.Remove(0); + } } //-- @@ -67,7 +73,7 @@ void Draw(QuadTree* tree, vec4 color) Array elements; Array leaves; - GET_DRAW_DATA(tree, boxes, elements, 4, box2); + DrawInner, TE, box2>(tree, boxes, elements, leaves, 4, color); vec3 off = vec3::v010 * .1f; vec3 add = vec3::v010 * .1f; @@ -98,7 +104,7 @@ void Draw(OcTree* tree, vec4 color) Array elements; Array leaves; - GET_DRAW_DATA(tree, boxes, elements, 8, box3); + DrawInner, TE, box3>(tree, boxes, elements, leaves, 8, color); vec3 off = vec3::v010 * .1f; vec3 add = vec3::v010 * .1f;