| Bullet Collision Detection & Physics Library
    | 
 
 
 
Go to the documentation of this file.    1 #ifndef GIM_BASIC_GEOMETRY_OPERATIONS_H_INCLUDED 
    2 #define GIM_BASIC_GEOMETRY_OPERATIONS_H_INCLUDED 
   40 #ifndef PLANEDIREPSILON 
   41 #define PLANEDIREPSILON 0.0000001f 
   44 #ifndef PARALELENORMALS 
   45 #define PARALELENORMALS 0.000001f 
   48 #define TRIANGLE_NORMAL(v1, v2, v3, n) \ 
   51                 VEC_DIFF(_dif1, v2, v1);       \ 
   52                 VEC_DIFF(_dif2, v3, v1);       \ 
   53                 VEC_CROSS(n, _dif1, _dif2);    \ 
   57 #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);         \ 
   66 #define TRIANGLE_PLANE(v1, v2, v3, plane)   \ 
   68                 TRIANGLE_NORMAL(v1, v2, v3, plane); \ 
   69                 plane[3] = VEC_DOT(v1, plane);      \ 
   73 #define TRIANGLE_PLANE_FAST(v1, v2, v3, plane)   \ 
   75                 TRIANGLE_NORMAL_FAST(v1, v2, v3, plane); \ 
   76                 plane[3] = VEC_DOT(v1, plane);           \ 
   80 #define EDGE_PLANE(e1, e2, n, plane)   \ 
   83                 VEC_DIFF(_dif, e2, e1);        \ 
   84                 VEC_CROSS(plane, _dif, n);     \ 
   85                 VEC_NORMALIZE(plane);          \ 
   86                 plane[3] = VEC_DOT(e1, plane); \ 
   89 #define DISTANCE_PLANE_POINT(plane, point) (VEC_DOT(plane, point) - plane[3]) 
   91 #define PROJECT_POINT_PLANE(point, plane, projected) \ 
   94                 _dis = DISTANCE_PLANE_POINT(plane, point);   \ 
   95                 VEC_SCALE(projected, -_dis, plane);          \ 
   96                 VEC_SUM(projected, projected, point);        \ 
  100 template <
typename CLASS_POINT, 
typename CLASS_PLANE>
 
  102         const CLASS_POINT &point, 
const CLASS_PLANE *planes, 
GUINT plane_count)
 
  105         for (
GUINT _i = 0; _i < plane_count; ++_i)
 
  108                 if (_dis > 0.0f) 
return false;
 
  113 template <
typename CLASS_POINT, 
typename CLASS_PLANE>
 
  115         const CLASS_POINT &s1,
 
  116         const CLASS_POINT &s2, 
const CLASS_PLANE &plane, CLASS_POINT &clipped)
 
  121         _dis2 = 
VEC_DOT(clipped, plane);
 
  122         VEC_SCALE(clipped, -_dis1 / _dis2, clipped);
 
  156 template <
typename CLASS_POINT, 
typename CLASS_PLANE>
 
  158         const CLASS_POINT &s1,
 
  159         const CLASS_POINT &s2,
 
  160         const CLASS_PLANE &plane, CLASS_POINT &clipped)
 
  176         _dis2 = 
VEC_DOT(clipped, plane);
 
  177         VEC_SCALE(clipped, -_dis1 / _dis2, clipped);
 
  198 template <
typename CLASS_POINT, 
typename CLASS_PLANE>
 
  200         const CLASS_POINT &s1,
 
  201         const CLASS_POINT &s2,
 
  202         const CLASS_PLANE &plane,
 
  203         CLASS_POINT &clipped1, CLASS_POINT &clipped2)
 
  206         switch (intersection_type)
 
  231         return intersection_type;
 
  235 #define PLANE_MINOR_AXES(plane, i0, i1) VEC_MINOR_AXES(plane, i0, i1) 
  242 template <
typename T, 
typename CLASS_POINT, 
typename CLASS_PLANE>
 
  244         const CLASS_PLANE &plane,
 
  245         const CLASS_POINT &vDir,
 
  246         const CLASS_POINT &vPoint,
 
  247         CLASS_POINT &pout, T &tparam)
 
  250         _dotdir = 
VEC_DOT(plane, vDir);
 
  256         tparam = -_dis / _dotdir;
 
  269 template <
typename T, 
typename CLASS_POINT, 
typename CLASS_PLANE>
 
  271         const CLASS_PLANE &plane,
 
  272         const CLASS_POINT &vDir,
 
  273         const CLASS_POINT &vPoint,
 
  279         _dotdir = 
VEC_DOT(plane, vDir);
 
  286         char returnvalue = _dis < 0.0f ? 2 : 1;
 
  287         tparam = -_dis / _dotdir;
 
  294         else if (tparam > tmax)
 
  315 template <
