37 #define TRI_LOCAL_EPSILON 0.000001f    38 #define MIN_EDGE_EDGE_DIS 0.00001f    81                         scale_edge0 = -D2/(D0-D2);
    82                         scale_edge1 = -D1/(D2-D1);
    83                         edge_index0 = 2;edge_index1 = 1;
    88                         scale_edge0 = -D0/(D1-D0);
    89                         scale_edge1 = -D1/(D2-D1);
    90                         edge_index0 = 0;edge_index1 = 1;
    92                 else if(D1*D2>0.0f || D0!=0.0f)
    95                         scale_edge0 = -D0/(D1-D0);
    96                         scale_edge1 = -D2/(D0-D2);
    97                         edge_index0 = 0 ;edge_index1 = 2;
   120                 EDGE_PLANE(tripoints[0],tripoints[1],tri_plane,edgeplane);
   123                         edgeplane,srcpoints[0],srcpoints[1],srcpoints[2],temp_points);
   125                 if(clipped_count == 0) 
return 0;
   129                 EDGE_PLANE(tripoints[1],tripoints[2],tri_plane,edgeplane);
   132                         edgeplane,temp_points,clipped_count,temp_points1);
   134                 if(clipped_count == 0) 
return 0;
   138                 EDGE_PLANE(tripoints[2],tripoints[0],tri_plane,edgeplane);
   141                         edgeplane,temp_points1,clipped_count,clip_points);
   143                 return clipped_count;
   203                 edge_edge_dir = tu_plane.
cross(tv_plane);
   212                 edge_edge_dir*= 1/Dlen;
   217                 GREAL tu_scale_e0,tu_scale_e1;
   219                         du0du1,du0du2,tu_scale_e0,tu_scale_e1,tu_e0,tu_e1)) 
return 0;
   223                 GREAL tv_scale_e0,tv_scale_e1;
   226                         dv0dv1,dv0dv2,tv_scale_e0,tv_scale_e1,tv_e0,tv_e1)) 
return 0;
   229                 btVector3 up_e0 = tu_vertices[tu_e0].
lerp(tu_vertices[(tu_e0+1)%3],tu_scale_e0);
   230                 btVector3 up_e1 = tu_vertices[tu_e1].
lerp(tu_vertices[(tu_e1+1)%3],tu_scale_e1);
   232                 btVector3 vp_e0 = tv_vertices[tv_e0].
lerp(tv_vertices[(tv_e0+1)%3],tv_scale_e0);
   233                 btVector3 vp_e1 = tv_vertices[tv_e1].
lerp(tv_vertices[(tv_e1+1)%3],tv_scale_e1);
   236                 GREAL isect_u[] = {up_e0.
dot(edge_edge_dir),up_e1.
dot(edge_edge_dir)};
   237                 GREAL isect_v[] = {vp_e0.
dot(edge_edge_dir),vp_e1.
dot(edge_edge_dir)};
   239                 sort_isect(isect_u[0],isect_u[1],tu_e0,tu_e1,up_e0,up_e1);
   240                 sort_isect(isect_v[0],isect_v[1],tv_e0,tv_e1,vp_e0,vp_e1);
   242                 const GREAL midpoint_u = 0.5f*(isect_u[0]+isect_u[1]); 
   243                 const GREAL midpoint_v = 0.5f*(isect_v[0]+isect_v[1]); 
   245                 if(midpoint_u<midpoint_v)
   247                         if(isect_u[1]>=isect_v[1]) 
   251                         else if(isect_v[0]<=isect_u[0]) 
   256                         closest_point_u = up_e1;
   257                         closest_point_v = vp_e0;
   263                                         tu_vertices[tu_e1],tu_vertices[(tu_e1+1)%3],
   264                                         tv_vertices[tv_e0],tv_vertices[(tv_e0+1)%3],
   270                                 edge_edge_dir *= 1.0f/distances[2];
   274                                 distances[2] = isect_v[0]-isect_u[1];
   281                         if(isect_v[1]>=isect_u[1]) 
   285                         else if(isect_u[0]<=isect_v[0]) 
   290                         closest_point_u = up_e0;
   291                         closest_point_v = vp_e1;
   297                                         tu_vertices[tu_e0],tu_vertices[(tu_e0+1)%3],
   298                                         tv_vertices[tv_e1],tv_vertices[(tv_e1+1)%3],
   304                                 edge_edge_dir *= 1.0f/distances[2];
   308                                 distances[2] = isect_u[0]-isect_v[1];
   329                 margin = margin_u + margin_v;
   342                 TRIANGLE_PLANE(tv_vertices[0],tv_vertices[1],tv_vertices[2],tv_plane);
   349                 du0du1 = du[0] * du[1];
   350                 du0du2 = du[0] * du[2];
   353                 if(du0du1>0.0f && du0du2>0.0f)  
   357                                 distances[0] = 
GIM_MAX3(du[0],du[1],du[2]);
   358                                 distances[0] = -distances[0];
   359                                 if(distances[0]>margin) 
return false; 
   362                                 VEC_SWAP(tv_vertices[0],tv_vertices[1]);
   367                                 distances[0] = 
GIM_MIN3(du[0],du[1],du[2]);
   368                                 if(distances[0]>margin) 
return false; 
   374                         distances[0] = (du[0]+du[1]+du[2])/3.0f; 
   376                         if(distances[0]<0.0f)
   379                                 VEC_SWAP(tv_vertices[0],tv_vertices[1]);
   382                                 distances[0] = 
