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

Comparing ray/src/gen/replmarks.c (file contents):
Revision 2.2 by greg, Tue Mar 3 21:30:03 1992 UTC vs.
Revision 2.10 by greg, Fri Jan 2 17:11:40 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 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   * Replace markers in Radiance scene description with objects or instances.
6   *
7   *      Created:        17 Feb 1991     Greg Ward
8   */
9  
10 < #include <stdio.h>
10 > #include <stdlib.h>
11   #include <ctype.h>
12   #include <math.h>
13 + #include <stdio.h>
14  
15 + #include "platform.h"
16 + #include "rtio.h"
17 + #include "rtprocess.h"
18   #include "fvect.h"
19  
20   #ifdef  M_PI
21 < #define  PI             M_PI
21 > #define  PI             ((double)M_PI)
22   #else
23   #define  PI             3.14159265358979323846
24   #endif
# Line 45 | Line 46 | int    expand;                 /* expand commands? */
46  
47   char    *progname;
48  
49 + static void convert(char *name, FILE *fin);
50 + static void cvcomm(char *fname, FILE *fin);
51 + static void cvobject(char *fname, FILE *fin);
52 + static void replace(char *fname, struct mrkr *m, char *mark, FILE *fin);
53 + static int edgecmp(const void *e1, const void *e2);
54 + static int buildxf(char *xf, double markscale, FILE *fin);
55 + static int addrot(char *xf, FVECT xp, FVECT yp, FVECT zp);
56  
57 < main(argc, argv)
58 < int     argc;
59 < char    *argv[];
57 >
58 > int
59 > main(
60 >        int     argc,
61 >        char    *argv[]
62 > )
63   {
64          FILE    *fp;
65          int     i, j;
# Line 108 | Line 119 | char   *argv[];
119                          convert(argv[i], fp);
120                          fclose(fp);
121                  }
122 <        exit(0);
122 >        return 0;
123   userr:
124          fprintf(stderr,
125   "Usage: %s [-e][-s size][-m modout] {-x objfile|-i octree} modname .. [file ..]\n",
126                  progname);
127 <        exit(1);
127 >        return 1;
128   }
129  
130  
131 < convert(name, fin)              /* replace marks in a stream */
132 < char    *name;
133 < register FILE   *fin;
131 > void
132 > convert(                /* replace marks in a stream */
133 >        char    *name,
134 >        register FILE   *fin
135 > )
136   {
137          register int    c;
138  
# Line 144 | Line 157 | register FILE  *fin;
157   }
158  
159  
160 < cvcomm(fname, fin)              /* convert a command */
161 < char    *fname;
162 < FILE    *fin;
160 > void
161 > cvcomm(         /* convert a command */
162 >        char    *fname,
163 >        FILE    *fin
164 > )
165   {
166 <        FILE    *pin, *popen();
166 >        FILE    *pin;
167          char    buf[512], *fgetline();
168  
169          fgetline(buf, sizeof(buf), fin);
# Line 166 | Line 181 | FILE   *fin;
181   }
182  
183  
184 < cvobject(fname, fin)            /* convert an object */
185 < char    *fname;
186 < FILE    *fin;
184 > void
185 > cvobject(               /* convert an object */
186 >        char    *fname,
187 >        FILE    *fin
188 > )
189   {
190 +        extern char     *fgetword();
191          char    buf[128], typ[16], nam[128];
192          int     i, n;
193          register int    j;
# Line 194 | Line 212 | FILE   *fin;
212                          goto readerr;
213                  printf("%d", n);
214                  for (j = 0; j < n; j++) {
215 <                        if (fscanf(fin, "%s", buf) != 1)
215 >                        if (fgetword(buf, sizeof(buf), fin) == NULL)
216                                  goto readerr;
217                          if (j%3 == 0)
218                                  putchar('\n');
219 <                        printf("\t%s", buf);
219 >                        putchar('\t');
220 >                        fputword(buf, stdout);
221                  }
222                  putchar('\n');
223          }
# Line 209 | Line 228 | readerr:
228   }
229  
230  
231 < replace(fname, m, mark, fin)            /* replace marker */
232 < char    *fname;
233 < register struct mrkr    *m;
234 < char    *mark;
235 < FILE    *fin;
231 > void
232 > replace(                /* replace marker */
233 >        char    *fname,
234 >        register struct mrkr    *m,
235 >        char    *mark,
236 >        FILE    *fin
237 > )
238   {
239          int     n;
240          char    buf[256];
241  
242 +        buf[0] = '\0';                  /* bug fix thanks to schorsch */
243          if (m->doxform) {
244 <                sprintf(buf, "xform -e -n %s", mark);
244 >                sprintf(buf, "xform -n %s", mark);
245                  if (m->modout != NULL)
246                          sprintf(buf+strlen(buf), " -m %s", m->modout);
247                  if (buildxf(buf+strlen(buf), m->mscale, fin) < 0)
# Line 245 | Line 267 | badxf:
267   }
268  
269  
270 < edgecmp(e1, e2)                 /* compare two edges, descending order */
271 < EDGE    *e1, *e2;
270 > int
271 > edgecmp(                        /* compare two edges, descending order */
272 >        const void *e1,
273 >        const void *e2
274 > )
275   {
276 <        if (e1->len2 > e2->len2)
276 >        if (((EDGE*)e1)->len2 > ((EDGE*)e2)->len2)
277                  return(-1);
278 <        if (e1->len2 < e2->len2)
278 >        if (((EDGE*)e1)->len2 < ((EDGE*)e2)->len2)
279                  return(1);
280          return(0);
281   }
282  
283  
284   int
285 < buildxf(xf, markscale, fin)             /* build transform for marker */
286 < char    *xf;
287 < double  markscale;
288 < FILE    *fin;
285 > buildxf(                /* build transform for marker */
286 >        register char   *xf,
287 >        double  markscale,
288 >        FILE    *fin
289 > )
290   {
291          static FVECT    vlist[MAXVERT];
292          static EDGE     elist[MAXVERT];
# Line 325 | Line 351 | FILE   *fin;
351          if (markscale > 0.0) {          /* add scale factor */
352                  sprintf(xf, " -s %f", xlen*markscale);
353                  n += 2;
354 <                xf += strlen(xf);
354 >                while (*xf) ++xf;
355          }
356                                          /* add rotation */
357          n += addrot(xf, xvec, yvec, zvec);
358 <        xf += strlen(xf);
358 >        while (*xf) ++xf;
359                                          /* add translation */
360          n += 4;
361          sprintf(xf, " -t %f %f %f", vlist[elist[1].beg][0],
# Line 338 | Line 364 | FILE   *fin;
364   }
365  
366  
367 < addrot(xf, xp, yp, zp)          /* compute rotation (x,y,z) => (xp,yp,zp) */
368 < char    *xf;
369 < FVECT   xp, yp, zp;
367 > int
368 > addrot(         /* compute rotation (x,y,z) => (xp,yp,zp) */
369 >        register char   *xf,
370 >        FVECT xp,
371 >        FVECT yp,
372 >        FVECT zp
373 > )
374   {
375          int     n;
376          double  theta;
# Line 349 | Line 379 | FVECT  xp, yp, zp;
379          theta = atan2(yp[2], zp[2]);
380          if (!FEQ(theta,0.0)) {
381                  sprintf(xf, " -rx %f", theta*(180./PI));
382 <                xf += strlen(xf);
382 >                while (*xf) ++xf;
383                  n += 2;
384          }
385          theta = asin(-xp[2]);
386          if (!FEQ(theta,0.0)) {
387                  sprintf(xf, " -ry %f", theta*(180./PI));
388 <                xf += strlen(xf);
388 >                while (*xf) ++xf;
389                  n += 2;
390          }
391          theta = atan2(xp[1], xp[0]);
392          if (!FEQ(theta,0.0)) {
393                  sprintf(xf, " -rz %f", theta*(180./PI));
394 <                /* xf += strlen(xf); */
394 >                /* while (*xf) ++xf; */
395                  n += 2;
396          }
397          return(n);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines