45 #define Dot(u,v) (u[0]*v[0] + u[1]*v[1] + u[2]*v[2])
48 static void Normalize( GLdouble v[3] )
50 GLdouble len = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
61 #define ABS(x) ((x) < 0 ? -(x) : (x))
63 static int LongAxis( GLdouble v[3] )
67 if( ABS(v[1]) > ABS(v[0]) ) { i = 1; }
68 if( ABS(v[2]) > ABS(v[i]) ) { i = 2; }
72 static void ComputeNormal(
GLUtesselator *tess, GLdouble norm[3] )
75 GLdouble c, tLen2, maxLen2;
76 GLdouble maxVal[3], minVal[3], d1[3], d2[3], tNorm[3];
81 maxVal[0] = maxVal[1] = maxVal[2] = -2 * GLU_TESS_MAX_COORD;
82 minVal[0] = minVal[1] = minVal[2] = 2 * GLU_TESS_MAX_COORD;
84 for( v = vHead->next; v != vHead; v = v->next ) {
85 for( i = 0; i < 3; ++i ) {
87 if( c < minVal[i] ) { minVal[i] = c; minVert[i] = v; }
88 if( c > maxVal[i] ) { maxVal[i] = c; maxVert[i] = v; }
96 if( maxVal[1] - minVal[1] > maxVal[0] - minVal[0] ) { i = 1; }
97 if( maxVal[2] - minVal[2] > maxVal[i] - minVal[i] ) { i = 2; }
98 if( minVal[i] >= maxVal[i] ) {
100 norm[0] = 0; norm[1] = 0; norm[2] = 1;
110 d1[0] = v1->coords[0] - v2->coords[0];
111 d1[1] = v1->coords[1] - v2->coords[1];
112 d1[2] = v1->coords[2] - v2->coords[2];
113 for( v = vHead->next; v != vHead; v = v->next ) {
114 d2[0] = v->coords[0] - v2->coords[0];
115 d2[1] = v->coords[1] - v2->coords[1];
116 d2[2] = v->coords[2] - v2->coords[2];
117 tNorm[0] = d1[1]*d2[2] - d1[2]*d2[1];
118 tNorm[1] = d1[2]*d2[0] - d1[0]*d2[2];
119 tNorm[2] = d1[0]*d2[1] - d1[1]*d2[0];
120 tLen2 = tNorm[0]*tNorm[0] + tNorm[1]*tNorm[1] + tNorm[2]*tNorm[2];
121 if( tLen2 > maxLen2 ) {
131 norm[0] = norm[1] = norm[2] = 0;
132 norm[LongAxis(d1)] = 1;
140 GLUface *f, *fHead = &tess->mesh->fHead;
141 GLUvertex *v, *vHead = &tess->mesh->vHead;
148 for( f = fHead->next; f != fHead; f = f->next ) {
150 if( e->winding <= 0 )
continue;
152 area += (e->Org->s - e->Dst->s) * (e->Org->t + e->Dst->t);
154 }
while( e != f->anEdge );
158 for( v = vHead->next; v != vHead; v = v->next ) {
161 tess->tUnit[0] = - tess->tUnit[0];
162 tess->tUnit[1] = - tess->tUnit[1];
163 tess->tUnit[2] = - tess->tUnit[2];
167 #ifdef FOR_TRITE_TEST_PROGRAM
169 extern int RandomSweep;
170 #define S_UNIT_X (RandomSweep ? (2*drand48()-1) : 1.0)
171 #define S_UNIT_Y (RandomSweep ? (2*drand48()-1) : 0.0)
173 #if defined(SLANTED_SWEEP)
183 #define S_UNIT_X 0.50941539564955385
184 #define S_UNIT_Y 0.86052074622010633
196 GLUvertex *v, *vHead = &tess->mesh->vHead;
198 GLdouble *sUnit, *tUnit;
199 int i, computedNormal = FALSE;
201 norm[0] = tess->normal[0];
202 norm[1] = tess->normal[1];
203 norm[2] = tess->normal[2];
204 if( norm[0] == 0 && norm[1] == 0 && norm[2] == 0 ) {
205 ComputeNormal( tess, norm );
206 computedNormal = TRUE;
210 i = LongAxis( norm );
212 #if defined(FOR_TRITE_TEST_PROGRAM) || defined(TRUE_PROJECT)
219 sUnit[(i+1)%3] = S_UNIT_X;
220 sUnit[(i+2)%3] = S_UNIT_Y;
223 w = Dot( sUnit, norm );
224 sUnit[0] -= w * norm[0];
225 sUnit[1] -= w * norm[1];
226 sUnit[2] -= w * norm[2];
230 tUnit[0] = norm[1]*sUnit[2] - norm[2]*sUnit[1];
231 tUnit[1] = norm[2]*sUnit[0] - norm[0]*sUnit[2];
232 tUnit[2] = norm[0]*sUnit[1] - norm[1]*sUnit[0];
237 sUnit[(i+1)%3] = S_UNIT_X;
238 sUnit[(i+2)%3] = S_UNIT_Y;
241 tUnit[(i+1)%3] = (norm[i] > 0) ? -S_UNIT_Y : S_UNIT_Y;
242 tUnit[(i+2)%3] = (norm[i] > 0) ? S_UNIT_X : -S_UNIT_X;
246 for( v = vHead->next; v != vHead; v = v->next ) {
247 v->s = Dot( v->coords, sUnit );
248 v->t = Dot( v->coords, tUnit );
250 if( computedNormal ) {
251 CheckOrientation( tess );