1 #ifndef GIM_BOX_COLLISION_H_INCLUDED     2 #define GIM_BOX_COLLISION_H_INCLUDED   100 #define TEST_CROSS_EDGE_BOX_MCR(edge,absolute_edge,pointa,pointb,_extend,i_dir_0,i_dir_1,i_comp_0,i_comp_1)\   102         const btScalar dir0 = -edge[i_dir_0];\   103         const btScalar dir1 = edge[i_dir_1];\   104         btScalar pmin = pointa[i_comp_0]*dir0 + pointa[i_comp_1]*dir1;\   105         btScalar pmax = pointb[i_comp_0]*dir0 + pointb[i_comp_1]*dir1;\   108                 GIM_SWAP_NUMBERS(pmin,pmax); \   110         const btScalar abs_dir0 = absolute_edge[i_dir_0];\   111         const btScalar abs_dir1 = absolute_edge[i_dir_1];\   112         const btScalar rad = _extend[i_comp_0] * abs_dir0 + _extend[i_comp_1] * abs_dir1;\   113         if(pmin>rad || -rad>pmax) return false;\   117 #define TEST_CROSS_EDGE_BOX_X_AXIS_MCR(edge,absolute_edge,pointa,pointb,_extend)\   119         TEST_CROSS_EDGE_BOX_MCR(edge,absolute_edge,pointa,pointb,_extend,2,1,1,2);\   122 #define TEST_CROSS_EDGE_BOX_Y_AXIS_MCR(edge,absolute_edge,pointa,pointb,_extend)\   124         TEST_CROSS_EDGE_BOX_MCR(edge,absolute_edge,pointa,pointb,_extend,0,2,2,0);\   127 #define TEST_CROSS_EDGE_BOX_Z_AXIS_MCR(edge,absolute_edge,pointa,pointb,_extend)\   129         TEST_CROSS_EDGE_BOX_MCR(edge,absolute_edge,pointa,pointb,_extend,1,0,0,1);\   144                 static const btVector3 vepsi(1e-6f,1e-6f,1e-6f);
   145                 m_AR[0] = vepsi + m_R1to0[0].
absolute();
   146                 m_AR[1] = vepsi + m_R1to0[1].
absolute();
   147                 m_AR[2] = vepsi + m_R1to0[2].
absolute();
   167                 m_T1to0 = m_R1to0 * (-trans0.
getOrigin());
   179                 m_T1to0 = m_R1to0 * (-trans0.
getOrigin());
   189         return point.
dot3(m_R1to0[0], m_R1to0[1], m_R1to0[2]) + 
m_T1to0;
   194 #define BOX_PLANE_EPSILON 0.000001f   211                 m_min[0] = 
GIM_MIN3(V1[0],V2[0],V3[0]);
   212                 m_min[1] = 
GIM_MIN3(V1[1],V2[1],V3[1]);
   213                 m_min[2] = 
GIM_MIN3(V1[2],V2[2],V3[2]);
   215                 m_max[0] = 
GIM_MAX3(V1[0],V2[0],V3[0]);
   216                 m_max[1] = 
GIM_MAX3(V1[1],V2[1],V3[1]);
   217                 m_max[2] = 
GIM_MAX3(V1[2],V2[2],V3[2]);
   225                 m_min[0] = 
GIM_MIN3(V1[0],V2[0],V3[0]);
   226                 m_min[1] = 
GIM_MIN3(V1[1],V2[1],V3[1]);
   227                 m_min[2] = 
GIM_MIN3(V1[2],V2[2],V3[2]);
   229                 m_max[0] = 
GIM_MAX3(V1[0],V2[0],V3[0]);
   230                 m_max[1] = 
GIM_MAX3(V1[1],V2[1],V3[1]);
   231                 m_max[2] = 
GIM_MAX3(V1[2],V2[2],V3[2]);
   242                 m_min(other.m_min),m_max(other.m_max)
   247                 m_min(other.m_min),m_max(other.m_max)
   279                 m_min[0] = other.
m_min[0] - margin;
   280                 m_min[1] = other.
m_min[1] - margin;
   281                 m_min[2] = other.
m_min[2] - margin;
   283                 m_max[0] = other.
