40 GUINT numIndices = endIndex - startIndex;
42 for (i = startIndex; i < endIndex; i++)
45 primitive_boxes[i].m_bound.m_min);
50 for (i = startIndex; i < endIndex; i++)
53 primitive_boxes[i].m_bound.m_min);
55 diff2 = diff2 * diff2;
68 GUINT splitIndex = startIndex;
69 GUINT numIndices = endIndex - startIndex;
73 for (i = startIndex; i < endIndex; i++)
75 splitValue += 0.5f * (primitive_boxes[i].m_bound.m_max[splitAxis] +
76 primitive_boxes[i].m_bound.m_min[splitAxis]);
81 for (i = startIndex; i < endIndex; i++)
83 btScalar center = 0.5f * (primitive_boxes[i].m_bound.m_max[splitAxis] +
84 primitive_boxes[i].m_bound.m_min[splitAxis]);
85 if (center > splitValue)
88 primitive_boxes.
swap(i, splitIndex);
102 GUINT rangeBalancedIndices = numIndices / 3;
103 bool unbalanced = ((splitIndex <= (startIndex + rangeBalancedIndices)) || (splitIndex >= (endIndex - 1 - rangeBalancedIndices)));
107 splitIndex = startIndex + (numIndices >> 1);
110 btAssert(!((splitIndex == startIndex) || (splitIndex == (endIndex))));
119 btAssert((endIndex - startIndex) > 0);
121 if ((endIndex - startIndex) == 1)
127 m_node_array[current_index].m_bound = primitive_boxes[startIndex].m_bound;
138 for (splitIndex = startIndex; splitIndex < endIndex; splitIndex++)
140 m_node_array[current_index].m_bound.merge(primitive_boxes[splitIndex].m_bound);
149 primitive_boxes, startIndex, endIndex, splitIndex);
void build_tree(gim_array< GIM_AABB_DATA > &primitive_boxes)
prototype functions for box tree management
void resize(GUINT size, bool call_constructor=true, const T &fillData=T())
Very simple array container with fast access and simd memory.
void swap(GUINT i, GUINT j)
btVector3 can be used to represent 3D points and vectors.
GUINT _sort_and_calc_splitting_index(gim_array< GIM_AABB_DATA > &primitive_boxes, GUINT startIndex, GUINT endIndex, GUINT splitAxis)
int maxAxis() const
Return the axis with the largest value Note return values are 0,1,2 for x, y, or z.
GUINT _calc_splitting_axis(gim_array< GIM_AABB_DATA > &primitive_boxes, GUINT startIndex, GUINT endIndex)
gim_array< GIM_BOX_TREE_NODE > m_node_array
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
void _build_sub_tree(gim_array< GIM_AABB_DATA > &primitive_boxes, GUINT startIndex, GUINT endIndex)