Преглед на файлове

algorithm: replace a fugly macro with a fugly function.

undefined
Sam Hocevar преди 10 години
родител
ревизия
0cbbca1d2f
променени са 1 файла, в които са добавени 39 реда и са изтрити 33 реда
  1. +39
    -33
      src/lol/algorithm/aabb_tree.h

+ 39
- 33
src/lol/algorithm/aabb_tree.h Целия файл

@@ -26,37 +26,43 @@ template <typename TE> 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<typename TREE, typename TE, typename TBB>
void DrawInner(TREE *tree, Array<TBB, vec4> &boxes,
Array<TE *, int, vec4> &elements,
Array<int, TBB> &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<TE>* tree, vec4 color)
Array<TE*, int, vec4> elements;
Array<int, box2> leaves;

GET_DRAW_DATA(tree, boxes, elements, 4, box2);
DrawInner<QuadTree<TE>, 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<TE>* tree, vec4 color)
Array<TE*, int, vec4> elements;
Array<int, box3> leaves;

GET_DRAW_DATA(tree, boxes, elements, 8, box3);
DrawInner<OcTree<TE>, TE, box3>(tree, boxes, elements, leaves, 8, color);

vec3 off = vec3::v010 * .1f;
vec3 add = vec3::v010 * .1f;


Зареждане…
Отказ
Запис