1 #ifndef GIM_BASIC_GEOMETRY_OPERATIONS_H_INCLUDED     2 #define GIM_BASIC_GEOMETRY_OPERATIONS_H_INCLUDED    45 #define PLANEDIREPSILON 0.0000001f    46 #define PARALELENORMALS 0.000001f    49 #define TRIANGLE_NORMAL(v1,v2,v3,n)\    52     VEC_DIFF(_dif1,v2,v1);\    53     VEC_DIFF(_dif2,v3,v1);\    54     VEC_CROSS(n,_dif1,_dif2);\    58 #define TRIANGLE_NORMAL_FAST(v1,v2,v3,n){\    60     VEC_DIFF(_dif1,v2,v1); \    61     VEC_DIFF(_dif2,v3,v1); \    62     VEC_CROSS(n,_dif1,_dif2); \    65 #define TRIANGLE_PLANE(v1,v2,v3,plane) {\    67     TRIANGLE_NORMAL(v1,v2,v3,plane);\    68     plane[3] = VEC_DOT(v1,plane);\    71 #define TRIANGLE_PLANE_FAST(v1,v2,v3,plane) {\    73     TRIANGLE_NORMAL_FAST(v1,v2,v3,plane);\    74     plane[3] = VEC_DOT(v1,plane);\    77 #define EDGE_PLANE(e1,e2,n,plane) {\    80     VEC_DIFF(_dif,e2,e1); \    81     VEC_CROSS(plane,_dif,n); \    82     VEC_NORMALIZE(plane); \    83     plane[3] = VEC_DOT(e1,plane);\    86 #define DISTANCE_PLANE_POINT(plane,point) (VEC_DOT(plane,point) - plane[3])    88 #define PROJECT_POINT_PLANE(point,plane,projected) {\    90         _dis = DISTANCE_PLANE_POINT(plane,point);\    91         VEC_SCALE(projected,-_dis,plane);\    92         VEC_SUM(projected,projected,point);     \    95 template<
typename CLASS_POINT,
typename CLASS_PLANE>
    98         const CLASS_POINT& point,
const CLASS_PLANE * planes,
GUINT plane_count)
   101         for (
GUINT _i = 0;_i< plane_count;++_i)
   104             if(_dis>0.0f) 
return false;
   109 template<
typename CLASS_POINT,
typename CLASS_PLANE>
   111         const CLASS_POINT& s1,
   112         const CLASS_POINT &s2,
const CLASS_PLANE &plane,CLASS_POINT &clipped)
   117         _dis2 = 
VEC_DOT(clipped,plane);
   152 template<
typename CLASS_POINT,
typename CLASS_PLANE>
   154         const CLASS_POINT& s1,
   155         const CLASS_POINT &s2,
   156         const CLASS_PLANE &plane,CLASS_POINT &clipped)
   172         _dis2 = 
VEC_DOT(clipped,plane);
   194 template<
typename CLASS_POINT,
typename CLASS_PLANE>
   196         const CLASS_POINT& s1,
   197         const CLASS_POINT &s2,
   198         const CLASS_PLANE &plane,
   199         CLASS_POINT &clipped1,CLASS_POINT &clipped2)
   202         switch(intersection_type)
   227         return intersection_type;
   232 #define PLANE_MINOR_AXES(plane, i0, i1) VEC_MINOR_AXES(plane, i0, i1)   239 template<
typename T,
typename CLASS_POINT,
typename CLASS_PLANE>
   241         const CLASS_PLANE & plane,
   242         const CLASS_POINT & vDir,
   243         const CLASS_POINT & vPoint,
   244         CLASS_POINT & pout,T &tparam)
   253         tparam = -_dis/_dotdir;
   266 template<
typename T,
typename CLASS_POINT,
typename CLASS_PLANE>
   268         const CLASS_PLANE & plane,
   269         const CLASS_POINT & vDir,
   270         const CLASS_POINT & vPoint,
   283         char returnvalue = _dis<0.0f?2:1;
   284         tparam = -_dis/_dotdir;
   312 template<
typename CLASS_POINT,
typename CLASS_PLANE>
   314                 const CLASS_PLANE &p1,
   315                 const CLASS_PLANE &p2,
   323         _n[0]=p1[3]*p2[0] - p2[3]*p1[0];
   324         _n[1]=p1[3]*p2[1] - p2[3]*p1[1];
   325         _n[2]=p1[3]*p2[2] - p2[3]*p1[2];
   337 template<
typename CLASS_POINT>
   339         CLASS_POINT & cp, 
const CLASS_POINT & v,
   340         const CLASS_POINT &e1,
const CLASS_POINT &e2)
   351         else if(_scalar >1.0f)
   374 template<
typename T,
typename CLASS_POINT>
   376         const CLASS_POINT & dir1,
   377         CLASS_POINT & point1,
   378         const CLASS_POINT & dir2,
   379         CLASS_POINT &  point2,
   390         det = e1e2*e1e2 - e1e1*e2e2;
   392         t1 = (e1e2*p1p2e2 - e2e2*p1p2e1)/det;
   393         t2 = (e1e1*p1p2e2 - e1e2*p1p2e1)/det;
   398 template<
