1 #ifndef GIM_BOX_SET_H_INCLUDED
2 #define GIM_BOX_SET_H_INCLUDED
128 return (!m_left && !m_right);
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>
230 m_primitive_manager.get_primitive_box(
getNodeData(nodecount),leafbox);
264 m_primitive_manager = 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);
308 while (curIndex < numNodes)
318 if (isleafnode && aabbOverlap)
323 if (aabbOverlap || isleafnode)
334 if(collided_results.
size()>0)
return true;
344 return boxQuery(transbox,collided_results);
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;
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;
543 if(!result)
return false;
545 if(t0_is_trimesh && node0_is_leaf)
557 if(!result)
return false;
560 else if(t1_is_trimesh && node1_is_leaf)
572 if(!result)
return false;
588 while(stack_collisions.
size())
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;
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
void build_tree(gim_array< GIM_AABB_DATA > &primitive_boxes)
prototype functions for box tree management
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.
virtual GUINT get_primitive_count()=0
_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
virtual bool is_trimesh()=0
determines if this manager consist on only triangles, which special case will be optimized ...
GUINT getNodeData(GUINT nodeindex) const
void retrieve_node0_info(GUINT node0)
GUINT _sort_and_calc_splitting_index(gim_array< GIM_AABB_DATA > &primitive_boxes, GUINT startIndex, GUINT endIndex, GUINT splitAxis)
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)
virtual void get_primitive_box(GUINT prim_index, GIM_AABB &primbox)=0
virtual void get_primitive_triangle(GUINT prim_index, GIM_TRIANGLE &triangle)=0
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.
GUINT _calc_splitting_axis(gim_array< GIM_AABB_DATA > &primitive_boxes, GUINT startIndex, GUINT endIndex)
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 GIM_PAIR &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
void _build_sub_tree(gim_array< GIM_AABB_DATA > &primitive_boxes, GUINT startIndex, GUINT endIndex)
GUINT getLeftNodeIndex(GUINT nodeindex) const
bool hasHierarchy() const
tells if this set has hierarcht