Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OPC_TriTriOverlap.h File Reference

Go to the source code of this file.

Macros

#define LOCAL_EPSILON   0.000001f
 if OPC_TRITRI_EPSILON_TEST is true then we do a check (if |dv|<EPSILON then dv=0.0;) else no check is done (which is less robust, but faster) More...
 
#define SORT(a, b)
 sort so that a<=b More...
 
#define EDGE_EDGE_TEST(V0, U0, U1)
 Edge to edge test based on Franlin Antonio's gem: "Faster Line Segment Intersection", in Graphics Gems III, pp. 199-202. More...
 
#define EDGE_AGAINST_TRI_EDGES(V0, V1, U0, U1, U2)
 TO BE DOCUMENTED. More...
 
#define POINT_IN_TRI(V0, U0, U1, U2)
 TO BE DOCUMENTED. More...
 
#define NEWCOMPUTE_INTERVALS(VV0, VV1, VV2, D0, D1, D2, D0D1, D0D2, A, B, C, X0, X1)
 TO BE DOCUMENTED. More...
 

Functions

bool CoplanarTriTri (const Point &n, const Point &v0, const Point &v1, const Point &v2, const Point &u0, const Point &u1, const Point &u2)
 TO BE DOCUMENTED. More...
 

Macro Definition Documentation

#define EDGE_AGAINST_TRI_EDGES (   V0,
  V1,
  U0,
  U1,
  U2 
)
Value:
{ \
float Bx,By,Cx,Cy,d,f; \
const float Ax = V1[i0] - V0[i0]; \
const float Ay = V1[i1] - V0[i1]; \
/* test edge U0,U1 against V0,V1 */ \
EDGE_EDGE_TEST(V0, U0, U1); \
/* test edge U1,U2 against V0,V1 */ \
EDGE_EDGE_TEST(V0, U1, U2); \
/* test edge U2,U1 against V0,V1 */ \
EDGE_EDGE_TEST(V0, U2, U0); \
}

TO BE DOCUMENTED.

Definition at line 36 of file OPC_TriTriOverlap.h.

Referenced by CoplanarTriTri().

#define EDGE_EDGE_TEST (   V0,
  U0,
  U1 
)
Value:
Bx = U0[i0] - U1[i0]; \
By = U0[i1] - U1[i1]; \
Cx = V0[i0] - U0[i0]; \
Cy = V0[i1] - U0[i1]; \
f = Ay*Bx - Ax*By; \
d = By*Cx - Bx*Cy; \
if((f>0.0f && d>=0.0f && d<=f) || (f<0.0f && d<=0.0f && d>=f)) \
{ \
const float e=Ax*Cy - Ay*Cx; \
if(f>0.0f) \
{ \
if(e>=0.0f && e<=f) return TRUE; \
} \
else \
{ \
if(e<=0.0f && e>=f) return TRUE; \
} \
}

Edge to edge test based on Franlin Antonio's gem: "Faster Line Segment Intersection", in Graphics Gems III, pp. 199-202.

Definition at line 15 of file OPC_TriTriOverlap.h.

#define LOCAL_EPSILON   0.000001f

if OPC_TRITRI_EPSILON_TEST is true then we do a check (if |dv|<EPSILON then dv=0.0;) else no check is done (which is less robust, but faster)

Definition at line 3 of file OPC_TriTriOverlap.h.

#define NEWCOMPUTE_INTERVALS (   VV0,
  VV1,
  VV2,
  D0,
  D1,
  D2,
  D0D1,
  D0D2,
  A,
  B,
  C,
  X0,
  X1 
)

TO BE DOCUMENTED.

Definition at line 124 of file OPC_TriTriOverlap.h.

#define POINT_IN_TRI (   V0,
  U0,
  U1,
  U2 
)
Value:
{ \
/* is T1 completly inside T2? */ \
/* check if V0 is inside tri(U0,U1,U2) */ \
float a = U1[i1] - U0[i1]; \
float b = -(U1[i0] - U0[i0]); \
float c = -a*U0[i0] - b*U0[i1]; \
float d0 = a*V0[i0] + b*V0[i1] + c; \
\
a = U2[i1] - U1[i1]; \
b = -(U2[i0] - U1[i0]); \
c = -a*U1[i0] - b*U1[i1]; \
const float d1 = a*V0[i0] + b*V0[i1] + c; \
\
a = U0[i1] - U2[i1]; \
b = -(U0[i0] - U2[i0]); \
c = -a*U2[i0] - b*U2[i1]; \
const float d2 = a*V0[i0] + b*V0[i1] + c; \
if(d0*d1>0.0f) \
{ \
if(d0*d2>0.0f) return TRUE; \
} \
}

TO BE DOCUMENTED.

Definition at line 50 of file OPC_TriTriOverlap.h.

Referenced by CoplanarTriTri().

#define SORT (   a,
  b 
)
Value:
if(a>b) \
{ \
const float c=a; \
a=b; \
b=c; \
}

sort so that a<=b

Definition at line 6 of file OPC_TriTriOverlap.h.

Function Documentation

bool CoplanarTriTri ( const Point n,
const Point v0,
const Point v1,
const Point v2,
const Point u0,
const Point u1,
const Point u2 
)

TO BE DOCUMENTED.

Definition at line 75 of file OPC_TriTriOverlap.h.

References EDGE_AGAINST_TRI_EDGES, FALSE, and POINT_IN_TRI.

76 {
77  float A[3];
78  short i0,i1;
79  /* first project onto an axis-aligned plane, that maximizes the area */
80  /* of the triangles, compute indices: i0,i1. */
81  A[0] = fabsf(n[0]);
82  A[1] = fabsf(n[1]);
83  A[2] = fabsf(n[2]);
84  if(A[0]>A[1])
85  {
86  if(A[0]>A[2])
87  {
88  i0=1; /* A[0] is greatest */
89  i1=2;
90  }
91  else
92  {
93  i0=0; /* A[2] is greatest */
94  i1=1;
95  }
96  }
97  else /* A[0]<=A[1] */
98  {
99  if(A[2]>A[1])
100  {
101  i0=0; /* A[2] is greatest */
102  i1=1;
103  }
104  else
105  {
106  i0=0; /* A[1] is greatest */
107  i1=2;
108  }
109  }
110 
111  /* test all edges of triangle 1 against the edges of triangle 2 */
112  EDGE_AGAINST_TRI_EDGES(v0, v1, u0, u1, u2);
113  EDGE_AGAINST_TRI_EDGES(v1, v2, u0, u1, u2);
114  EDGE_AGAINST_TRI_EDGES(v2, v0, u0, u1, u2);
115 
116  /* finally, test if tri1 is totally contained in tri2 or vice versa */
117  POINT_IN_TRI(v0, u0, u1, u2);
118  POINT_IN_TRI(u0, v0, v1, v2);
119 
120  return FALSE;
121 }