1 #ifndef BT_BOX_COLLISION_H_INCLUDED
2 #define BT_BOX_COLLISION_H_INCLUDED
31 #define BT_SWAP_NUMBERS(a,b){ \
38 #define BT_MAX(a,b) (a<b?b:a)
39 #define BT_MIN(a,b) (a>b?b:a)
41 #define BT_GREATER(x, y) btFabs(x) > (y)
43 #define BT_MAX3(a,b,c) BT_MAX(a,BT_MAX(b,c))
44 #define BT_MIN3(a,b,c) BT_MIN(a,BT_MIN(b,c))
119 #define TEST_CROSS_EDGE_BOX_MCR(edge,absolute_edge,pointa,pointb,_extend,i_dir_0,i_dir_1,i_comp_0,i_comp_1)\
121 const btScalar dir0 = -edge[i_dir_0];\
122 const btScalar dir1 = edge[i_dir_1];\
123 btScalar pmin = pointa[i_comp_0]*dir0 + pointa[i_comp_1]*dir1;\
124 btScalar pmax = pointb[i_comp_0]*dir0 + pointb[i_comp_1]*dir1;\
127 BT_SWAP_NUMBERS(pmin,pmax); \
129 const btScalar abs_dir0 = absolute_edge[i_dir_0];\
130 const btScalar abs_dir1 = absolute_edge[i_dir_1];\
131 const btScalar rad = _extend[i_comp_0] * abs_dir0 + _extend[i_comp_1] * abs_dir1;\
132 if(pmin>rad || -rad>pmax) return false;\
136 #define TEST_CROSS_EDGE_BOX_X_AXIS_MCR(edge,absolute_edge,pointa,pointb,_extend)\
138 TEST_CROSS_EDGE_BOX_MCR(edge,absolute_edge,pointa,pointb,_extend,2,1,1,2);\
141 #define TEST_CROSS_EDGE_BOX_Y_AXIS_MCR(edge,absolute_edge,pointa,pointb,_extend)\
143 TEST_CROSS_EDGE_BOX_MCR(edge,absolute_edge,pointa,pointb,_extend,0,2,2,0);\
146 #define TEST_CROSS_EDGE_BOX_Z_AXIS_MCR(edge,absolute_edge,pointa,pointb,_extend)\
148 TEST_CROSS_EDGE_BOX_MCR(edge,absolute_edge,pointa,pointb,_extend,1,0,0,1);\
156 return vec3[0]*mat[0][colindex] + vec3[1]*mat[1][colindex] + vec3[2]*mat[2][colindex];
181 m_AR[i][j] = 1e-6f +
btFabs(m_R1to0[i][j]);
198 temp_trans = temp_trans * trans1;
204 calc_absolute_matrix();
211 m_T1to0 = m_R1to0 * (-trans0.
getOrigin());
216 calc_absolute_matrix();
221 return point.
dot3( m_R1to0[0], m_R1to0[1], m_R1to0[2] ) + m_T1to0;
226 #define BOX_PLANE_EPSILON 0.000001f
243 m_min[0] =
BT_MIN3(V1[0],V2[0],V3[0]);
244 m_min[1] =
BT_MIN3(V1[1],V2[1],V3[1]);
245 m_min[2] =
BT_MIN3(V1[2],V2[2],V3[2]);
247 m_max[0] =
BT_MAX3(V1[0],V2[0],V3[0]);
248 m_max[1] =
BT_MAX3(V1[1],V2[1],V3[1]);
249 m_max[2] =
BT_MAX3(V1[2],V2[2],V3[2]);
257 m_min[0] =
BT_MIN3(V1[0],V2[0],V3[0]);
258 m_min[1] =
BT_MIN3(V1[1],V2[1],V3[1]);
259 m_min[2] =
BT_MIN3(V1[2],V2[2],V3[2]);
261 m_max[0] =
BT_MAX3(V1[0],V2[0],V3[0]);
262 m_max[1] =
BT_MAX3(V1[1],V2[1],V3[1]);
263 m_max[2] =
BT_MAX3(V1[2],V2[2],V3[2]);
274 m_min(other.m_min),m_max(other.m_max)
279 m_min(other.m_min),m_max(other.m_max)
311 m_min[0] = other.
m_min[0] - margin;
312 m_min[1] = other.
m_min[1] - margin;
313 m_min[2] = other.
m_min[2] - margin;
315 m_max[0] = other.
m_max[0] + margin;
316 m_max[1] = other.
m_max[1] + margin;
317 m_max[2] = other.
m_max[2] + margin;
320 template<
typename CLASS_POINT>
322 const CLASS_POINT & V1,
323 const CLASS_POINT & V2,
324 const CLASS_POINT & V3)
326 m_min[0] =
BT_MIN3(V1[0],V2[0],V3[0]);
327 m_min[1] =
BT_MIN3(V1[1],V2[1],V3[1]);
328 m_min[2] =
BT_MIN3(V1[2],V2[2],V3[2]);
330 m_max[0] =
BT_MAX3(V1[0],V2[0],V3[0]);
331 m_max[1] =
BT_MAX3(V1[1],V2[1],V3[1]);
332 m_max[2] =
BT_MAX3(V1[2],V2[2],V3[2]);
335 template<
typename CLASS_POINT>
337 const CLASS_POINT & V1,
338 const CLASS_POINT & V2,
339 const CLASS_POINT & V3,
btScalar margin)
341 m_min[0] =
BT_MIN3(V1[0],V2[0],V3[0]);
342 m_min[1] =
BT_MIN3(V1[1],V2[1],V3[1]);
343 m_min[2] =
BT_MIN3(V1[2],V2[2],V3[2]);
345 m_max[0] =
BT_MAX3(V1[0],V2[0],V3[0]);
346 m_max[1] =
BT_MAX3(V1[1],V2[1],V3[1]);
347 m_max[2] =
BT_MAX3(V1[2],V2[2],V3[2]);
363 center = trans(center);
369 m_min = center - textends;
370 m_max = center + textends;
386 m_min = center - textends;
387 m_max = center + textends;
403 template<
typename CLASS_POINT>
406 m_min[0] =
BT_MIN(m_min[0],point[0]);
407 m_min[1] =
BT_MIN(m_min[1],point[1]);
408 m_min[2] =
BT_MIN(m_min[2],point[2]);
410 m_max[0] =
BT_MAX(m_max[0],point[0]);
411 m_max[1] =
BT_MAX(m_max[1],point[1]);
412 m_max[2] =
BT_MAX(m_max[2],point[2]);
418 center = (m_max+m_min)*0.5f;
419 extend = m_max - center;
437 if(m_min[0] > other.
m_max[0] ||
438 m_max[0] < other.
m_min[0] ||
439 m_min[1] > other.
m_max[1] ||
440 m_max[1] < other.
m_min[1] ||
441 m_min[2] > other.
m_max[2] ||
442 m_max[2] < other.
m_min[2])
457 this->get_center_extend(center,extents);;
459 btScalar Dx = vorigin[0] - center[0];
460 if(
BT_GREATER(Dx, extents[0]) && Dx*vdir[0]>=0.0f)
return false;
461 btScalar Dy = vorigin[1] - center[1];
462 if(
BT_GREATER(Dy, extents[1]) && Dy*vdir[1]>=0.0f)
return false;
463 btScalar Dz = vorigin[2] - center[2];
464 if(
BT_GREATER(Dz, extents[2]) && Dz*vdir[2]>=0.0f)
return false;
467 btScalar f = vdir[1] * Dz - vdir[2] * Dy;
469 f = vdir[2] * Dx - vdir[0] * Dz;
471 f = vdir[0] * Dy - vdir[1] * Dx;
484 vmin = _fOrigin - _fMaximumExtent;
485 vmax = _fOrigin + _fMaximumExtent;
491 this->projection_interval(plane,_fmin,_fmax);
509 return has_collision(tbox);
517 return has_collision(tbox);
528 get_center_extend(ca,ea);
539 T[i] = transcache.
m_R1to0[i].dot(cb) + transcache.
m_T1to0[i] - ca[i];
540 t = transcache.
m_AR[i].dot(eb) + ea[i];
564 t = T[n]*transcache.
m_R1to0[m][j] - T[m]*transcache.
m_R1to0[n][j];
565 t2 = ea[o]*transcache.
m_AR[p][j] + ea[p]*transcache.
m_AR[o][j] +
566 eb[r]*transcache.
m_AR[i][q] + eb[q]*transcache.
m_AR[i][r];
589 if(!collide_plane(triangle_plane))
return false;
592 this->get_center_extend(center,extends);
645 #endif // GIM_BOX_COLLISION_H_INCLUDED