27 #ifdef TRI_COLLISION_PROFILING 30 float g_q_accum_tree_collision_time = 0;
31 int g_q_count_traversing = 0;
33 void bt_begin_gim02_q_tree_time()
35 g_q_tree_clock.
reset();
38 void bt_end_gim02_q_tree_time()
41 g_q_count_traversing++;
45 float btGImpactQuantizedBvh::getAverageTreeCollisionTime()
47 if (g_q_count_traversing == 0)
return 0;
49 float avgtime = g_q_accum_tree_collision_time;
50 avgtime /= (float)g_q_count_traversing;
52 g_q_accum_tree_collision_time = 0;
53 g_q_count_traversing = 0;
61 #endif //TRI_COLLISION_PROFILING 72 for (
int i = 0; i < primitive_boxes.
size(); i++)
74 global_bound.
merge(primitive_boxes[i].m_bound);
88 int numIndices = endIndex - startIndex;
90 for (i = startIndex; i < endIndex; i++)
93 primitive_boxes[i].m_bound.m_min);
98 for (i = startIndex; i < endIndex; i++)
101 primitive_boxes[i].m_bound.m_min);
103 diff2 = diff2 * diff2;
113 int endIndex,
int splitAxis)
116 int splitIndex = startIndex;
117 int numIndices = endIndex - startIndex;
123 for (i = startIndex; i < endIndex; i++)
126 primitive_boxes[i].m_bound.m_min);
131 splitValue = means[splitAxis];
134 for (i = startIndex; i < endIndex; i++)
137 primitive_boxes[i].m_bound.m_min);
138 if (center[splitAxis] > splitValue)
141 primitive_boxes.
swap(i, splitIndex);
156 int rangeBalancedIndices = numIndices / 3;
157 bool unbalanced = ((splitIndex <= (startIndex + rangeBalancedIndices)) || (splitIndex >= (endIndex - 1 - rangeBalancedIndices)));
161 splitIndex = startIndex + (numIndices >> 1);
164 btAssert(!((splitIndex == startIndex) || (splitIndex == (endIndex))));
174 btAssert((endIndex - startIndex) > 0);
176 if ((endIndex - startIndex) == 1)
179 setNodeBound(curIndex, primitive_boxes[startIndex].m_bound);
180 m_node_array[curIndex].setDataIndex(primitive_boxes[startIndex].m_data);
190 primitive_boxes, startIndex, endIndex,
199 for (
int i = startIndex; i < endIndex; i++)
201 node_bound.
merge(primitive_boxes[i].m_bound);
254 bound.
merge(temp_box);
261 bound.
merge(temp_box);
276 for (
int i = 0; i < primitive_boxes.
size(); i++)
279 primitive_boxes[i].m_data = i;
293 unsigned short quantizedMin[3];
294 unsigned short quantizedMax[3];
299 while (curIndex < numNodes)
306 if (isleafnode && aabbOverlap)
311 if (aabbOverlap || isleafnode)
322 if (collided_results.
size() > 0)
return true;
334 while (curIndex < numNodes)
341 bool aabbOverlap = bound.
collide_ray(ray_origin, ray_dir);
344 if (isleafnode && aabbOverlap)
349 if (aabbOverlap || isleafnode)
360 if (collided_results.
size() > 0)
return true;
367 int node0,
int node1,
bool complete_primitive_tests)
384 int node0,
int node1,
bool complete_primitive_tests)
387 boxset0, boxset1, trans_cache_1to0,
388 node0, node1, complete_primitive_tests) ==
false)
return;
405 collision_pairs, trans_cache_1to0,
411 collision_pairs, trans_cache_1to0,
422 collision_pairs, trans_cache_1to0,
429 collision_pairs, trans_cache_1to0,
438 collision_pairs, trans_cache_1to0,
445 collision_pairs, trans_cache_1to0,
452 collision_pairs, trans_cache_1to0,
459 collision_pairs, trans_cache_1to0,
476 #ifdef TRI_COLLISION_PROFILING 477 bt_begin_gim02_q_tree_time();
478 #endif //TRI_COLLISION_PROFILING 482 &collision_pairs, trans_cache_1to0, 0, 0,
true);
483 #ifdef TRI_COLLISION_PROFILING 484 bt_end_gim02_q_tree_time();
485 #endif //TRI_COLLISION_PROFILING 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)
btVector3 m_bvhQuantization
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
virtual int get_primitive_count() const =0
int getNodeData(int nodeindex) const
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 testQuantizedBoxOverlapp(int node_index, unsigned short *quantizedMin, unsigned short *quantizedMax) const
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.
void merge(const btAABB &box)
Merges a Box.
int getEscapeNodeIndex(int nodeindex) const
btQuantizedBvhTree m_box_tree
void swap(int index0, int index1)
void push_pair(int index1, int index2)
bool boxQuery(const btAABB &box, btAlignedObjectArray< int > &collided_results) const
returns the indices of the primitives in the m_primitive_manager
void setNodeBound(int nodeindex, const btAABB &bound)
bool isLeafNode(int nodeindex) const
tells if the node is a leaf
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)
void quantizePoint(unsigned short *quantizedpoint, const btVector3 &point) const
unsigned long long int getTimeMicroseconds()
Returns the time in us since the last call to reset or since the Clock was created.
virtual void get_primitive_box(int prim_index, btAABB &primbox) const =0
int getNodeCount() const
node count
GIM_QUANTIZED_BVH_NODE_ARRAY m_node_array
btVector3 can be used to represent 3D points and vectors.
bool collide_ray(const btVector3 &vorigin, const btVector3 &vdir) const
Finds the Ray intersection parameter.
int size() const
return the number of elements in the array
void getNodeBound(int nodeindex, btAABB &bound) const
void bt_calc_quantization_parameters(btVector3 &outMinBound, btVector3 &outMaxBound, btVector3 &bvhQuantization, const btVector3 &srcMinBound, const btVector3 &srcMaxBound, btScalar quantizationMargin)
int getLeftNode(int nodeindex) const
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)
int getRightNode(int nodeindex) const
int maxAxis() const
Return the axis with the largest value Note return values are 0,1,2 for x, y, or z.
int _sort_and_calc_splitting_index(GIM_BVH_DATA_ARRAY &primitive_boxes, int startIndex, int endIndex, int splitAxis)
static void find_collision(const btGImpactQuantizedBvh *boxset1, const btTransform &trans1, const btGImpactQuantizedBvh *boxset2, const btTransform &trans2, btPairSet &collision_pairs)
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
void _build_sub_tree(GIM_BVH_DATA_ARRAY &primitive_boxes, int startIndex, int endIndex)