27 #ifdef TRI_COLLISION_PROFILING
31 float g_q_accum_tree_collision_time = 0;
32 int g_q_count_traversing = 0;
35 void bt_begin_gim02_q_tree_time()
37 g_q_tree_clock.
reset();
40 void bt_end_gim02_q_tree_time()
43 g_q_count_traversing++;
48 float btGImpactQuantizedBvh::getAverageTreeCollisionTime()
50 if(g_q_count_traversing == 0)
return 0;
52 float avgtime = g_q_accum_tree_collision_time;
53 avgtime /= (float)g_q_count_traversing;
55 g_q_accum_tree_collision_time = 0;
56 g_q_count_traversing = 0;
65 #endif //TRI_COLLISION_PROFILING
76 for (
int i=0;i<primitive_boxes.
size() ;i++ )
78 global_bound.
merge(primitive_boxes[i].m_bound);
96 int numIndices = endIndex-startIndex;
98 for (i=startIndex;i<endIndex;i++)
101 primitive_boxes[i].m_bound.m_min);
106 for (i=startIndex;i<endIndex;i++)
109 primitive_boxes[i].m_bound.m_min);
111 diff2 = diff2 * diff2;
122 int endIndex,
int splitAxis)
125 int splitIndex =startIndex;
126 int numIndices = endIndex - startIndex;
132 for (i=startIndex;i<endIndex;i++)
135 primitive_boxes[i].m_bound.m_min);
140 splitValue = means[splitAxis];
144 for (i=startIndex;i<endIndex;i++)
147 primitive_boxes[i].m_bound.m_min);
148 if (center[splitAxis] > splitValue)
151 primitive_boxes.
swap(i,splitIndex);
166 int rangeBalancedIndices = numIndices/3;
167 bool unbalanced = ((splitIndex<=(startIndex+rangeBalancedIndices)) || (splitIndex >=(endIndex-1-rangeBalancedIndices)));
171 splitIndex = startIndex+ (numIndices>>1);
174 btAssert(!((splitIndex==startIndex) || (splitIndex == (endIndex))));
188 if ((endIndex-startIndex)==1)
191 setNodeBound(curIndex,primitive_boxes[startIndex].m_bound);
192 m_node_array[curIndex].setDataIndex(primitive_boxes[startIndex].m_data);
202 primitive_boxes,startIndex,endIndex,
212 for (
int i=startIndex;i<endIndex;i++)
214 node_bound.
merge(primitive_boxes[i].m_bound);
271 bound.
merge(temp_box);
278 bound.
merge(temp_box);
293 for (
int i = 0;i<primitive_boxes.
size() ;i++ )
296 primitive_boxes[i].m_data = i;
310 unsigned short quantizedMin[3];
311 unsigned short quantizedMax[3];
317 while (curIndex < numNodes)
325 if (isleafnode && aabbOverlap)
330 if (aabbOverlap || isleafnode)
341 if(collided_results.
size()>0)
return true;
355 while (curIndex < numNodes)
362 bool aabbOverlap = bound.
collide_ray(ray_origin,ray_dir);
365 if (isleafnode && aabbOverlap)
370 if (aabbOverlap || isleafnode)
381 if(collided_results.
size()>0)
return true;
389 int node0 ,
int node1,
bool complete_primitive_tests)
408 int node0,
int node1,
bool complete_primitive_tests)
414 boxset0,boxset1,trans_cache_1to0,
415 node0,node1,complete_primitive_tests) ==
false)
return;
433 collision_pairs,trans_cache_1to0,
439 collision_pairs,trans_cache_1to0,
453 collision_pairs,trans_cache_1to0,
461 collision_pairs,trans_cache_1to0,
474 collision_pairs,trans_cache_1to0,
481 collision_pairs,trans_cache_1to0,
489 collision_pairs,trans_cache_1to0,
496 collision_pairs,trans_cache_1to0,
515 #ifdef TRI_COLLISION_PROFILING
516 bt_begin_gim02_q_tree_time();
517 #endif //TRI_COLLISION_PROFILING
521 &collision_pairs,trans_cache_1to0,0,0,
true);
522 #ifdef TRI_COLLISION_PROFILING
523 bt_end_gim02_q_tree_time();
524 #endif //TRI_COLLISION_PROFILING
int getRightNode(int nodeindex) const
void build_tree(GIM_BVH_DATA_ARRAY &primitive_boxes)
prototype functions for box tree management
void push_back(const T &_Val)
void calc_quantization(GIM_BVH_DATA_ARRAY &primitive_boxes, btScalar boundMargin=btScalar(1.0))
int _calc_splitting_axis(GIM_BVH_DATA_ARRAY &primitive_boxes, int startIndex, int endIndex)
bool testQuantizedBoxOverlapp(int node_index, unsigned short *quantizedMin, unsigned short *quantizedMax) const
btVector3 m_bvhQuantization
int getNodeData(int nodeindex) const
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 reset()
Resets the initial reference time.
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
void merge(const btAABB &box)
Merges a Box.
btQuantizedBvhTree m_box_tree
void swap(int index0, int index1)
bool isLeafNode(int nodeindex) const
tells if the node is a leaf
void push_pair(int index1, int index2)
int size() const
return the number of elements in the array
void setNodeBound(int nodeindex, const btAABB &bound)
int getLeftNode(int nodeindex) const
static void _find_quantized_collision_pairs_recursive(const btGImpactQuantizedBvh *boxset0, const btGImpactQuantizedBvh *boxset1, btPairSet *collision_pairs, const BT_BOX_BOX_TRANSFORM_CACHE &trans_cache_1to0, int node0, int node1, bool complete_primitive_tests)
int getNodeCount() const
node count
virtual void get_primitive_box(int prim_index, btAABB &primbox) const =0
bool collide_ray(const btVector3 &vorigin, const btVector3 &vdir) const
Finds the Ray intersection parameter.
GIM_QUANTIZED_BVH_NODE_ARRAY m_node_array
btVector3 can be used to represent 3D points and vectors.
void bt_calc_quantization_parameters(btVector3 &outMinBound, btVector3 &outMaxBound, btVector3 &bvhQuantization, const btVector3 &srcMinBound, const btVector3 &srcMaxBound, btScalar quantizationMargin)
void resize(int newsize, const T &fillData=T())
btPrimitiveManagerBase * m_primitive_manager
bool _quantized_node_collision(const btGImpactQuantizedBvh *boxset0, const btGImpactQuantizedBvh *boxset1, const BT_BOX_BOX_TRANSFORM_CACHE &trans_cache_1to0, int node0, int node1, bool complete_primitive_tests)
bool boxQuery(const btAABB &box, btAlignedObjectArray< int > &collided_results) const
returns the indices of the primitives in the m_primitive_manager
int getEscapeNodeIndex(int nodeindex) const
int _sort_and_calc_splitting_index(GIM_BVH_DATA_ARRAY &primitive_boxes, int startIndex, int endIndex, int splitAxis)
void quantizePoint(unsigned short *quantizedpoint, const btVector3 &point) const
static void find_collision(const btGImpactQuantizedBvh *boxset1, const btTransform &trans1, const btGImpactQuantizedBvh *boxset2, const btTransform &trans2, btPairSet &collision_pairs)
void getNodeBound(int nodeindex, btAABB &bound) const
Structure for containing Boxes.
void setNodeBound(int nodeindex, const btAABB &bound)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
void buildSet()
this rebuild the entire set
int maxAxis() const
Return the axis with the largest value Note return values are 0,1,2 for x, y, or z.
void _build_sub_tree(GIM_BVH_DATA_ARRAY &primitive_boxes, int startIndex, int endIndex)