typename CLASS_POINT, 
typename CLASS_PLANE>
 
  317         const CLASS_PLANE &p1,
 
  318         const CLASS_PLANE &p2,
 
  326         _n[0] = p1[3] * p2[0] - p2[3] * p1[0];
 
  327         _n[1] = p1[3] * p2[1] - p2[3] * p1[1];
 
  328         _n[2] = p1[3] * p2[2] - p2[3] * p1[2];
 
  340 template <
typename CLASS_POINT>
 
  342         CLASS_POINT &cp, 
const CLASS_POINT &v,
 
  343         const CLASS_POINT &e1, 
const CLASS_POINT &e2)
 
  354         else if (_scalar > 1.0f)
 
  376 template <
typename T, 
typename CLASS_POINT>
 
  378         const CLASS_POINT &dir1,
 
  380         const CLASS_POINT &dir2,
 
  392         det = e1e2 * e1e2 - e1e1 * e2e2;
 
  394         t1 = (e1e2 * p1p2e2 - e2e2 * p1p2e1) / det;
 
  395         t2 = (e1e1 * p1p2e2 - e1e2 * p1p2e1) / det;
 
  400 template <
typename CLASS_POINT>
 
  402         const CLASS_POINT &vA1,
 
  403         const CLASS_POINT &vA2,
 
  404         const CLASS_POINT &vB1,
 
  405         const CLASS_POINT &vB2,
 
  406         CLASS_POINT &vPointA,
 
  407         CLASS_POINT &vPointB)
 
  409         CLASS_POINT _AD, _BD, n;
 
  418                 bool invert_b_order = 
false;
 
  423                         invert_b_order = 
true;
 
  429                 n[0] = (_M[0] + _M[1]) * 0.5f;
 
  430                 n[1] = (_M[2] + _M[3]) * 0.5f;
 
  436                                 vPointB = invert_b_order ? vB1 : vB2;
 
  439                         else if (_M[1] < _M[3])
 
  441                                 vPointB = invert_b_order ? vB1 : vB2;
 
  454                                 vPointB = invert_b_order ? vB2 : vB1;
 
  457                         else if (_M[3] < _M[1])
 
  464                                 vPointB = invert_b_order ? vB1 : vB2;
 
  481         VEC_SUM(vPointB, vPointB, vB1);
 
  495 template <
typename T>
 
  500                 return !(pos < bmin || pos > bmax);
 
  502         GREAL a0 = (bmin - pos) / dir;
 
  503         GREAL a1 = (bmax - pos) / dir;
 
  507         if (tlast < tfirst) 
return false;
 
  512 template <
typename T>
 
  515         GUINT *order_indices)
 
  518         order_indices[0] = values[0] < values[1] ? (values[0] < values[2] ? 0 : 2) : (values[1] < values[2] ? 1 : 2);
 
  521         GUINT i0 = (order_indices[0] + 1) % 3;
 
  522         GUINT i1 = (i0 + 1) % 3;
 
  524         if (values[i0] < values[i1])
 
  526                 order_indices[1] = i0;
 
  527                 order_indices[2] = i1;
 
  531                 order_indices[1] = i1;
 
  532                 order_indices[2] = i0;
 
  536 #endif  // GIM_VECTOR_H_INCLUDED 
 
#define VEC_SCALE(c, a, b)
scalar times vector
#define VEC_DIFF(v21, v2, v1)
Vector difference.
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
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 GIM_CLAMP(number, minval, maxval)
returns a clamped number
void CLOSEST_POINT_ON_SEGMENT(CLASS_POINT &cp, const CLASS_POINT &v, const CLASS_POINT &e1, const CLASS_POINT &e2)
#define VEC_DOT(a, b)
Vector dot product.
#define GIM_IS_ZERO(value)
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
#define GIM_SWAP_NUMBERS(a, b)
Swap numbers.
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
btScalar btFabs(btScalar x)
void PLANE_CLIP_SEGMENT(const CLASS_POINT &s1, const CLASS_POINT &s2, const CLASS_PLANE &plane, CLASS_POINT &clipped)
GREAL vec4f[4]
Float vector 4D.
bool BOX_AXIS_INTERSECT(T pos, T dir, T bmin, T bmax, T &tfirst, T &tlast)
Line box intersection in one dimension.
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.
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.
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.
#define VEC_SUM(v21, v2, v1)
Vector sum.
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...
#define SIMD_FORCE_INLINE
GREAL vec3f[3]
Float vector 3D.
void SORT_3_INDICES(const T *values, GUINT *order_indices)
Sorts 3 componets.
#define VEC_CROSS(c, a, b)
Vector cross.
#define DISTANCE_PLANE_POINT(plane, point)
#define VEC_COPY(b, a)
Copy 3D vector.
bool POINT_IN_HULL(const CLASS_POINT &point, const CLASS_PLANE *planes, GUINT plane_count)
Verifies if a point is in the plane hull.