26 #ifdef TRI_COLLISION_PROFILING
30 float g_accum_tree_collision_time = 0;
31 int g_count_traversing = 0;
34 void bt_begin_gim02_tree_time()
39 void bt_end_gim02_tree_time()
46 float btGImpactBvh::getAverageTreeCollisionTime()
48 if(g_count_traversing == 0)
return 0;
50 float avgtime = g_accum_tree_collision_time;
51 avgtime /= (float)g_count_traversing;
53 g_accum_tree_collision_time = 0;
54 g_count_traversing = 0;
63 #endif //TRI_COLLISION_PROFILING
75 int numIndices = endIndex-startIndex;
77 for (i=startIndex;i<endIndex;i++)
80 primitive_boxes[i].m_bound.m_min);
85 for (i=startIndex;i<endIndex;i++)
88 primitive_boxes[i].m_bound.m_min);
90 diff2 = diff2 * diff2;
101 int endIndex,
int splitAxis)
104 int splitIndex =startIndex;
105 int numIndices = endIndex - startIndex;
111 for (i=startIndex;i<endIndex;i++)
114 primitive_boxes[i].m_bound.m_min);
119 splitValue = means[splitAxis];
123 for (i=startIndex;i<endIndex;i++)
126 primitive_boxes[i].m_bound.m_min);
127 if (center[splitAxis] > splitValue)
130 primitive_boxes.
swap(i,splitIndex);
145 int rangeBalancedIndices = numIndices/3;
146 bool unbalanced = ((splitIndex<=(startIndex+rangeBalancedIndices)) || (splitIndex >=(endIndex-1-rangeBalancedIndices)));
150 splitIndex = startIndex+ (numIndices>>1);
153 btAssert(!((splitIndex==startIndex) || (splitIndex == (endIndex))));
167 if ((endIndex-startIndex)==1)
170 setNodeBound(curIndex,primitive_boxes[startIndex].m_bound);
171 m_node_array[curIndex].setDataIndex(primitive_boxes[startIndex].m_data);
181 primitive_boxes,startIndex,endIndex,
191 for (
int i=startIndex;i<endIndex;i++)
193 node_bound.
merge(primitive_boxes[i].m_bound);
249 bound.
merge(temp_box);
256 bound.
merge(temp_box);
271 for (
int i = 0;i<primitive_boxes.
size() ;i++ )
274 primitive_boxes[i].m_data = i;
286 while (curIndex < numNodes)
296 if (isleafnode && aabbOverlap)
301 if (aabbOverlap || isleafnode)
312 if(collided_results.
size()>0)
return true;
326 while (curIndex < numNodes)
333 bool aabbOverlap = bound.
collide_ray(ray_origin,ray_dir);
336 if (isleafnode && aabbOverlap)
341 if (aabbOverlap || isleafnode)
352 if(collided_results.
size()>0)
return true;
360 int node0 ,
int node1,
bool complete_primitive_tests)
379 int node0,
int node1,
bool complete_primitive_tests)
385 boxset0,boxset1,trans_cache_1to0,
386 node0,node1,complete_primitive_tests) ==
false)
return;
404 collision_pairs,trans_cache_1to0,
410 collision_pairs,trans_cache_1to0,
424 collision_pairs,trans_cache_1to0,
432 collision_pairs,trans_cache_1to0,
445 collision_pairs,trans_cache_1to0,
452 collision_pairs,trans_cache_1to0,
460 collision_pairs,trans_cache_1to0,
467 collision_pairs,trans_cache_1to0,
486 #ifdef TRI_COLLISION_PROFILING
487 bt_begin_gim02_tree_time();
488 #endif //TRI_COLLISION_PROFILING
492 &collision_pairs,trans_cache_1to0,0,0,
true);
493 #ifdef TRI_COLLISION_PROFILING
494 bt_end_gim02_tree_time();
495 #endif //TRI_COLLISION_PROFILING
static void find_collision(btGImpactBvh *boxset1, const btTransform &trans1, btGImpactBvh *boxset2, const btTransform &trans2, btPairSet &collision_pairs)
void push_back(const T &_Val)
GIM_BVH_TREE_NODE_ARRAY m_node_array
void setNodeBound(int nodeindex, const btAABB &bound)
virtual int get_primitive_count() const =0
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
unsigned long int getTimeMicroseconds()
Returns the time in us since the last call to reset or since the Clock was created.
The btClock is a portable basic clock that measures accurate time in seconds, use for profiling...
#define SIMD_FORCE_INLINE
void build_tree(GIM_BVH_DATA_ARRAY &primitive_boxes)
prototype functions for box tree management
void reset()
Resets the initial reference time.
void merge(const btAABB &box)
Merges a Box.
bool _node_collision(btGImpactBvh *boxset0, btGImpactBvh *boxset1, const BT_BOX_BOX_TRANSFORM_CACHE &trans_cache_1to0, int node0, int node1, bool complete_primitive_tests)
void _build_sub_tree(GIM_BVH_DATA_ARRAY &primitive_boxes, int startIndex, int endIndex)
void swap(int index0, int index1)
void push_pair(int index1, int index2)
int _calc_splitting_axis(GIM_BVH_DATA_ARRAY &primitive_boxes, int startIndex, int endIndex)
int _sort_and_calc_splitting_index(GIM_BVH_DATA_ARRAY &primitive_boxes, int startIndex, int endIndex, int splitAxis)
void getNodeBound(int nodeindex, btAABB &bound) const
int size() const
return the number of elements in the array
virtual void get_primitive_box(int prim_index, btAABB &primbox) const =0
bool isLeafNode(int nodeindex) const
tells if the node is a leaf
void setNodeBound(int nodeindex, const btAABB &bound)
bool collide_ray(const btVector3 &vorigin, const btVector3 &vdir) const
Finds the Ray intersection parameter.
void buildSet()
this rebuild the entire set
btVector3 can be used to represent 3D points and vectors.
int getEscapeNodeIndex(int nodeindex) const
btPrimitiveManagerBase * m_primitive_manager
bool boxQuery(const btAABB &box, btAlignedObjectArray< int > &collided_results) const
returns the indices of the primitives in the m_primitive_manager
void resize(int newsize, const T &fillData=T())
int getNodeData(int nodeindex) const
Structure for containing Boxes.
int getNodeCount() const
node count
int getLeftNode(int nodeindex) const
int getRightNode(int nodeindex) const
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 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
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
bool has_collision(const btAABB &other) const
int maxAxis() const
Return the axis with the largest value Note return values are 0,1,2 for x, y, or z.