m_max[0] + margin;
   284                 m_max[1] = other.
m_max[1] + margin;
   285                 m_max[2] = other.
m_max[2] + margin;
   288         template<
typename CLASS_POINT>
   290                                                         const CLASS_POINT & V1,
   291                                                         const CLASS_POINT & V2,
   292                                                         const CLASS_POINT & V3)
   294                 m_min[0] = 
GIM_MIN3(V1[0],V2[0],V3[0]);
   295                 m_min[1] = 
GIM_MIN3(V1[1],V2[1],V3[1]);
   296                 m_min[2] = 
GIM_MIN3(V1[2],V2[2],V3[2]);
   298                 m_max[0] = 
GIM_MAX3(V1[0],V2[0],V3[0]);
   299                 m_max[1] = 
GIM_MAX3(V1[1],V2[1],V3[1]);
   300                 m_max[2] = 
GIM_MAX3(V1[2],V2[2],V3[2]);
   303         template<
typename CLASS_POINT>
   305                                                         const CLASS_POINT & V1,
   306                                                         const CLASS_POINT & V2,
   307                                                         const CLASS_POINT & V3, 
btScalar margin)
   309                 m_min[0] = 
GIM_MIN3(V1[0],V2[0],V3[0]);
   310                 m_min[1] = 
GIM_MIN3(V1[1],V2[1],V3[1]);
   311                 m_min[2] = 
GIM_MIN3(V1[2],V2[2],V3[2]);
   313                 m_max[0] = 
GIM_MAX3(V1[0],V2[0],V3[0]);
   314                 m_max[1] = 
GIM_MAX3(V1[1],V2[1],V3[1]);
   315                 m_max[2] = 
GIM_MAX3(V1[2],V2[2],V3[2]);
   331                 center = trans(center);
   337                 m_min = center - textends;
   338                 m_max = center + textends;
   354         template<
typename CLASS_POINT>
   357                 m_min[0] = 
GIM_MIN(m_min[0],point[0]);
   358                 m_min[1] = 
GIM_MIN(m_min[1],point[1]);
   359                 m_min[2] = 
GIM_MIN(m_min[2],point[2]);
   361                 m_max[0] = 
GIM_MAX(m_max[0],point[0]);
   362                 m_max[1] = 
GIM_MAX(m_max[1],point[1]);
   363                 m_max[2] = 
GIM_MAX(m_max[2],point[2]);
   369                 center = (m_max+m_min)*0.5f;
   370                 extend = m_max - center;
   388                 if(m_min[0] > other.
m_max[0] ||
   389                    m_max[0] < other.
m_min[0] ||
   390                    m_min[1] > other.
m_max[1] ||
   391                    m_max[1] < other.
m_min[1] ||
   392                    m_min[2] > other.
m_max[2] ||
   393                    m_max[2] < other.
m_min[2])
   408                 this->get_center_extend(center,extents);;
   410                 btScalar Dx = vorigin[0] - center[0];
   411                 if(
GIM_GREATER(Dx, extents[0]) && Dx*vdir[0]>=0.0f)     
return false;
   412                 btScalar Dy = vorigin[1] - center[1];
   413                 if(
GIM_GREATER(Dy, extents[1]) && Dy*vdir[1]>=0.0f)     
return false;
   414                 btScalar Dz = vorigin[2] - center[2];
   415                 if(
GIM_GREATER(Dz, extents[2]) && Dz*vdir[2]>=0.0f)     
return false;
   418                 btScalar f = vdir[1] * Dz - vdir[2] * Dy;
   420                 f = vdir[2] * Dx - vdir[0] * Dz;
   422                 f = vdir[0] * Dy - vdir[1] * Dx;
   435                 vmin = _fOrigin - _fMaximumExtent;
   436                 vmax = _fOrigin + _fMaximumExtent;
   442                 this->projection_interval(plane,_fmin,_fmax);
   460                 return has_collision(tbox);
   471                 get_center_extend(ca,ea);
   482                         T[i] =  transcache.
m_R1to0[i].dot(cb) + transcache.
m_T1to0[i] - ca[i];
   483                         t = transcache.
m_AR[i].dot(eb) + ea[i];
   507                                         t = T[n]*transcache.
