ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/wfconv.c
(Generate patch)

Comparing ray/src/ot/wfconv.c (file contents):
Revision 2.13 by greg, Tue Jun 10 23:19:00 2014 UTC vs.
Revision 2.18 by greg, Fri Apr 30 16:40:10 2021 UTC

# Line 261 | Line 261 | dominant_axis(char *v1, char *v2, char *v3)
261          for (i = imax = 2; i--; )
262                  if (vn[i]*vn[i] > vn[imax]*vn[imax])
263                          imax = i;
264 <        return(vn[imax]*vn[imax] > FTINY ? imax : -1);
264 >        return(vn[imax]*vn[imax] > FTINY*FTINY*FTINY*FTINY ? imax : -1);
265   }
266  
267 + /* struct needed for triangulation callback */
268 + typedef struct {
269 +        char    **avl;
270 +        int     rev;
271 + } WFpoly;
272 +
273   /* callback for triangle output from polygon */
274   static int
275   tri_out(const Vert2_list *tp, int a, int b, int c)
276   {
277 <        return( puttri( ((char **)tp->p)[a],
278 <                        ((char **)tp->p)[b],
279 <                        ((char **)tp->p)[c] ) );
277 >        WFpoly *        wp = (WFpoly *)tp->p;
278 >
279 >        if (wp->rev)
280 >                return( puttri(wp->avl[c], wp->avl[b], wp->avl[a]) );
281 >
282 >        return( puttri(wp->avl[a], wp->avl[b], wp->avl[c]) );
283   }
284  
285   static int
# Line 279 | Line 288 | putface(                               /* put out an N-sided polygon */
288          char    **av
289   )
290   {
291 <        Vert2_list      *poly = polyAlloc(ac);
291 >        Vert2_list      *poly;
292 >        WFpoly          myps;
293          int             i, ax, ay;
294  
285        if (poly == NULL)
286                return(0);
287        poly->p = (void *)av;
295          for (i = ac-3; i >= 0; i--)     /* identify dominant axis */
296                  if ((ax = dominant_axis(av[i], av[i+1], av[i+2])) >= 0)
297                          break;
298          if (ax < 0)
299                  return(1);              /* ignore degenerate face */
300 +        poly = polyAlloc(ac);
301 +        if (poly == NULL)
302 +                return(0);
303 +        myps.avl = av;
304 +        poly->p = &myps;
305          if (++ax >= 3) ax = 0;
306          ay = ax;
307          if (++ay >= 3) ay = 0;
# Line 303 | Line 315 | putface(                               /* put out an N-sided polygon */
315                  poly->v[i].mX = vlist[vi[0]][ax];
316                  poly->v[i].mY = vlist[vi[0]][ay];
317          }
318 +                                        /* flag for order reversal */
319 +        myps.rev = (polyArea(poly) < .0);
320                                          /* break into triangles & output */
321          if (!polyTriangulate(poly, &tri_out)) {
322                  sprintf(errmsg, "self-intersecting face with %d vertices", ac);
# Line 468 | Line 482 | syntax(                        /* report syntax error and exit */
482          char    *er
483   )
484   {
485 <        sprintf(errmsg, "%s: Wavefront syntax error near line %d: %s\n",
485 >        sprintf(errmsg, "%s: Wavefront syntax error near line %d: %s",
486                          inpfile, lineno, er);
487          error(USER, errmsg);
488   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines