1 #ifndef GIM_BOX_SET_H_INCLUDED 2 #define GIM_BOX_SET_H_INCLUDED 96 virtual bool is_trimesh() = 0;
97 virtual GUINT get_primitive_count() = 0;
98 virtual void get_primitive_box(
GUINT prim_index ,
GIM_AABB & primbox) = 0;
99 virtual void get_primitive_triangle(
GUINT prim_index,
GIM_TRIANGLE & triangle) = 0;
128 return (!m_left && !m_right);
139 GUINT _sort_and_calc_splitting_index(
158 m_node_array.
clear();
171 return m_node_array[nodeindex].is_leaf_node();
176 return m_node_array[nodeindex].
m_data;
181 bound = m_node_array[nodeindex].m_bound;
186 m_node_array[nodeindex].m_bound = bound;
191 return m_node_array[nodeindex].m_left;
196 return m_node_array[nodeindex].m_right;
201 return m_node_array[nodeindex].m_escapeIndex;
214 template<
typename _GIM_PRIMITIVE_MANAGER_PROTOTYPE,
typename _GIM_BOX_TREE_PROTOTYPE>
224 GUINT nodecount = getNodeCount();
227 if(isLeafNode(nodecount))
230 m_primitive_manager.get_primitive_box(getNodeData(nodecount),leafbox);
231 setNodeBound(nodecount,leafbox);
236 GUINT childindex = getLeftNodeIndex(nodecount);
238 getNodeBound(childindex,bound);
240 childindex = getRightNodeIndex(nodecount);
242 getNodeBound(childindex,bound2);
245 setNodeBound(nodecount,bound);
258 getNodeBound(0, totalbox);
264 m_primitive_manager = primitive_manager;
269 return m_primitive_manager;
274 return m_primitive_manager;
291 primitive_boxes.
resize(m_primitive_manager.get_primitive_count(),
false);
293 for (
GUINT i = 0;i<primitive_boxes.
size() ;i++ )
295 m_primitive_manager.get_primitive_box(i,primitive_boxes[i].m_bound);
296 primitive_boxes[i].
m_data = i;
299 m_box_tree.build_tree(primitive_boxes);
306 GUINT numNodes = getNodeCount();
308 while (curIndex < numNodes)
311 getNodeBound(curIndex,bound);
316 bool isleafnode = isLeafNode(curIndex);
318 if (isleafnode && aabbOverlap)
320 collided_results.
push_back(getNodeData(curIndex));
323 if (aabbOverlap || isleafnode)
331 curIndex+= getScapeNodeIndex(curIndex);
334 if(collided_results.
size()>0)
return true;
344 return boxQuery(transbox,collided_results);
353 GUINT numNodes = getNodeCount();
355 while (curIndex < numNodes)
358 getNodeBound(curIndex,bound);
362 bool aabbOverlap = bound.
collide_ray(ray_origin,ray_dir);
363 bool isleafnode = isLeafNode(curIndex);
365 if (isleafnode && aabbOverlap)
367 collided_results.
push_back(getNodeData( curIndex));
370 if (aabbOverlap || isleafnode)
378 curIndex+= getScapeNodeIndex(curIndex);
381 if(collided_results.
size()>0)
return true;
394 return m_primitive_manager.is_trimesh();
400 return m_box_tree.getNodeCount();
406 return m_box_tree.isLeafNode(nodeindex);
411 return m_box_tree.getNodeData(nodeindex);
416 m_box_tree.getNodeBound(nodeindex, bound);
421 m_box_tree.setNodeBound(nodeindex, bound);
426 return m_box_tree.getLeftNodeIndex(nodeindex);
431 return m_box_tree.getRightNodeIndex(nodeindex);
436 return m_box_tree.getScapeNodeIndex(nodeindex);
441 m_primitive_manager.get_primitive_triangle(getNodeData(nodeindex),triangle);
450 template<
typename _GIM_PRIMITIVE_MANAGER_PROTOTYPE>
462 template<
typename BOX_SET_CLASS0,
typename BOX_SET_CLASS1>
496 if(node0_has_triangle)
return;
497 m_boxset0->getNodeTriangle(node0,m_tri0);
504 node0_has_triangle =
true;
509 if(node1_has_triangle)
return;
510 m_boxset1->getNodeTriangle(node1,m_tri1);
517 node1_has_triangle =
true;
522 if(node0 == current_node0)
return;
523 m_boxset0->getNodeBound(node0,m_box0);
524 node0_is_leaf = m_boxset0->isLeafNode(node0);
525 node0_has_triangle =
false;
526 current_node0 = node0;
531 if(node1 == current_node1)
return;
532 m_boxset1->getNodeBound(node1,m_box1);
533 node1_is_leaf = m_boxset1->isLeafNode(node1);
534 node1_has_triangle =
false;
535 current_node1 = node1;
540 retrieve_node0_info(node0);
541 retrieve_node1_info(node1);
543 if(!result)
return false;
545 if(t0_is_trimesh && node0_is_leaf)
548 retrieve_node0_triangle(node0);
557 if(!result)
return false;
560 else if(t1_is_trimesh && node1_is_leaf)
563 retrieve_node1_triangle(node1);
572 if(!result)
return false;
588 while(stack_collisions.
size())
594 if(node_collision(node0,node1))
600 m_collision_pairs->
push_pair(m_boxset0->getNodeData(node0),m_boxset1->getNodeData(node1));
605 stack_collisions.
push_pair(node0,m_boxset1->getLeftNodeIndex(node1));
608 stack_collisions.
push_pair(node0,m_boxset1->getRightNodeIndex(node1));
616 stack_collisions.
push_pair(m_boxset0->getLeftNodeIndex(node0),node1);
618 stack_collisions.
push_pair(m_boxset0->getRightNodeIndex(node0),node1);
622 GUINT left0 = m_boxset0->getLeftNodeIndex(node0);
623 GUINT right0 = m_boxset0->getRightNodeIndex(node0);
624 GUINT left1 = m_boxset1->getLeftNodeIndex(node1);
625 GUINT right1 = m_boxset1->getRightNodeIndex(node1);
629 stack_collisions.
push_pair(left0,right1);
631 stack_collisions.
push_pair(right0,left1);
633 stack_collisions.
push_pair(right0,right1);
643 BOX_SET_CLASS1 * boxset2,
const btTransform & trans2,
644 gim_pair_set & collision_pairs,
bool complete_primitive_tests =
true)
646 m_collision_pairs = &collision_pairs;
652 trans_cache_0to1 = trans2.
inverse();
653 trans_cache_0to1 *= trans1;
656 if(complete_primitive_tests)
658 t0_is_trimesh = boxset1->getPrimitiveManager().is_trimesh();
659 t1_is_trimesh = boxset2->getPrimitiveManager().is_trimesh();
663 t0_is_trimesh =
false;
664 t1_is_trimesh =
false;
667 find_collision_pairs();
672 #endif // GIM_BOXPRUNING_H_INCLUDED void find_collision(BOX_SET_CLASS0 *boxset1, const btTransform &trans1, BOX_SET_CLASS1 *boxset2, const btTransform &trans2, gim_pair_set &collision_pairs, bool complete_primitive_tests=true)
_GIM_PRIMITIVE_MANAGER_PROTOTYPE m_primitive_manager
GUINT m_data
primitive index if apply
BOX_SET_CLASS0 * m_boxset0
GUINT m_right
Right subtree.
bool isLeafNode(GUINT nodeindex) const
tells if the node is a leaf
void push_pair(GUINT index1, GUINT index2)
bool node_collision(GUINT node0, GUINT node1)
BOX_SET_CLASS1 * m_boxset1
GUINT m_left
Left subtree.
GIM_BOX_TREE_TEMPLATE_SET()
GIM_PAIR(GUINT index1, GUINT index2)
#define G_UINT_INFINITY
A very very high value.
GUINT getRightNodeIndex(GUINT nodeindex) const
bool isLeafNode(GUINT nodeindex) const
tells if the node is a leaf
GIM_BOX_SET collision methods.
void buildSet()
this rebuild the entire set
bool has_collision(const GIM_AABB &other) const
#define SIMD_FORCE_INLINE
void getNodeTriangle(GUINT nodeindex, GIM_TRIANGLE &triangle) const
void resize(GUINT size, bool call_constructor=true, const T &fillData=T())
void setPrimitiveManager(const _GIM_PRIMITIVE_MANAGER_PROTOTYPE &primitive_manager)
virtual ~GIM_PRIMITIVE_MANAGER_PROTOTYPE()
GUINT getNodeCount() const
node count
void retrieve_node0_triangle(GUINT node0)
GUINT getRightNodeIndex(GUINT nodeindex) const
_GIM_PRIMITIVE_MANAGER_PROTOTYPE & getPrimitiveManager()
GUINT getNodeCount() const
node count
GUINT getLeftNodeIndex(GUINT nodeindex) const
bool collide_ray(const btVector3 &vorigin, const btVector3 &vdir)
Finds the Ray intersection parameter.
GIM_AABB getGlobalBox() const
void getNodeBound(GUINT nodeindex, GIM_AABB &bound) const
void get_plane(btVector4 &plane) const
void find_collision_pairs()
bool boxQuery(const GIM_AABB &box, gim_array< GUINT > &collided_results) const
returns the indices of the primitives in the m_primitive_manager
GUINT m_escapeIndex
Scape index for traversing.
_GIM_BOX_TREE_PROTOTYPE m_box_tree
GUINT getNodeData(GUINT nodeindex) const
Class for colliding triangles.
void update()
node manager prototype functions
void retrieve_node1_info(GUINT node1)
bool is_leaf_node() const
Very simple array container with fast access and simd memory.
void setNodeBound(GUINT nodeindex, const GIM_AABB &bound)
bool boxQueryTrans(const GIM_AABB &box, const btTransform &transform, gim_array< GUINT > &collided_results) const
returns the indices of the primitives in the m_primitive_manager
Basic Box tree structure.
GIM_BOX_BOX_TRANSFORM_CACHE trans_cache_1to0
btVector3 can be used to represent 3D points and vectors.
GUINT getScapeNodeIndex(GUINT nodeindex) const
void push_pair_inv(GUINT index1, GUINT index2)
bool overlapping_trans_cache(const GIM_AABB &box, const GIM_BOX_BOX_TRANSFORM_CACHE &transcache, bool fulltest)
transcache is the transformation cache from box to this AABB
GUINT getNodeData(GUINT nodeindex) const
void retrieve_node0_info(GUINT node0)
bool rayQuery(const btVector3 &ray_dir, const btVector3 &ray_origin, gim_array< GUINT > &collided_results) const
returns the indices of the primitives in the m_primitive_manager
gim_pair_set * m_collision_pairs
GIM_PAIR(const GIM_PAIR &p)
void appy_transform(const btTransform &trans)
Apply a transform to an AABB.
bool isTrimesh() const
tells if this set is a trimesh
void retrieve_node1_triangle(GUINT node1)
void setNodeBound(GUINT nodeindex, const GIM_AABB &bound)
Generic Box Tree Template.
gim_array< GIM_BOX_TREE_NODE > m_node_array
Prototype Base class for primitive classification.
bool collide_triangle_exact(const btVector3 &p1, const btVector3 &p2, const btVector3 &p3, const btVector4 &triangle_plane)
test for a triangle, with edges
void getNodeBound(GUINT nodeindex, GIM_AABB &bound) const
Node Structure for trees.
bool reserve(GUINT size)
public operations
void push_back(const T &obj)
const _GIM_PRIMITIVE_MANAGER_PROTOTYPE & getPrimitiveManager() const
btTransform trans_cache_0to1
void increment_margin(btScalar margin)
void merge(const GIM_AABB &box)
Merges a Box.
GUINT getScapeNodeIndex(GUINT nodeindex) const
GUINT getLeftNodeIndex(GUINT nodeindex) const
bool hasHierarchy() const
tells if this set has hierarcht