m_R1to0[m][j] - T[m]*transcache.
m_R1to0[n][j];
   508                                         t2 = ea[o]*transcache.
m_AR[p][j] + ea[p]*transcache.
m_AR[o][j] +
   509                                                 eb[r]*transcache.
m_AR[i][q] + eb[q]*transcache.
m_AR[i][r];
   532                 if(!collide_plane(triangle_plane)) 
return false;
   535                 this->get_center_extend(center,extends);
   588 #endif // GIM_BOX_COLLISION_H_INCLUDED btMatrix3x3 inverse() const 
Return the inverse of the matrix. 
ePLANE_INTERSECTION_TYPE plane_classify(const btVector4 &plane) const 
void calc_from_triangle_margin(const CLASS_POINT &V1, const CLASS_POINT &V2, const CLASS_POINT &V3, btScalar margin)
void find_intersection(const GIM_AABB &other, GIM_AABB &intersection) const 
Finds the intersecting box between this box and the other. 
void get_center_extend(btVector3 ¢er, btVector3 &extend) const 
Gets the extend and center. 
#define TEST_CROSS_EDGE_BOX_X_AXIS_MCR(edge, absolute_edge, pointa, pointb, _extend)
#define GIM_GREATER(x, y)
btVector3 absolute() const 
Return a vector will the absolute values of each element. 
bool has_collision(const GIM_AABB &other) const 
#define SIMD_FORCE_INLINE
const btVector3 & getRow(int i) const 
Get a row of the matrix as a vector. 
GIM_AABB(const GIM_AABB &other)
btScalar dot(const btVector3 &v) const 
Return the dot product. 
void copy_with_margin(const GIM_AABB &other, btScalar margin)
bool overlapping_trans_conservative(const GIM_AABB &box, btTransform &trans1_to_0)
bool collide_ray(const btVector3 &vorigin, const btVector3 &vdir)
Finds the Ray intersection parameter. 
void calc_from_triangle(const CLASS_POINT &V1, const CLASS_POINT &V2, const CLASS_POINT &V3)
btMatrix3x3 absolute() const 
Return the matrix with all values non negative. 
#define BOX_PLANE_EPSILON
#define TEST_CROSS_EDGE_BOX_Y_AXIS_MCR(edge, absolute_edge, pointa, pointb, _extend)
bool collide_plane(const btVector4 &plane)
Simple test for planes. 
GIM_AABB(const GIM_AABB &other, btScalar margin)
#define GIM_MIN3(a, b, c)
btVector3 can be used to represent 3D points and vectors. 
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 
GREAL mat4f[4][4]
Matrix 4D, row ordered. 
GIM_AABB(const btVector3 &V1, const btVector3 &V2, const btVector3 &V3)
bool btCompareTransformsEqual(const btTransform &t1, const btTransform &t2)
Compairison of transformation objects. 
btMatrix3x3 transpose() const 
Return the transpose of the matrix. 
void merge_point(const CLASS_POINT &point)
Merges a point. 
void appy_transform(const btTransform &trans)
Apply a transform to an AABB. 
btVector3 dot3(const btVector3 &v0, const btVector3 &v1, const btVector3 &v2) const 
#define MAT_GET_TRANSLATION(mat, vec3)
Get the triple(3) col of a transform matrix. 
#define COPY_MATRIX_3X3(b, a)
#define TEST_CROSS_EDGE_BOX_Z_AXIS_MCR(edge, absolute_edge, pointa, pointb, _extend)
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
bool collide_triangle_exact(const btVector3 &p1, const btVector3 &p2, const btVector3 &p3, const btVector4 &triangle_plane)
test for a triangle, with edges 
void projection_interval(const btVector3 &direction, btScalar &vmin, btScalar &vmax) const 
#define GIM_MAX3(a, b, c)
GIM_AABB(const btVector3 &V1, const btVector3 &V2, const btVector3 &V3, GREAL margin)
#define MAT_DOT_COL(mat, vec3, colindex)
Returns the dot product between a vec3f and the col of a matrix. 
void increment_margin(btScalar margin)
void merge(const GIM_AABB &box)
Merges a Box. 
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
btScalar btFabs(btScalar x)