1 #ifndef GIM_BASIC_GEOMETRY_OPERATIONS_H_INCLUDED 2 #define GIM_BASIC_GEOMETRY_OPERATIONS_H_INCLUDED 44 #ifndef PLANEDIREPSILON 45 #define PLANEDIREPSILON 0.0000001f 48 #ifndef PARALELENORMALS 49 #define PARALELENORMALS 0.000001f 52 #define TRIANGLE_NORMAL(v1,v2,v3,n)\ 55 VEC_DIFF(_dif1,v2,v1);\ 56 VEC_DIFF(_dif2,v3,v1);\ 57 VEC_CROSS(n,_dif1,_dif2);\ 61 #define TRIANGLE_NORMAL_FAST(v1,v2,v3,n){\ 63 VEC_DIFF(_dif1,v2,v1); \ 64 VEC_DIFF(_dif2,v3,v1); \ 65 VEC_CROSS(n,_dif1,_dif2); \ 68 #define TRIANGLE_PLANE(v1,v2,v3,plane) {\ 70 TRIANGLE_NORMAL(v1,v2,v3,plane);\ 71 plane[3] = VEC_DOT(v1,plane);\ 74 #define TRIANGLE_PLANE_FAST(v1,v2,v3,plane) {\ 76 TRIANGLE_NORMAL_FAST(v1,v2,v3,plane);\ 77 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) {\ 93 _dis = DISTANCE_PLANE_POINT(plane,point);\ 94 VEC_SCALE(projected,-_dis,plane);\ 95 VEC_SUM(projected,projected,point); \ 98 template<
typename CLASS_POINT,
typename CLASS_PLANE>
101 const CLASS_POINT& point,
const CLASS_PLANE * planes,
GUINT plane_count)
104 for (
GUINT _i = 0;_i< plane_count;++_i)
107 if(_dis>0.0f)
return false;
112 template<
typename CLASS_POINT,
typename CLASS_PLANE>
114 const CLASS_POINT& s1,
115 const CLASS_POINT &s2,
const CLASS_PLANE &plane,CLASS_POINT &clipped)
120 _dis2 =
VEC_DOT(clipped,plane);
155 template<
typename CLASS_POINT,
typename CLASS_PLANE>
157 const CLASS_POINT& s1,
158 const CLASS_POINT &s2,
159 const CLASS_PLANE &plane,CLASS_POINT &clipped)
175 _dis2 =
VEC_DOT(clipped,plane);
197 template<
typename CLASS_POINT,
typename CLASS_PLANE>
199 const CLASS_POINT& s1,
200 const CLASS_POINT &s2,
201 const CLASS_PLANE &plane,
202 CLASS_POINT &clipped1,CLASS_POINT &clipped2)
205 switch(intersection_type)
230 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)
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,
286 char returnvalue = _dis<0.0f?2:1;
287 tparam = -_dis/_dotdir;
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)
377 template<
typename T,
typename CLASS_POINT>
379 const CLASS_POINT & dir1,
380 CLASS_POINT & point1,
381 const CLASS_POINT & dir2,
382 CLASS_POINT & point2,
393 det = e1e2*e1e2 - e1e1*e2e2;
395 t1 = (e1e2*p1p2e2 - e2e2*p1p2e1)/det;
396 t2 = (e1e1*p1p2e2 - e1e2*p1p2e1)/det;
401 template<
typename CLASS_POINT>
403 const CLASS_POINT & vA1,
404 const CLASS_POINT & vA2,
405 const CLASS_POINT & vB1,
406 const CLASS_POINT & vB2,
407 CLASS_POINT & vPointA,
408 CLASS_POINT & vPointB)
410 CLASS_POINT _AD,_BD,n;
419 bool invert_b_order =
false;
424 invert_b_order =
true;
430 n[0] = (_M[0]+_M[1])*0.5f;
431 n[1] = (_M[2]+_M[3])*0.5f;
437 vPointB = invert_b_order?vB1:vB2;
442 vPointB = invert_b_order?vB1:vB2;
455 vPointB = invert_b_order?vB2:vB1;
465 vPointB = invert_b_order?vB1:vB2;
505 return !(pos < bmin || pos > bmax);
507 GREAL a0 = (bmin - pos) / dir;
508 GREAL a1 = (bmax - pos) / dir;
512 if (tlast < tfirst)
return false;
521 GUINT * order_indices)
524 order_indices[0] = values[0] < values[1] ? (values[0] < values[2] ? 0 : 2) : (values[1] < values[2] ? 1 : 2);
527 GUINT i0 = (order_indices[0] + 1)%3;
528 GUINT i1 = (i0 + 1)%3;
530 if(values[i0] < values[i1])
532 order_indices[1] = i0;
533 order_indices[2] = i1;
537 order_indices[1] = i1;
538 order_indices[2] = i0;
546 #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)