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

Comparing ray/src/cv/mgf2rad.c (file contents):
Revision 2.24 by gwlarson, Wed Jun 9 14:06:00 1999 UTC vs.
Revision 2.27 by schorsch, Sun Jul 27 22:12:01 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1996 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Convert MGF (Materials and Geometry Format) to Radiance
6   */
7  
8   #include <stdio.h>
9 + #include <stdlib.h>
10   #include <math.h>
11   #include <string.h>
12   #include "mgflib/parser.h"
# Line 165 | Line 163 | char   **av;
163                  if (r2 == 0.)
164                          return(MG_EILL);
165                  inv = r2 < 0.;
166 <        } else if (r2 != 0. && inv ^ r2 < 0.)
166 >        } else if (r2 != 0. && inv ^ (r2 < 0.))
167                  return(MG_EILL);
168          if (inv) {
169                  r1 = -r1;
# Line 278 | Line 276 | char   **av;
276          xf_rotvect(norm, cv->n);                /* rotate normal */
277          r1 = xf_scale(atof(av[2]));             /* scale radii */
278          r2 = xf_scale(atof(av[3]));
279 <        if (r1 < 0. | r2 <= r1)
279 >        if ((r1 < 0.) | (r2 <= r1))
280                  return(MG_EILL);
281          if ((mat = material()) == NULL)         /* get material */
282                  return(MG_EBADMAT);
# Line 298 | Line 296 | int    ac;
296   char    **av;
297   {
298          static int      nfaces;
299 +        int             myi = invert;
300          char    *mat;
301          register int    i;
302          register C_VERTEX       *cv;
# Line 316 | Line 315 | char   **av;
315                          if (is0vect(cva[i-1]->n))
316                                  break;
317                  }
318 <                if (i == ac) {
318 >                if (i < ac)
319 >                        i = ISFLAT;
320 >                else
321                          i = flat_tri(cva[0]->p, cva[1]->p, cva[2]->p,
322                                          cva[0]->n, cva[1]->n, cva[2]->n);
323 <                        if (i < 0)
324 <                                return(MG_OK);  /* degenerate (error?) */
323 >                if (i == DEGEN)
324 >                        return(MG_OK);          /* degenerate (error?) */
325 >                if (i == RVBENT) {
326 >                        myi = !myi;
327 >                        i = ISBENT;
328 >                } else if (i == RVFLAT) {
329 >                        myi = !myi;
330 >                        i = ISFLAT;
331                  }
332 <                if (!i) {                       /* smoothed triangles */
333 <                        do_tri(mat, cva[0], cva[1], cva[2]);
332 >                if (i == ISBENT) {              /* smoothed triangles */
333 >                        do_tri(mat, cva[0], cva[1], cva[2], myi);
334                          if (ac == 5)
335 <                                do_tri(mat, cva[2], cva[3], cva[0]);
335 >                                do_tri(mat, cva[2], cva[3], cva[0], myi);
336                          return(MG_OK);
337                  }
338          }
# Line 333 | Line 340 | char   **av;
340          printf("\n%s polygon %sf%d\n", mat, object(), ++nfaces);
341          printf("0\n0\n%d\n", 3*(ac-1));
342          for (i = 1; i < ac; i++) {      /* get, transform, print each vertex */
343 <                if ((cv = c_getvert(av[invert ? ac-i : i])) == NULL)
343 >                if ((cv = c_getvert(av[myi ? ac-i : i])) == NULL)
344                          return(MG_EUNDEF);
345                  xf_xfmpoint(v, cv->p);
346                  putv(v);
# Line 407 | Line 414 | char   **av;
414   }
415  
416  
417 < do_tri(mat, cv1, cv2, cv3)              /* put out smoothed triangle */
417 > do_tri(mat, cv1, cv2, cv3, iv)          /* put out smoothed triangle */
418   char    *mat;
419   C_VERTEX        *cv1, *cv2, *cv3;
420 + int     iv;
421   {
422          static int      ntris;
423          BARYCCM bvecs;
424 <        FLOAT   bcoor[3][3];
424 >        RREAL   bcoor[3][3];
425          C_VERTEX        *cvt;
426          FVECT   v1, v2, v3;
427          FVECT   n1, n2, n3;
428          register int    i;
429  
430 <        if (invert) {                   /* swap vertex order if inverted */
430 >        if (iv) {                       /* swap vertex order if inverted */
431                  cvt = cv1;
432                  cv1 = cv3;
433                  cv3 = cvt;
# Line 482 | Line 490 | material()                     /* get (and print) current material */
490          }
491          d = c_cmaterial->rd + c_cmaterial->td +
492                          c_cmaterial->rs + c_cmaterial->ts;
493 <        if (d < 0. | d > 1.)
493 >        if ((d < 0.) | (d > 1.))
494                  return(NULL);
495                                          /* check for glass/dielectric */
496          if (c_cmaterial->nr > 1.1 &&
# Line 613 | Line 621 | addarg(op, arg)                                /* add argument and advance pointer
621   register char   *op, *arg;
622   {
623          *op = ' ';
624 <        while (*++op = *arg++)
624 >        while ( (*++op = *arg++) )
625                  ;
626          return(op);
627   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines