|
Bullet Collision Detection & Physics Library
|
Go to the documentation of this file. 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
btAABB(const btAABB &other, btScalar margin)
btVector3 absolute() const
Return a vector will the absolute values of each element.
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
btVector3 dot3(const btVector3 &v0, const btVector3 &v1, const btVector3 &v2) const
void get_center_extend(btVector3 ¢er, btVector3 &extend) const
Gets the extend and center.
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
btMatrix3x3 inverse() const
Return the inverse of the matrix.
eBT_PLANE_INTERSECTION_TYPE
btScalar dot(const btVector3 &v) const
Return the dot product.
bool overlapping_trans_conservative2(const btAABB &box, const BT_BOX_BOX_TRANSFORM_CACHE &trans1_to_0) const
void projection_interval(const btVector3 &direction, btScalar &vmin, btScalar &vmax) const
void appy_transform_trans_cache(const BT_BOX_BOX_TRANSFORM_CACHE &trans)
Apply a transform to an AABB.
bool collide_triangle_exact(const btVector3 &p1, const btVector3 &p2, const btVector3 &p3, const btVector4 &triangle_plane) const
test for a triangle, with edges
btAABB(const btVector3 &V1, const btVector3 &V2, const btVector3 &V3)
#define TEST_CROSS_EDGE_BOX_X_AXIS_MCR(edge, absolute_edge, pointa, pointb, _extend)
void copy_with_margin(const btAABB &other, btScalar margin)
const btVector3 & getRow(int i) const
Get a row of the matrix as a vector.
void find_intersection(const btAABB &other, btAABB &intersection) const
Finds the intersecting box between this box and the other.
bool btCompareTransformsEqual(const btTransform &t1, const btTransform &t2)
Compairison of transformation objects.
btScalar btFabs(btScalar x)
void increment_margin(btScalar margin)
#define TEST_CROSS_EDGE_BOX_Y_AXIS_MCR(edge, absolute_edge, pointa, pointb, _extend)
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
#define BOX_PLANE_EPSILON
bool overlapping_trans_conservative(const btAABB &box, btTransform &trans1_to_0) const
#define TEST_CROSS_EDGE_BOX_Z_AXIS_MCR(edge, absolute_edge, pointa, pointb, _extend)
btVector3 can be used to represent 3D points and vectors.
btAABB(const btVector3 &V1, const btVector3 &V2, const btVector3 &V3, btScalar margin)
#define ATTRIBUTE_ALIGNED16(a)
void calc_from_triangle_margin(const CLASS_POINT &V1, const CLASS_POINT &V2, const CLASS_POINT &V3, btScalar margin)
#define SIMD_FORCE_INLINE
void merge_point(const CLASS_POINT &point)
Merges a point.
void merge(const btAABB &box)
Merges a Box.
void appy_transform(const btTransform &trans)
Apply a transform to an AABB.
bool collide_ray(const btVector3 &vorigin, const btVector3 &vdir) const
Finds the Ray intersection parameter.
eBT_PLANE_INTERSECTION_TYPE plane_classify(const btVector4 &plane) const
btScalar bt_mat3_dot_col(const btMatrix3x3 &mat, const btVector3 &vec3, int colindex)
Returns the dot product between a vec3f and the col of a matrix.
btAABB(const btAABB &other)
bool has_collision(const btAABB &other) const
void calc_from_triangle(const CLASS_POINT &V1, const CLASS_POINT &V2, const CLASS_POINT &V3)
bool collide_plane(const btVector4 &plane) const
Simple test for planes.