| 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 
   30 #define BT_SWAP_NUMBERS(a, b) \ 
   37 #define BT_MAX(a, b) (a < b ? b : a) 
   38 #define BT_MIN(a, b) (a > b ? b : a) 
   40 #define BT_GREATER(x, y) btFabs(x) > (y) 
   42 #define BT_MAX3(a, b, c) BT_MAX(a, BT_MAX(b, c)) 
   43 #define BT_MIN3(a, b, c) BT_MIN(a, BT_MIN(b, c)) 
  112 #define TEST_CROSS_EDGE_BOX_MCR(edge, absolute_edge, pointa, pointb, _extend, i_dir_0, i_dir_1, i_comp_0, i_comp_1) \ 
  114                 const btScalar dir0 = -edge[i_dir_0];                                                                       \ 
  115                 const btScalar dir1 = edge[i_dir_1];                                                                        \ 
  116                 btScalar pmin = pointa[i_comp_0] * dir0 + pointa[i_comp_1] * dir1;                                          \ 
  117                 btScalar pmax = pointb[i_comp_0] * dir0 + pointb[i_comp_1] * dir1;                                          \ 
  120                         BT_SWAP_NUMBERS(pmin, pmax);                                                                            \ 
  122                 const btScalar abs_dir0 = absolute_edge[i_dir_0];                                                           \ 
  123                 const btScalar abs_dir1 = absolute_edge[i_dir_1];                                                           \ 
  124                 const btScalar rad = _extend[i_comp_0] * abs_dir0 + _extend[i_comp_1] * abs_dir1;                           \ 
  125                 if (pmin > rad || -rad > pmax) return false;                                                                \ 
  128 #define TEST_CROSS_EDGE_BOX_X_AXIS_MCR(edge, absolute_edge, pointa, pointb, _extend)       \ 
  130                 TEST_CROSS_EDGE_BOX_MCR(edge, absolute_edge, pointa, pointb, _extend, 2, 1, 1, 2); \ 
  133 #define TEST_CROSS_EDGE_BOX_Y_AXIS_MCR(edge, absolute_edge, pointa, pointb, _extend)       \ 
  135                 TEST_CROSS_EDGE_BOX_MCR(edge, absolute_edge, pointa, pointb, _extend, 0, 2, 2, 0); \ 
  138 #define TEST_CROSS_EDGE_BOX_Z_AXIS_MCR(edge, absolute_edge, pointa, pointb, _extend)       \ 
  140                 TEST_CROSS_EDGE_BOX_MCR(edge, absolute_edge, pointa, pointb, _extend, 1, 0, 0, 1); \ 
  147         return vec3[0] * mat[0][colindex] + vec3[1] * mat[1][colindex] + vec3[2] * mat[2][colindex];
 
  168                 for (i = 0; i < 3; i++)
 
  170                         for (j = 0; j < 3; j++)
 
  172                                 m_AR[i][j] = 1e-6f + 
btFabs(m_R1to0[i][j]);
 
  185                 temp_trans = temp_trans * trans1;
 
  190                 calc_absolute_matrix();
 
  197                 m_T1to0 = m_R1to0 * (-trans0.
getOrigin());
 
  202                 calc_absolute_matrix();
 
  207                 return point.
dot3(m_R1to0[0], m_R1to0[1], m_R1to0[2]) + m_T1to0;
 
  211 #define BOX_PLANE_EPSILON 0.000001f 
  229                 m_min[0] = 
BT_MIN3(V1[0], V2[0], V3[0]);
 
  230                 m_min[1] = 
BT_MIN3(V1[1], V2[1], V3[1]);
 
  231                 m_min[2] = 
BT_MIN3(V1[2], V2[2], V3[2]);
 
  233                 m_max[0] = 
BT_MAX3(V1[0], V2[0], V3[0]);
 
  234                 m_max[1] = 
BT_MAX3(V1[1], V2[1], V3[1]);
 
  235                 m_max[2] = 
BT_MAX3(V1[2], V2[2], V3[2]);
 
  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]);
 
  295                 m_min[0] = other.
m_min[0] - margin;
 
  296                 m_min[1] = other.
m_min[1] - margin;
 
  297                 m_min[2] = other.
m_min[2] - margin;
 
  299                 m_max[0] = other.
m_max[0] + margin;
 
  300                 m_max[1] = other.
m_max[1] + margin;
 
  301                 m_max[2] = other.
m_max[2] + margin;
 
  304         template <
typename CLASS_POINT>
 
  306                 const CLASS_POINT &V1,
 
  307                 const CLASS_POINT &V2,
 
  308                 const CLASS_POINT &V3)
 
  310                 m_min[0] = 
BT_MIN3(V1[0], V2[0], V3[0]);
 
  311                 m_min[1] = 
BT_MIN3(V1[1], V2[1], V3[1]);
 
  312                 m_min[2] = 
BT_MIN3(V1[2], V2[2], V3[2]);
 
  314                 m_max[0] = 
BT_MAX3(V1[0], V2[0], V3[0]);
 
  315                 m_max[1] = 
BT_MAX3(V1[1], V2[1], V3[1]);
 
  316                 m_max[2] = 
BT_MAX3(V1[2], V2[2], V3[2]);
 
  319         template <
