26#ifdef TRI_COLLISION_PROFILING
30float g_accum_tree_collision_time = 0;
31int g_count_traversing = 0;
33void bt_begin_gim02_tree_time()
38void bt_end_gim02_tree_time()
45float btGImpactBvh::getAverageTreeCollisionTime()
47 if (g_count_traversing == 0)
return 0;
49 float avgtime = g_accum_tree_collision_time;
50 avgtime /= (float)g_count_traversing;
52 g_accum_tree_collision_time = 0;
53 g_count_traversing = 0;
72 int numIndices = endIndex - startIndex;
74 for (i = startIndex; i < endIndex; i++)
77 primitive_boxes[i].m_bound.m_min);
82 for (i = startIndex; i < endIndex; i++)
85 primitive_boxes[i].m_bound.m_min);
87 diff2 = diff2 * diff2;
97 int endIndex,
int splitAxis)
100 int splitIndex = startIndex;
101 int numIndices = endIndex - startIndex;
107 for (i = startIndex; i < endIndex; i++)
110 primitive_boxes[i].m_bound.m_min);
115 splitValue = means[splitAxis];
118 for (i = startIndex; i < endIndex; i++)
121 primitive_boxes[i].m_bound.m_min);
122 if (center[splitAxis] > splitValue)
125 primitive_boxes.
swap(i, splitIndex);
140 int rangeBalancedIndices = numIndices / 3;
141 bool unbalanced = ((splitIndex <= (startIndex + rangeBalancedIndices)) || (splitIndex >= (endIndex - 1 - rangeBalancedIndices)));
145 splitIndex = startIndex + (numIndices >> 1);
148 btAssert(!((splitIndex == startIndex) || (splitIndex == (endIndex))));
158 btAssert((endIndex - startIndex) > 0);
160 if ((endIndex - startIndex) == 1)
163 setNodeBound(curIndex, primitive_boxes[startIndex].m_bound);
164 m_node_array[curIndex].setDataIndex(primitive_boxes[startIndex].m_data);
174 primitive_boxes, startIndex, endIndex,
183 for (
int i = startIndex; i < endIndex; i++)
185 node_bound.
merge(primitive_boxes[i].m_bound);
237 bound.
merge(temp_box);
244 bound.
merge(temp_box);
259 for (
int i = 0; i < primitive_boxes.
size(); i++)
262 primitive_boxes[i].
m_data = i;
274 while (curIndex < numNodes)
284 if (isleafnode && aabbOverlap)
289 if (aabbOverlap || isleafnode)
300 if (collided_results.
size() > 0)
return true;
312 while (curIndex < numNodes)
319 bool aabbOverlap = bound.
collide_ray(ray_origin, ray_dir);
322 if (isleafnode && aabbOverlap)
327 if (aabbOverlap || isleafnode)
338 if (collided_results.
size() > 0)
return true;
345 int node0,
int node1,
bool complete_primitive_tests)
362 int node0,
int node1,
bool complete_primitive_tests)
365 boxset0, boxset1, trans_cache_1to0,
366 node0, node1, complete_primitive_tests) ==
false)
return;
383 collision_pairs, trans_cache_1to0,
389 collision_pairs, trans_cache_1to0,
400 collision_pairs, trans_cache_1to0,
407 collision_pairs, trans_cache_1to0,
416 collision_pairs, trans_cache_1to0,
423 collision_pairs, trans_cache_1to0,
430 collision_pairs, trans_cache_1to0,
437 collision_pairs, trans_cache_1to0,
454#ifdef TRI_COLLISION_PROFILING
455 bt_begin_gim02_tree_time();
460 &collision_pairs, trans_cache_1to0, 0, 0,
true);
461#ifdef TRI_COLLISION_PROFILING
462 bt_end_gim02_tree_time();
static void _find_collision_pairs_recursive(btGImpactBvh *boxset0, btGImpactBvh *boxset1, btPairSet *collision_pairs, const BT_BOX_BOX_TRANSFORM_CACHE &trans_cache_1to0, int node0, int node1, bool complete_primitive_tests)
bool _node_collision(btGImpactBvh *boxset0, btGImpactBvh *boxset1, const BT_BOX_BOX_TRANSFORM_CACHE &trans_cache_1to0, int node0, int node1, bool complete_primitive_tests)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
#define SIMD_FORCE_INLINE
bool overlapping_trans_cache(const btAABB &box, const BT_BOX_BOX_TRANSFORM_CACHE &transcache, bool fulltest) const
transcache is the transformation cache from box to this AABB
bool collide_ray(const btVector3 &vorigin, const btVector3 &vdir) const
Finds the Ray intersection parameter.
void merge(const btAABB &box)
Merges a Box.
bool has_collision(const btAABB &other) const
int size() const
return the number of elements in the array
void resize(int newsize, const T &fillData=T())
void swap(int index0, int index1)
void push_back(const T &_Val)
void _build_sub_tree(GIM_BVH_DATA_ARRAY &primitive_boxes, int startIndex, int endIndex)
int _calc_splitting_axis(GIM_BVH_DATA_ARRAY &primitive_boxes, int startIndex, int endIndex)
GIM_BVH_TREE_NODE_ARRAY m_node_array
void setNodeBound(int nodeindex, const btAABB &bound)
int _sort_and_calc_splitting_index(GIM_BVH_DATA_ARRAY &primitive_boxes, int startIndex, int endIndex, int splitAxis)
void build_tree(GIM_BVH_DATA_ARRAY &primitive_boxes)
prototype functions for box tree management
The btClock is a portable basic clock that measures accurate time in seconds, use for profiling.
void reset()
Resets the initial reference time.
unsigned long long int getTimeMicroseconds()
Returns the time in us since the last call to reset or since the Clock was created.
Structure for containing Boxes.
void buildSet()
this rebuild the entire set
int getRightNode(int nodeindex) const
int getNodeCount() const
node count
bool isLeafNode(int nodeindex) const
tells if the node is a leaf
int getLeftNode(int nodeindex) const
bool boxQuery(const btAABB &box, btAlignedObjectArray< int > &collided_results) const
returns the indices of the primitives in the m_primitive_manager
void getNodeBound(int nodeindex, btAABB &bound) const
int getEscapeNodeIndex(int nodeindex) const
int getNodeData(int nodeindex) const
bool rayQuery(const btVector3 &ray_dir, const btVector3 &ray_origin, btAlignedObjectArray< int > &collided_results) const
returns the indices of the primitives in the m_primitive_manager
btPrimitiveManagerBase * m_primitive_manager
void setNodeBound(int nodeindex, const btAABB &bound)
static void find_collision(btGImpactBvh *boxset1, const btTransform &trans1, btGImpactBvh *boxset2, const btTransform &trans2, btPairSet &collision_pairs)
void push_pair(int index1, int index2)
virtual int get_primitive_count() const =0
virtual void get_primitive_box(int prim_index, btAABB &primbox) const =0
btVector3 can be used to represent 3D points and vectors.
int maxAxis() const
Return the axis with the largest value Note return values are 0,1,2 for x, y, or z.