Bullet Collision Detection & Physics Library: gim_box_set.h Source File

Bullet Collision Detection & Physics Library

gim_box_set.h
Go to the documentation of this file.
1 #ifndef GIM_BOX_SET_H_INCLUDED
2 #define GIM_BOX_SET_H_INCLUDED
3
7 /*
8 -----------------------------------------------------------------------------
9 This source file is part of GIMPACT Library.
10
11 For the latest info, see http://gimpact.sourceforge.net/
12
13 Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
14 email: projectileman@yahoo.com
15
16 This library is free software; you can redistribute it and/or
17 modify it under the terms of EITHER:
18 (1) The GNU Lesser General Public License as published by the Free
19 Software Foundation; either version 2.1 of the License, or (at
20 your option) any later version. The text of the GNU Lesser
21 General Public License is included with this library in the
22 file GIMPACT-LICENSE-LGPL.TXT.
23 (2) The BSD-style license that is included with this library in
24 the file GIMPACT-LICENSE-BSD.TXT.
25 (3) The zlib/libpng license that is included with this library in
26 the file GIMPACT-LICENSE-ZLIB.TXT.
27
28 This library is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
31 GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
32
33 -----------------------------------------------------------------------------
34 */
35
36 #include "gim_array.h"
37 #include "gim_radixsort.h"
38 #include "gim_box_collision.h"
39 #include "gim_tri_collision.h"
40 #include "gim_pair.h"
41
43 class gim_pair_set : public gim_array<GIM_PAIR>
44 {
45 public:
46 gim_pair_set() : gim_array<GIM_PAIR>(32)
47 {
48 }
49 inline void push_pair(GUINT index1, GUINT index2)
50 {
51 push_back(GIM_PAIR(index1, index2));
52 }
53
54 inline void push_pair_inv(GUINT index1, GUINT index2)
55 {
56 push_back(GIM_PAIR(index2, index1));
57 }
58 };
59
61
66 class GIM_PRIMITIVE_MANAGER_PROTOTYPE
67 {
68 public:
69 virtual ~GIM_PRIMITIVE_MANAGER_PROTOTYPE() {}
71 virtual bool is_trimesh() = 0;
72 virtual GUINT get_primitive_count() = 0;
73 virtual void get_primitive_box(GUINT prim_index, GIM_AABB& primbox) = 0;
74 virtual void get_primitive_triangle(GUINT prim_index, GIM_TRIANGLE& triangle) = 0;
75 };
76
77 struct GIM_AABB_DATA
78 {
79 GIM_AABB m_bound;
80 GUINT m_data;
81 };
82
84 struct GIM_BOX_TREE_NODE
85 {
86 GIM_AABB m_bound;
87 GUINT m_left;
88 GUINT m_right;
89 GUINT m_escapeIndex;
90 GUINT m_data;
91
92 GIM_BOX_TREE_NODE()
93 {
94 m_left = 0;
95 m_right = 0;
96 m_escapeIndex = 0;
97 m_data = 0;
98 }
99
100 SIMD_FORCE_INLINE bool is_leaf_node() const
101 {
102 return (!m_left && !m_right);
103 }
104 };
105
107 class GIM_BOX_TREE
108 {
109 protected:
110 GUINT m_num_nodes;
111 gim_array<GIM_BOX_TREE_NODE> m_node_array;
112
113 protected:
114 GUINT _sort_and_calc_splitting_index(
115 gim_array<GIM_AABB_DATA>& primitive_boxes,
116 GUINT startIndex, GUINT endIndex, GUINT splitAxis);
117
118 GUINT _calc_splitting_axis(gim_array<GIM_AABB_DATA>& primitive_boxes, GUINT startIndex, GUINT endIndex);
119
120 void _build_sub_tree(gim_array<GIM_AABB_DATA>& primitive_boxes, GUINT startIndex, GUINT endIndex);
121
122 public:
123 GIM_BOX_TREE()
124 {
125 m_num_nodes = 0;
126 }
127
130 void build_tree(gim_array<GIM_AABB_DATA>& primitive_boxes);
131
132 SIMD_FORCE_INLINE void clearNodes()
133 {
134 m_node_array.clear();
135 m_num_nodes = 0;
136 }
137
139 SIMD_FORCE_INLINE GUINT getNodeCount() const
140 {
141 return m_num_nodes;
142 }
143
145 SIMD_FORCE_INLINE bool isLeafNode(GUINT nodeindex) const
146 {
147 return m_node_array[nodeindex].is_leaf_node();
148 }
149
150 SIMD_FORCE_INLINE GUINT getNodeData(GUINT nodeindex) const
151 {
152 return m_node_array[nodeindex].m_data;
153 }
154
155 SIMD_FORCE_INLINE void getNodeBound(GUINT nodeindex, GIM_AABB& bound) const
156 {
157 bound = m_node_array[nodeindex].m_bound;
158 }
159
160 SIMD_FORCE_INLINE void setNodeBound(GUINT nodeindex, const GIM_AABB& bound)
161 {
162 m_node_array[nodeindex].m_bound = bound;
163 }
164
165 SIMD_FORCE_INLINE GUINT getLeftNodeIndex(GUINT nodeindex) const
166 {
167 return m_node_array[nodeindex].m_left;
168 }
169
170 SIMD_FORCE_INLINE GUINT getRightNodeIndex(GUINT nodeindex) const
171 {
172 return m_node_array[nodeindex].m_right;
173 }
174
175 SIMD_FORCE_INLINE GUINT getScapeNodeIndex(GUINT nodeindex) const
176 {
177 return m_node_array[nodeindex].m_escapeIndex;
178 }
179
181 };
182
184
189 template <typename _GIM_PRIMITIVE_MANAGER_PROTOTYPE, typename _GIM_BOX_TREE_PROTOTYPE>
190 class GIM_BOX_TREE_TEMPLATE_SET
191 {
192 protected:
193 _GIM_PRIMITIVE_MANAGER_PROTOTYPE m_primitive_manager;
194 _GIM_BOX_TREE_PROTOTYPE m_box_tree;
195
196 protected:
197 //stackless refit
198 SIMD_FORCE_INLINE void refit()
199 {
200 GUINT nodecount = getNodeCount();
201 while (nodecount--)
202 {
203 if (isLeafNode(nodecount))
204 {
205 GIM_AABB leafbox;
206 m_primitive_manager.get_primitive_box(getNodeData(nodecount), leafbox);
207 setNodeBound(nodecount, leafbox);
208 }
209 else
210 {
211 //get left bound
212 GUINT childindex = getLeftNodeIndex(nodecount);
213 GIM_AABB bound;
214 getNodeBound(childindex, bound);
215 //get right bound
216 childindex = getRightNodeIndex(nodecount);
217 GIM_AABB bound2;
218 getNodeBound(childindex, bound2);
219 bound.merge(bound2);
220
221 setNodeBound(nodecount, bound);
222 }
223 }
224 }
225
226 public:
227 GIM_BOX_TREE_TEMPLATE_SET()
228 {
229 }
230
231 SIMD_FORCE_INLINE GIM_AABB getGlobalBox() const
232 {
233 GIM_AABB totalbox;
234 getNodeBound(0, totalbox);
235 return totalbox;
236 }
237
238 SIMD_FORCE_INLINE void setPrimitiveManager(const _GIM_PRIMITIVE_MANAGER_PROTOTYPE& primitive_manager)
239 {
240 m_primitive_manager = primitive_manager;
241 }
242
243 const _GIM_PRIMITIVE_MANAGER_PROTOTYPE& getPrimitiveManager() const
244 {
245 return m_primitive_manager;
246 }
247
248 _GIM_PRIMITIVE_MANAGER_PROTOTYPE& getPrimitiveManager()
249 {
250 return m_primitive_manager;
251 }
252
255
257 SIMD_FORCE_INLINE void update()
258 {
259 refit();
260 }
261
263 SIMD_FORCE_INLINE void buildSet()
264 {
265 //obtain primitive boxes
266 gim_array<GIM_AABB_DATA> primitive_boxes;
267 primitive_boxes.resize(m_primitive_manager.get_primitive_count(), false);
268
269 for (GUINT i = 0; i < primitive_boxes.size(); i++)
270 {
271 m_primitive_manager.get_primitive_box(i, primitive_boxes[i].m_bound);
272 primitive_boxes[i].m_data = i;
273 }
274
275 m_box_tree.build_tree(primitive_boxes);
276 }
277
279 SIMD_FORCE_INLINE bool boxQuery(const GIM_AABB& box, gim_array<GUINT>& collided_results) const
280 {
281 GUINT curIndex = 0;
282 GUINT numNodes = getNodeCount();
283
284 while (curIndex < numNodes)
285 {
286 GIM_AABB bound;
287 getNodeBound(curIndex, bound);
288
289 //catch bugs in tree data
290
291 bool aabbOverlap = bound.has_collision(box);
292 bool isleafnode = isLeafNode(curIndex);
293
294 if (isleafnode && aabbOverlap)
295 {
296 collided_results.push_back(getNodeData(curIndex));
297 }
298
299 if (aabbOverlap || isleafnode)
300 {
301 //next subnode
302 curIndex++;
303 }
304 else
305 {
306 //skip node
307 curIndex += getScapeNodeIndex(curIndex);
308 }
309 }
310 if (collided_results.size() > 0) return true;
311 return false;
312 }
313
315 SIMD_FORCE_INLINE bool boxQueryTrans(const GIM_AABB& box,
316 const btTransform& transform, gim_array<GUINT>& collided_results) const
317 {
318 GIM_AABB transbox = box;
319 transbox.appy_transform(transform);
320 return boxQuery(transbox, collided_results);
321 }
322
324 SIMD_FORCE_INLINE bool rayQuery(
325 const btVector3& ray_dir, const btVector3& ray_origin,
326 gim_array<GUINT>& collided_results) const
327 {
328 GUINT curIndex = 0;
329 GUINT numNodes = getNodeCount();
330
331 while (curIndex < numNodes)
332 {
333 GIM_AABB bound;
334 getNodeBound(curIndex, bound);
335
336 //catch bugs in tree data
337
338 bool aabbOverlap = bound.collide_ray(ray_origin, ray_dir);
339 bool isleafnode = isLeafNode(curIndex);
340
341 if (isleafnode && aabbOverlap)
342 {
343 collided_results.push_back(getNodeData(curIndex));
344 }
345
346 if (aabbOverlap || isleafnode)
347 {
348 //next subnode
349 curIndex++;
350 }
351 else
352 {
353 //skip node
354 curIndex += getScapeNodeIndex(curIndex);
355 }
356 }
357 if (collided_results.size() > 0) return true;
358 return false;
359 }
360
362 SIMD_FORCE_INLINE bool hasHierarchy() const
363 {
364 return true;
365 }
366
368 SIMD_FORCE_INLINE bool isTrimesh() const
369 {
370 return m_primitive_manager.is_trimesh();
371 }
372
374 SIMD_FORCE_INLINE GUINT getNodeCount() const
375 {
376 return m_box_tree.getNodeCount();
377 }
378
380 SIMD_FORCE_INLINE bool isLeafNode(GUINT nodeindex) const
381 {
382 return m_box_tree.isLeafNode(nodeindex);
383 }
384
385 SIMD_FORCE_INLINE GUINT getNodeData(GUINT nodeindex) const
386 {
387 return m_box_tree.getNodeData(nodeindex);
388 }
389
390 SIMD_FORCE_INLINE void getNodeBound(GUINT nodeindex, GIM_AABB& bound) const
391 {
392 m_box_tree.getNodeBound(nodeindex, bound);
393 }
394
395 SIMD_FORCE_INLINE void setNodeBound(GUINT nodeindex, const GIM_AABB& bound)
396 {
397 m_box_tree.setNodeBound(nodeindex, bound);
398 }
399
400 SIMD_FORCE_INLINE GUINT getLeftNodeIndex(GUINT nodeindex) const
401 {
402 return m_box_tree.getLeftNodeIndex(nodeindex);
403 }
404
405 SIMD_FORCE_INLINE GUINT getRightNodeIndex(GUINT nodeindex) const
406 {
407 return m_box_tree.getRightNodeIndex(nodeindex);
408 }
409
410 SIMD_FORCE_INLINE GUINT getScapeNodeIndex(GUINT nodeindex) const
411 {
412 return m_box_tree.getScapeNodeIndex(nodeindex);
413 }
414
415 SIMD_FORCE_INLINE void getNodeTriangle(GUINT nodeindex, GIM_TRIANGLE& triangle) const
416 {
417 m_primitive_manager.get_primitive_triangle(getNodeData(nodeindex), triangle);
418 }
419 };
420
422
425 template <typename _GIM_PRIMITIVE_MANAGER_PROTOTYPE>
426 class GIM_BOX_TREE_SET : public GIM_BOX_TREE_TEMPLATE_SET<_GIM_PRIMITIVE_MANAGER_PROTOTYPE, GIM_BOX_TREE>
427 {
428 public:
429 };
430
432 template <typename BOX_SET_CLASS0, typename BOX_SET_CLASS1>
433 class GIM_TREE_TREE_COLLIDER
434 {
435 public:
436 gim_pair_set* m_collision_pairs;
437 BOX_SET_CLASS0* m_boxset0;
438 BOX_SET_CLASS1* m_boxset1;
439 GUINT current_node0;
440 GUINT current_node1;
441 bool node0_is_leaf;
442 bool node1_is_leaf;
443 bool t0_is_trimesh;
444 bool t1_is_trimesh;
445 bool node0_has_triangle;
446 bool node1_has_triangle;
447 GIM_AABB m_box0;
448 GIM_AABB m_box1;
449 GIM_BOX_BOX_TRANSFORM_CACHE trans_cache_1to0;
450 btTransform trans_cache_0to1;
451 GIM_TRIANGLE m_tri0;
452 btVector4 m_tri0_plane;
453 GIM_TRIANGLE m_tri1;
454 btVector4 m_tri1_plane;
455
456 public:
457 GIM_TREE_TREE_COLLIDER()
458 {
459 current_node0 = G_UINT_INFINITY;
460 current_node1 = G_UINT_INFINITY;
461 }
462
463 protected:
464 SIMD_FORCE_INLINE void retrieve_node0_triangle(GUINT node0)
465 {
466 if (node0_has_triangle) return;
467 m_boxset0->getNodeTriangle(node0, m_tri0);
468 //transform triangle
469 m_tri0.m_vertices[0] = trans_cache_0to1(m_tri0.m_vertices[0]);
470 m_tri0.m_vertices[1] = trans_cache_0to1(m_tri0.m_vertices[1]);
471 m_tri0.m_vertices[2] = trans_cache_0to1(m_tri0.m_vertices[2]);
472 m_tri0.get_plane(m_tri0_plane);
473
474 node0_has_triangle = true;
475 }
476
477 SIMD_FORCE_INLINE void retrieve_node1_triangle(GUINT node1)
478 {
479 if (node1_has_triangle) return;
480 m_boxset1->getNodeTriangle(node1, m_tri1);
481 //transform triangle
482 m_tri1.m_vertices[0] = trans_cache_1to0.transform(m_tri1.m_vertices[0]);
483 m_tri1.m_vertices[1] = trans_cache_1to0.transform(m_tri1.m_vertices[1]);
484 m_tri1.m_vertices[2] = trans_cache_1to0.transform(m_tri1.m_vertices[2]);
485 m_tri1.get_plane(m_tri1_plane);
486
487 node1_has_triangle = true;
488 }
489
490 SIMD_FORCE_INLINE void retrieve_node0_info(GUINT node0)
491 {
492 if (node0 == current_node0) return;
493 m_boxset0->getNodeBound(node0, m_box0);
494 node0_is_leaf = m_boxset0->isLeafNode(node0);
495 node0_has_triangle = false;
496 current_node0 = node0;
497 }
498
499 SIMD_FORCE_INLINE void retrieve_node1_info(GUINT node1)
500 {
501 if (node1 == current_node1) return;
502 m_boxset1->getNodeBound(node1, m_box1);
503 node1_is_leaf = m_boxset1->isLeafNode(node1);
504 node1_has_triangle = false;
505 current_node1 = node1;
506 }
507
508 SIMD_FORCE_INLINE bool node_collision(GUINT node0, GUINT node1)
509 {
510 retrieve_node0_info(node0);
511 retrieve_node1_info(node1);
512 bool result = m_box0.overlapping_trans_cache(m_box1, trans_cache_1to0, true);
513 if (!result) return false;
514
515 if (t0_is_trimesh && node0_is_leaf)
516 {
517 //perform primitive vs box collision
518 retrieve_node0_triangle(node0);
519 //do triangle vs box collision
520 m_box1.increment_margin(m_tri0.m_margin);
521
522 result = m_box1.collide_triangle_exact(
523 m_tri0.m_vertices[0], m_tri0.m_vertices[1], m_tri0.m_vertices[2], m_tri0_plane);
524
525 m_box1.increment_margin(-m_tri0.m_margin);
526
527 if (!result) return false;
528 return true;
529 }
530 else if (t1_is_trimesh && node1_is_leaf)
531 {
532 //perform primitive vs box collision
533 retrieve_node1_triangle(node1);
534 //do triangle vs box collision
535 m_box0.increment_margin(m_tri1.m_margin);
536
537 result = m_box0.collide_triangle_exact(
538 m_tri1.m_vertices[0], m_tri1.m_vertices[1], m_tri1.m_vertices[2], m_tri1_plane);
539
540 m_box0.increment_margin(-m_tri1.m_margin);
541
542 if (!result) return false;
543 return true;
544 }
545 return true;
546 }
547
548 //stackless collision routine
549 void find_collision_pairs()
550 {
551 gim_pair_set stack_collisions;
552 stack_collisions.reserve(32);
553
554 //add the first pair
555 stack_collisions.push_pair(0, 0);
556
557 while (stack_collisions.size())
558 {
559 //retrieve the last pair and pop
560 GUINT node0 = stack_collisions.back().m_index1;
561 GUINT node1 = stack_collisions.back().m_index2;
562 stack_collisions.pop_back();
563 if (node_collision(node0, node1)) // a collision is found
564 {
565 if (node0_is_leaf)
566 {
567 if (node1_is_leaf)
568 {
569 m_collision_pairs->push_pair(m_boxset0->getNodeData(node0), m_boxset1->getNodeData(node1));
570 }
571 else
572 {
573 //collide left
574 stack_collisions.push_pair(node0, m_boxset1->getLeftNodeIndex(node1));
575
576 //collide right
577 stack_collisions.push_pair(node0, m_boxset1->getRightNodeIndex(node1));
578 }
579 }
580 else
581 {
582 if (node1_is_leaf)
583 {
584 //collide left
585 stack_collisions.push_pair(m_boxset0->getLeftNodeIndex(node0), node1);
586 //collide right
587 stack_collisions.push_pair(m_boxset0->getRightNodeIndex(node0), node1);
588 }
589 else
590 {
591 GUINT left0 = m_boxset0->getLeftNodeIndex(node0);
592 GUINT right0 = m_boxset0->getRightNodeIndex(node0);
593 GUINT left1 = m_boxset1->getLeftNodeIndex(node1);
594 GUINT right1 = m_boxset1->getRightNodeIndex(node1);
595 //collide left
596 stack_collisions.push_pair(left0, left1);
597 //collide right
598 stack_collisions.push_pair(left0, right1);
599 //collide left
600 stack_collisions.push_pair(right0, left1);
601 //collide right
602 stack_collisions.push_pair(right0, right1);
603
604 } // else if node1 is not a leaf
605 } // else if node0 is not a leaf
606
607 } // if(node_collision(node0,node1))
608 } //while(stack_collisions.size())
609 }
610
611 public:
612 void find_collision(BOX_SET_CLASS0* boxset1, const btTransform& trans1,
613 BOX_SET_CLASS1* boxset2, const btTransform& trans2,
614 gim_pair_set& collision_pairs, bool complete_primitive_tests = true)
615 {
616 m_collision_pairs = &collision_pairs;
617 m_boxset0 = boxset1;
618 m_boxset1 = boxset2;
619
620 trans_cache_1to0.calc_from_homogenic(trans1, trans2);
621
622 trans_cache_0to1 = trans2.inverse();
623 trans_cache_0to1 *= trans1;
624
625 if (complete_primitive_tests)
626 {
627 t0_is_trimesh = boxset1->getPrimitiveManager().is_trimesh();
628 t1_is_trimesh = boxset2->getPrimitiveManager().is_trimesh();
629 }
630 else
631 {
632 t0_is_trimesh = false;
633 t1_is_trimesh = false;
634 }
635
636 find_collision_pairs();
637 }
638 };
639
640 #endif // GIM_BOXPRUNING_H_INCLUDED
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition: btScalar.h:98
GIM_AABB
Axis aligned box.
Definition: gim_box_collision.h:196
GIM_AABB::overlapping_trans_cache
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
Definition: gim_box_collision.h:458
GIM_AABB::collide_triangle_exact
bool collide_triangle_exact(const btVector3 &p1, const btVector3 &p2, const btVector3 &p3, const btVector4 &triangle_plane)
test for a triangle, with edges
Definition: gim_box_collision.h:518
GIM_AABB::merge
void merge(const GIM_AABB &box)
Merges a Box.
Definition: gim_box_collision.h:338
GIM_AABB::collide_ray
bool collide_ray(const btVector3 &vorigin, const btVector3 &vdir)
Finds the Ray intersection parameter.
Definition: gim_box_collision.h:400
GIM_AABB::appy_transform
void appy_transform(const btTransform &trans)
Apply a transform to an AABB.
Definition: gim_box_collision.h:322
GIM_AABB::has_collision
bool has_collision(const GIM_AABB &other) const
Definition: gim_box_collision.h:381
GIM_AABB::increment_margin
void increment_margin(btScalar margin)
Definition: gim_box_collision.h:263
GIM_BOX_BOX_TRANSFORM_CACHE
Class for transforming a model1 to the space of model0.
Definition: gim_box_collision.h:135
GIM_BOX_BOX_TRANSFORM_CACHE::transform
btVector3 transform(const btVector3 &point)
Definition: gim_box_collision.h:184
GIM_BOX_BOX_TRANSFORM_CACHE::calc_from_homogenic
void calc_from_homogenic(const btTransform &trans0, const btTransform &trans1)
Calc the transformation relative 1 to 0. Inverts matrics by transposing.
Definition: gim_box_collision.h:161
GIM_BOX_TREE_SET
Class for Box Tree Sets.
Definition: gim_box_set.h:427
GIM_BOX_TREE_TEMPLATE_SET
Generic Box Tree Template.
Definition: gim_box_set.h:191
GIM_BOX_TREE_TEMPLATE_SET::m_primitive_manager
_GIM_PRIMITIVE_MANAGER_PROTOTYPE m_primitive_manager
Definition: gim_box_set.h:193
GIM_BOX_TREE_TEMPLATE_SET::getNodeData
GUINT getNodeData(GUINT nodeindex) const
Definition: gim_box_set.h:385
GIM_BOX_TREE_TEMPLATE_SET::getLeftNodeIndex
GUINT getLeftNodeIndex(GUINT nodeindex) const
Definition: gim_box_set.h:400
GIM_BOX_TREE_TEMPLATE_SET::getPrimitiveManager
const _GIM_PRIMITIVE_MANAGER_PROTOTYPE & getPrimitiveManager() const
Definition: gim_box_set.h:243
GIM_BOX_TREE_TEMPLATE_SET::setPrimitiveManager
void setPrimitiveManager(const _GIM_PRIMITIVE_MANAGER_PROTOTYPE &primitive_manager)
Definition: gim_box_set.h:238
GIM_BOX_TREE_TEMPLATE_SET::GIM_BOX_TREE_TEMPLATE_SET
GIM_BOX_TREE_TEMPLATE_SET()
Definition: gim_box_set.h:227
GIM_BOX_TREE_TEMPLATE_SET::buildSet
void buildSet()
this rebuild the entire set
Definition: gim_box_set.h:263
GIM_BOX_TREE_TEMPLATE_SET::boxQuery
bool boxQuery(const GIM_AABB &box, gim_array< GUINT > &collided_results) const
returns the indices of the primitives in the m_primitive_manager
Definition: gim_box_set.h:279
GIM_BOX_TREE_TEMPLATE_SET::isLeafNode
bool isLeafNode(GUINT nodeindex) const
tells if the node is a leaf
Definition: gim_box_set.h:380
GIM_BOX_TREE_TEMPLATE_SET::hasHierarchy
bool hasHierarchy() const
tells if this set has hierarcht
Definition: gim_box_set.h:362
GIM_BOX_TREE_TEMPLATE_SET::getRightNodeIndex
GUINT getRightNodeIndex(GUINT nodeindex) const
Definition: gim_box_set.h:405
GIM_BOX_TREE_TEMPLATE_SET::update
void update()
node manager prototype functions
Definition: gim_box_set.h:257
GIM_BOX_TREE_TEMPLATE_SET::m_box_tree
_GIM_BOX_TREE_PROTOTYPE m_box_tree
Definition: gim_box_set.h:194
GIM_BOX_TREE_TEMPLATE_SET::isTrimesh
bool isTrimesh() const
tells if this set is a trimesh
Definition: gim_box_set.h:368
GIM_BOX_TREE_TEMPLATE_SET::getNodeCount
GUINT getNodeCount() const
node count
Definition: gim_box_set.h:374
GIM_BOX_TREE_TEMPLATE_SET::rayQuery
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
Definition: gim_box_set.h:324
GIM_BOX_TREE_TEMPLATE_SET::getNodeTriangle
void getNodeTriangle(GUINT nodeindex, GIM_TRIANGLE &triangle) const
Definition: gim_box_set.h:415
GIM_BOX_TREE_TEMPLATE_SET::refit
void refit()
Definition: gim_box_set.h:198
GIM_BOX_TREE_TEMPLATE_SET::getPrimitiveManager
_GIM_PRIMITIVE_MANAGER_PROTOTYPE & getPrimitiveManager()
Definition: gim_box_set.h:248
GIM_BOX_TREE_TEMPLATE_SET::setNodeBound
void setNodeBound(GUINT nodeindex, const GIM_AABB &bound)
Definition: gim_box_set.h:395
GIM_BOX_TREE_TEMPLATE_SET::getGlobalBox
GIM_AABB getGlobalBox() const
Definition: gim_box_set.h:231
GIM_BOX_TREE_TEMPLATE_SET::getNodeBound
void getNodeBound(GUINT nodeindex, GIM_AABB &bound) const
Definition: gim_box_set.h:390
GIM_BOX_TREE_TEMPLATE_SET::boxQueryTrans
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
Definition: gim_box_set.h:315
GIM_BOX_TREE_TEMPLATE_SET::getScapeNodeIndex
GUINT getScapeNodeIndex(GUINT nodeindex) const
Definition: gim_box_set.h:410
GIM_BOX_TREE
Basic Box tree structure.
Definition: gim_box_set.h:108
GIM_BOX_TREE::getScapeNodeIndex
GUINT getScapeNodeIndex(GUINT nodeindex) const
Definition: gim_box_set.h:175
GIM_BOX_TREE::getNodeBound
void getNodeBound(GUINT nodeindex, GIM_AABB &bound) const
Definition: gim_box_set.h:155
GIM_BOX_TREE::setNodeBound
void setNodeBound(GUINT nodeindex, const GIM_AABB &bound)
Definition: gim_box_set.h:160
GIM_BOX_TREE::GIM_BOX_TREE
GIM_BOX_TREE()
Definition: gim_box_set.h:123
GIM_BOX_TREE::clearNodes
void clearNodes()
Definition: gim_box_set.h:132
GIM_BOX_TREE::_calc_splitting_axis
GUINT _calc_splitting_axis(gim_array< GIM_AABB_DATA > &primitive_boxes, GUINT startIndex, GUINT endIndex)
Definition: gim_box_set.cpp:33
GIM_BOX_TREE::m_node_array
gim_array< GIM_BOX_TREE_NODE > m_node_array
Definition: gim_box_set.h:111
GIM_BOX_TREE::getLeftNodeIndex
GUINT getLeftNodeIndex(GUINT nodeindex) const
Definition: gim_box_set.h:165
GIM_BOX_TREE::getRightNodeIndex
GUINT getRightNodeIndex(GUINT nodeindex) const
Definition: gim_box_set.h:170
GIM_BOX_TREE::getNodeData
GUINT getNodeData(GUINT nodeindex) const
Definition: gim_box_set.h:150
GIM_BOX_TREE::isLeafNode
bool isLeafNode(GUINT nodeindex) const
tells if the node is a leaf
Definition: gim_box_set.h:145
GIM_BOX_TREE::_sort_and_calc_splitting_index
GUINT _sort_and_calc_splitting_index(gim_array< GIM_AABB_DATA > &primitive_boxes, GUINT startIndex, GUINT endIndex, GUINT splitAxis)
Definition: gim_box_set.cpp:63
GIM_BOX_TREE::m_num_nodes
GUINT m_num_nodes
Definition: gim_box_set.h:110
GIM_BOX_TREE::getNodeCount
GUINT getNodeCount() const
node count
Definition: gim_box_set.h:139
GIM_BOX_TREE::_build_sub_tree
void _build_sub_tree(gim_array< GIM_AABB_DATA > &primitive_boxes, GUINT startIndex, GUINT endIndex)
Definition: gim_box_set.cpp:115
GIM_BOX_TREE::build_tree
void build_tree(gim_array< GIM_AABB_DATA > &primitive_boxes)
prototype functions for box tree management
Definition: gim_box_set.cpp:167
GIM_PRIMITIVE_MANAGER_PROTOTYPE
Prototype Base class for primitive classification.
Definition: gim_box_set.h:67
GIM_PRIMITIVE_MANAGER_PROTOTYPE::get_primitive_box
virtual void get_primitive_box(GUINT prim_index, GIM_AABB &primbox)=0
GIM_PRIMITIVE_MANAGER_PROTOTYPE::get_primitive_count
virtual GUINT get_primitive_count()=0
GIM_PRIMITIVE_MANAGER_PROTOTYPE::is_trimesh
virtual bool is_trimesh()=0
determines if this manager consist on only triangles, which special case will be optimized
GIM_PRIMITIVE_MANAGER_PROTOTYPE::~GIM_PRIMITIVE_MANAGER_PROTOTYPE
virtual ~GIM_PRIMITIVE_MANAGER_PROTOTYPE()
Definition: gim_box_set.h:69
GIM_PRIMITIVE_MANAGER_PROTOTYPE::get_primitive_triangle
virtual void get_primitive_triangle(GUINT prim_index, GIM_TRIANGLE &triangle)=0
GIM_TREE_TREE_COLLIDER
GIM_BOX_SET collision methods.
Definition: gim_box_set.h:434
GIM_TREE_TREE_COLLIDER::node0_is_leaf
bool node0_is_leaf
Definition: gim_box_set.h:441
GIM_TREE_TREE_COLLIDER::m_tri0_plane
btVector4 m_tri0_plane
Definition: gim_box_set.h:452
GIM_TREE_TREE_COLLIDER::node_collision
bool node_collision(GUINT node0, GUINT node1)
Definition: gim_box_set.h:508
GIM_TREE_TREE_COLLIDER::m_boxset1
BOX_SET_CLASS1 * m_boxset1
Definition: gim_box_set.h:438
GIM_TREE_TREE_COLLIDER::find_collision
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)
Definition: gim_box_set.h:612
GIM_TREE_TREE_COLLIDER::node1_has_triangle
bool node1_has_triangle
Definition: gim_box_set.h:446
GIM_TREE_TREE_COLLIDER::m_tri0
GIM_TRIANGLE m_tri0
Definition: gim_box_set.h:451
GIM_TREE_TREE_COLLIDER::m_box1
GIM_AABB m_box1
Definition: gim_box_set.h:448
GIM_TREE_TREE_COLLIDER::node0_has_triangle
bool node0_has_triangle
Definition: gim_box_set.h:445
GIM_TREE_TREE_COLLIDER::retrieve_node1_triangle
void retrieve_node1_triangle(GUINT node1)
Definition: gim_box_set.h:477
GIM_TREE_TREE_COLLIDER::retrieve_node0_triangle
void retrieve_node0_triangle(GUINT node0)
Definition: gim_box_set.h:464
GIM_TREE_TREE_COLLIDER::trans_cache_1to0
GIM_BOX_BOX_TRANSFORM_CACHE trans_cache_1to0
Definition: gim_box_set.h:449
GIM_TREE_TREE_COLLIDER::m_tri1_plane
btVector4 m_tri1_plane
Definition: gim_box_set.h:454
GIM_TREE_TREE_COLLIDER::find_collision_pairs
void find_collision_pairs()
Definition: gim_box_set.h:549
GIM_TREE_TREE_COLLIDER::current_node0
GUINT current_node0
Definition: gim_box_set.h:439
GIM_TREE_TREE_COLLIDER::current_node1
GUINT current_node1
Definition: gim_box_set.h:440
GIM_TREE_TREE_COLLIDER::m_boxset0
BOX_SET_CLASS0 * m_boxset0
Definition: gim_box_set.h:437
GIM_TREE_TREE_COLLIDER::retrieve_node0_info
void retrieve_node0_info(GUINT node0)
Definition: gim_box_set.h:490
GIM_TREE_TREE_COLLIDER::node1_is_leaf
bool node1_is_leaf
Definition: gim_box_set.h:442
GIM_TREE_TREE_COLLIDER::t1_is_trimesh
bool t1_is_trimesh
Definition: gim_box_set.h:444
GIM_TREE_TREE_COLLIDER::retrieve_node1_info
void retrieve_node1_info(GUINT node1)
Definition: gim_box_set.h:499
GIM_TREE_TREE_COLLIDER::trans_cache_0to1
btTransform trans_cache_0to1
Definition: gim_box_set.h:450
GIM_TREE_TREE_COLLIDER::m_tri1
GIM_TRIANGLE m_tri1
Definition: gim_box_set.h:453
GIM_TREE_TREE_COLLIDER::m_collision_pairs
gim_pair_set * m_collision_pairs
Definition: gim_box_set.h:436
GIM_TREE_TREE_COLLIDER::m_box0
GIM_AABB m_box0
Definition: gim_box_set.h:447
GIM_TREE_TREE_COLLIDER::GIM_TREE_TREE_COLLIDER
GIM_TREE_TREE_COLLIDER()
Definition: gim_box_set.h:457
GIM_TREE_TREE_COLLIDER::t0_is_trimesh
bool t0_is_trimesh
Definition: gim_box_set.h:443
GIM_TRIANGLE
Class for colliding triangles.
Definition: gim_tri_collision.h:121
GIM_TRIANGLE::m_margin
btScalar m_margin
Definition: gim_tri_collision.h:123
GIM_TRIANGLE::m_vertices
btVector3 m_vertices[3]
Definition: gim_tri_collision.h:124
GIM_TRIANGLE::get_plane
void get_plane(btVector4 &plane) const
Definition: gim_tri_collision.h:140
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:30
btTransform::inverse
btTransform inverse() const
Return the inverse of this transform.
Definition: btTransform.h:182
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
btVector4
Definition: btVector3.h:1074
gim_array
Very simple array container with fast access and simd memory.
Definition: gim_array.h:43
gim_array< GIM_PAIR >::push_back
void push_back(const GIM_PAIR &obj)
Definition: gim_array.h:213
gim_array::reserve
bool reserve(GUINT size)
public operations
Definition: gim_array.h:96
gim_array::size
GUINT size() const
Definition: gim_array.h:143
gim_array::resize
void resize(GUINT size, bool call_constructor=true, const T &fillData=T())
Definition: gim_array.h:287
gim_array::back
T & back()
Definition: gim_array.h:198
gim_array::clear
void clear()
Definition: gim_array.h:110
gim_array::m_data
T * m_data
properties
Definition: gim_array.h:47
gim_array::pop_back
void pop_back()
Definition: gim_array.h:234
gim_pair_set
A pairset array.
Definition: gim_box_set.h:44
gim_pair_set::gim_pair_set
gim_pair_set()
Definition: gim_box_set.h:46
gim_pair_set::push_pair
void push_pair(GUINT index1, GUINT index2)
Definition: gim_box_set.h:49
gim_pair_set::push_pair_inv
void push_pair_inv(GUINT index1, GUINT index2)
Definition: gim_box_set.h:54
gim_array.h
gim_box_collision.h
GUINT
#define GUINT
Definition: gim_math.h:40
G_UINT_INFINITY
#define G_UINT_INFINITY
A very very high value.
Definition: gim_math.h:53
gim_pair.h
gim_radixsort.h
gim_tri_collision.h
GIM_AABB_DATA
Definition: gim_box_set.h:78
GIM_AABB_DATA::m_bound
GIM_AABB m_bound
Definition: gim_box_set.h:79
GIM_AABB_DATA::m_data
GUINT m_data
Definition: gim_box_set.h:80
GIM_BOX_TREE_NODE
Node Structure for trees.
Definition: gim_box_set.h:85
GIM_BOX_TREE_NODE::m_escapeIndex
GUINT m_escapeIndex
Scape index for traversing.
Definition: gim_box_set.h:89
GIM_BOX_TREE_NODE::m_left
GUINT m_left
Left subtree.
Definition: gim_box_set.h:87
GIM_BOX_TREE_NODE::m_right
GUINT m_right
Right subtree.
Definition: gim_box_set.h:88
GIM_BOX_TREE_NODE::GIM_BOX_TREE_NODE
GIM_BOX_TREE_NODE()
Definition: gim_box_set.h:92
GIM_BOX_TREE_NODE::m_data
GUINT m_data
primitive index if apply
Definition: gim_box_set.h:90
GIM_BOX_TREE_NODE::is_leaf_node
bool is_leaf_node() const
Definition: gim_box_set.h:100
GIM_BOX_TREE_NODE::m_bound
GIM_AABB m_bound
Definition: gim_box_set.h:86
GIM_PAIR
Overlapping pair.
Definition: gim_pair.h:7
GIM_PAIR::m_index1
int m_index1
Definition: gim_pair.h:8
GIM_PAIR::m_index2
int m_index2
Definition: gim_pair.h:9