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