typename CLASS_POINT>
 
  321                 const CLASS_POINT &V1,
 
  322                 const CLASS_POINT &V2,
 
  323                 const CLASS_POINT &V3, 
btScalar margin)
 
  325                 m_min[0] = 
BT_MIN3(V1[0], V2[0], V3[0]);
 
  326                 m_min[1] = 
BT_MIN3(V1[1], V2[1], V3[1]);
 
  327                 m_min[2] = 
BT_MIN3(V1[2], V2[2], V3[2]);
 
  329                 m_max[0] = 
BT_MAX3(V1[0], V2[0], V3[0]);
 
  330                 m_max[1] = 
BT_MAX3(V1[1], V2[1], V3[1]);
 
  331                 m_max[2] = 
BT_MAX3(V1[2], V2[2], V3[2]);
 
  344                 btVector3 center = (m_max + m_min) * 0.5f;
 
  347                 center = trans(center);
 
  353                 m_min = center - textends;
 
  354                 m_max = center + textends;
 
  360                 btVector3 center = (m_max + m_min) * 0.5f;
 
  369                 m_min = center - textends;
 
  370                 m_max = center + textends;
 
  386         template <
typename CLASS_POINT>
 
  389                 m_min[0] = 
BT_MIN(m_min[0], point[0]);
 
  390                 m_min[1] = 
BT_MIN(m_min[1], point[1]);
 
  391                 m_min[2] = 
BT_MIN(m_min[2], point[2]);
 
  393                 m_max[0] = 
BT_MAX(m_max[0], point[0]);
 
  394                 m_max[1] = 
BT_MAX(m_max[1], point[1]);
 
  395                 m_max[2] = 
BT_MAX(m_max[2], point[2]);
 
  401                 center = (m_max + m_min) * 0.5f;
 
  402                 extend = m_max - center;
 
  419                 if (m_min[0] > other.
m_max[0] ||
 
  420                         m_max[0] < other.
m_min[0] ||
 
  421                         m_min[1] > other.
m_max[1] ||
 
  422                         m_max[1] < other.
m_min[1] ||
 
  423                         m_min[2] > other.
m_max[2] ||
 
  424                         m_max[2] < other.
m_min[2])
 
  439                 this->get_center_extend(center, extents);
 
  442                 btScalar Dx = vorigin[0] - center[0];
 
  443                 if (
BT_GREATER(Dx, extents[0]) && Dx * vdir[0] >= 0.0f) 
return false;
 
  444                 btScalar Dy = vorigin[1] - center[1];
 
  445                 if (
BT_GREATER(Dy, extents[1]) && Dy * vdir[1] >= 0.0f) 
return false;
 
  446                 btScalar Dz = vorigin[2] - center[2];
 
  447                 if (
BT_GREATER(Dz, extents[2]) && Dz * vdir[2] >= 0.0f) 
return false;
 
  449                 btScalar f = vdir[1] * Dz - vdir[2] * Dy;
 
  450                 if (
btFabs(f) > extents[1] * 
btFabs(vdir[2]) + extents[2] * 
btFabs(vdir[1])) 
return false;
 
  451                 f = vdir[2] * Dx - vdir[0] * Dz;
 
  452                 if (
btFabs(f) > extents[0] * 
btFabs(vdir[2]) + extents[2] * 
btFabs(vdir[0])) 
return false;
 
  453                 f = vdir[0] * Dy - vdir[1] * Dx;
 
  454                 if (
btFabs(f) > extents[0] * 
btFabs(vdir[1]) + extents[1] * 
btFabs(vdir[0])) 
return false;
 
  460                 btVector3 center = (m_max + m_min) * 0.5f;
 
  465                 vmin = _fOrigin - _fMaximumExtent;
 
  466                 vmax = _fOrigin + _fMaximumExtent;
 
  472                 this->projection_interval(plane, _fmin, _fmax);
 
  490                 return has_collision(tbox);
 
  498                 return has_collision(tbox);
 
  508                 get_center_extend(ca, ea);
 
  516                 for (i = 0; i < 3; i++)
 
  518                         T[i] = transcache.
m_R1to0[i].dot(cb) + transcache.
m_T1to0[i] - ca[i];
 
  519                         t = transcache.
m_AR[i].dot(eb) + ea[i];
 
  523                 for (i = 0; i < 3; i++)
 
  532                         int j, m, n, o, p, q, r;
 
  533                         for (i = 0; i < 3; i++)
 
  539                                 for (j = 0; j < 3; j++)
 
  543                                         t = T[n] * transcache.
m_R1to0[m][j] - T[m] * transcache.
m_R1to0[n][j];
 
  544                                         t2 = ea[o] * transcache.
m_AR[p][j] + ea[p] * transcache.
m_AR[o][j] +
 
  545                                                  eb[r] * transcache.
m_AR[i][q] + eb[q] * transcache.
m_AR[i][r];
 
  568                 if (!collide_plane(triangle_plane)) 
return false;
 
  571                 this->get_center_extend(center, extends);
 
  620 #endif  // GIM_BOX_COLLISION_H_INCLUDED 
 
btAABB(const btAABB &other, btScalar margin)
btVector3 absolute() const
Return a vector with 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.