GIM_MAX3(du[0],du[1],du[2]);
   383                                 distances[0] = -distances[0];
   387                                 distances[0] = 
GIM_MIN3(du[0],du[1],du[2]);
   394                 TRIANGLE_PLANE(tu_vertices[0],tu_vertices[1],tu_vertices[2],tu_plane);
   400                 dv0dv1 = dv[0] * dv[1];
   401                 dv0dv2 = dv[0] * dv[2];
   404                 if(dv0dv1>0.0f && dv0dv2>0.0f)  
   408                                 distances[1] = 
GIM_MAX3(dv[0],dv[1],dv[2]);
   409                                 distances[1] = -distances[1];
   410                                 if(distances[1]>margin) 
return false; 
   413                                 VEC_SWAP(tu_vertices[0],tu_vertices[1]);
   418                                 distances[1] = 
GIM_MIN3(dv[0],dv[1],dv[2]);
   419                                 if(distances[1]>margin) 
return false; 
   425                         distances[1] = (dv[0]+dv[1]+dv[2])/3.0f; 
   427                         if(distances[1]<0.0f)
   430                                 VEC_SWAP(tu_vertices[0],tu_vertices[1]);
   433                                 distances[1] = 
GIM_MAX3(dv[0],dv[1],dv[2]);
   434                                 distances[1] = -distances[1];
   438                                 distances[1] = 
GIM_MIN3(dv[0],dv[1],dv[2]);
   452                         if(distances[0]<distances[1]) bl = 1;
   457                         if(distances[2]>margin) 
return false;
   474                         point_count = 
clip_triangle(tv_plane,tv_vertices,tu_vertices,contact_points);
   475                         if(point_count == 0) 
return false;                                              
   476                         contacts.
merge_points(tv_plane,margin,contact_points,point_count);                      
   480                         point_count = 
clip_triangle(tu_plane,tu_vertices,tv_vertices,contact_points);
   481                         if(point_count == 0) 
return false;                      
   482                         contacts.
merge_points(tu_plane,margin,contact_points,point_count);
   632                                         m_vertices[0],m_vertices[1],m_vertices[2],m_margin,
 
#define TRIANGLE_PLANE(v1, v2, v3, plane)
plane is a vec4f 
#define VEC_SCALE_4(c, a, b)
scalar times vector 
btVector3 temp_points[MAX_TRI_CLIPPING]
#define EDGE_PLANE(e1, e2, n, plane)
Calc a plane from an edge an a normal. plane is a vec4f. 
bool compute_intervals(const GREAL &D0, const GREAL &D1, const GREAL &D2, const GREAL &D0D1, const GREAL &D0D2, GREAL &scale_edge0, GREAL &scale_edge1, GUINT &edge_index0, GUINT &edge_index1)
if returns false, the faces are paralele 
void sort_isect(GREAL &isect0, GREAL &isect1, GUINT &e0, GUINT &e1, btVector3 &vec0, btVector3 &vec1)
btVector3 temp_points1[MAX_TRI_CLIPPING]
GUINT PLANE_CLIP_POLYGON3D(const CLASS_PLANE &plane, const CLASS_POINT *polygon_points, GUINT polygon_point_count, CLASS_POINT *clipped)
bool collide_triangle_hard_test(const GIM_TRIANGLE &other, GIM_TRIANGLE_CONTACT_DATA &contact_data) const 
Test triangles by finding separating axis. 
#define SIMD_FORCE_INLINE
void SEGMENT_COLLISION(const CLASS_POINT &vA1, const CLASS_POINT &vA2, const CLASS_POINT &vB1, const CLASS_POINT &vB2, CLASS_POINT &vPointA, CLASS_POINT &vPointB)
Find closest points on segments. 
GUINT cross_line_intersection_test()
Test verifying interval intersection with the direction between planes. 
#define GIM_SWAP_NUMBERS(a, b)
Swap numbers. 
#define VEC_COPY(b, a)
Copy 3D vector. 
btScalar dot(const btVector3 &v) const 
Return the dot product. 
btVector3 lerp(const btVector3 &v, const btScalar &t) const 
Return the linear interpolation between this and another vector. 
#define VEC_SWAP(b, a)
VECTOR SWAP. 
#define MIN_EDGE_EDGE_DIS
GUINT PLANE_CLIP_TRIANGLE3D(const CLASS_PLANE &plane, const CLASS_POINT &point0, const CLASS_POINT &point1, const CLASS_POINT &point2, CLASS_POINT *clipped)
Class for colliding triangles. 
btVector3 closest_point_u
btVector3 cross(const btVector3 &v) const 
Return the cross product between this and another vector. 
#define VEC_LENGTH(a, l)
Vector length. 
#define GIM_MIN3(a, b, c)
bool triangle_collision(const btVector3 &u0, const btVector3 &u1, const btVector3 &u2, GREAL margin_u, const btVector3 &v0, const btVector3 &v1, const btVector3 &v2, GREAL margin_v, GIM_TRIANGLE_CONTACT_DATA &contacts)
collides by two sides 
btVector3 can be used to represent 3D points and vectors. 
#define DISTANCE_PLANE_POINT(plane, point)
GUINT clip_triangle(const btVector4 &tri_plane, const btVector3 *tripoints, const btVector3 *srcpoints, btVector3 *clip_points)
clip triangle 
btVector3 contact_points[MAX_TRI_CLIPPING]
#define GIM_MAX3(a, b, c)
btVector3 closest_point_v