typename CLASS_POINT>
   400         const CLASS_POINT & vA1,
   401         const CLASS_POINT & vA2,
   402         const CLASS_POINT & vB1,
   403         const CLASS_POINT & vB2,
   404         CLASS_POINT & vPointA,
   405         CLASS_POINT & vPointB)
   407     CLASS_POINT _AD,_BD,n;
   416         bool invert_b_order = 
false;
   421                 invert_b_order  = 
true;
   427         n[0] = (_M[0]+_M[1])*0.5f;
   428         n[1] = (_M[2]+_M[3])*0.5f;
   434                         vPointB = invert_b_order?vB1:vB2;
   439                         vPointB = invert_b_order?vB1:vB2;
   452                         vPointB = invert_b_order?vB2:vB1;
   462                         vPointB = invert_b_order?vB1:vB2;
   502         return !(pos < bmin || pos > bmax);
   504         GREAL a0 = (bmin - pos) / dir;
   505         GREAL a1 = (bmax - pos) / dir;
   509         if (tlast < tfirst) 
return false;
   518                 GUINT * order_indices)
   521         order_indices[0] = values[0] < values[1] ? (values[0] < values[2] ? 0 : 2) : (values[1] < values[2] ? 1 : 2);
   524         GUINT i0 = (order_indices[0] + 1)%3;
   525         GUINT i1 = (i0 + 1)%3;
   527         if(values[i0] < values[i1])
   529                 order_indices[1] = i0;
   530                 order_indices[2] = i1;
   534                 order_indices[1] = i1;
   535                 order_indices[2] = i0;
   543 #endif // GIM_VECTOR_H_INCLUDED GUINT LINE_PLANE_COLLISION(const CLASS_PLANE &plane, const CLASS_POINT &vDir, const CLASS_POINT &vPoint, CLASS_POINT &pout, T &tparam, T tmin, T tmax)
line collision 
#define GIM_CLAMP(number, minval, maxval)
returns a clamped number 
#define GIM_IS_ZERO(value)
eLINE_PLANE_INTERSECTION_TYPE
#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. 
#define GIM_SWAP_NUMBERS(a, b)
Swap numbers. 
bool INTERSECT_PLANES(const CLASS_PLANE &p1, const CLASS_PLANE &p2, CLASS_POINT &p, CLASS_POINT &d)
Returns the Ray on which 2 planes intersect if they do. Written by Rodrigo Hernandez on ODE convex co...
bool BOX_AXIS_INTERSECT(T pos, T dir, T bmin, T bmax, T &tfirst, T &tlast)
Line box intersection in one dimension. 
#define VEC_COPY(b, a)
Copy 3D vector. 
eLINE_PLANE_INTERSECTION_TYPE PLANE_CLIP_SEGMENT_CLOSEST(const CLASS_POINT &s1, const CLASS_POINT &s2, const CLASS_PLANE &plane, CLASS_POINT &clipped1, CLASS_POINT &clipped2)
Confirms if the plane intersect the edge or not. 
#define VEC_SCALE(c, a, b)
scalar times vector 
void PLANE_CLIP_SEGMENT(const CLASS_POINT &s1, const CLASS_POINT &s2, const CLASS_PLANE &plane, CLASS_POINT &clipped)
#define VEC_DOT(a, b)
Vector dot product. 
#define VEC_DIFF(v21, v2, v1)
Vector difference. 
#define VEC_SUM(v21, v2, v1)
Vector sum. 
GREAL vec3f[3]
Float vector 3D. 
bool LINE_INTERSECTION_PARAMS(const CLASS_POINT &dir1, CLASS_POINT &point1, const CLASS_POINT &dir2, CLASS_POINT &point2, T &t1, T &t2)
Finds the line params where these lines intersect. 
eLINE_PLANE_INTERSECTION_TYPE PLANE_CLIP_SEGMENT2(const CLASS_POINT &s1, const CLASS_POINT &s2, const CLASS_PLANE &plane, CLASS_POINT &clipped)
Confirms if the plane intersect the edge or nor. 
#define DISTANCE_PLANE_POINT(plane, point)
bool POINT_IN_HULL(const CLASS_POINT &point, const CLASS_PLANE *planes, GUINT plane_count)
Verifies if a point is in the plane hull. 
GREAL vec4f[4]
Float vector 4D. 
#define VEC_CROSS(c, a, b)
Vector cross. 
void SORT_3_INDICES(const T *values, GUINT *order_indices)
Sorts 3 componets. 
bool RAY_PLANE_COLLISION(const CLASS_PLANE &plane, const CLASS_POINT &vDir, const CLASS_POINT &vPoint, CLASS_POINT &pout, T &tparam)
Ray plane collision in one way. 
void CLOSEST_POINT_ON_SEGMENT(CLASS_POINT &cp, const CLASS_POINT &v, const CLASS_POINT &e1, const CLASS_POINT &e2)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
btScalar btFabs(btScalar x)