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

Comparing ray/src/util/glrad.c (file contents):
Revision 3.14 by greg, Mon May 19 16:32:19 2003 UTC vs.
Revision 3.26 by greg, Thu Apr 28 16:28:20 2016 UTC

# Line 11 | Line 11 | static const char      RCSid[] = "$Id$";
11   #include <X11/extensions/SGIStereo.h>
12   #endif
13   #include <ctype.h>
14 + #include <string.h>
15   #include <time.h>
16 +
17   #include "radogl.h"
18   #include "view.h"
19   #include "paths.h"
20   #include "glradicon.h"
21 + #include "rtprocess.h"
22  
23   #ifndef MAXVIEW
24   #define MAXVIEW         63              /* maximum number of standard views */
# Line 24 | Line 27 | static const char      RCSid[] = "$Id$";
27   #define MAXSCENE        127             /* maximum number of scene files */
28   #endif
29  
30 < #define ZOOMPCT         9               /* percent to zoom at a time */
30 > #define ZOOMPCT         9               /* percent to zoom for +/- */
31 > #define WZOOMPCT        3               /* percent to zoom for mouse wheel */
32  
33 < #define MOVPCT          7               /* percent distance to move /frame */
33 > #define MOVPCT          4               /* percent distance to move /frame */
34   #define MOVDIR(b)       ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1)
35 < #define MOVDEG          (-5)            /* degrees to orbit CW/down /frame */
35 > #define MOVDEG          (-1.5)          /* degrees to orbit CW/down /frame */
36   #define MOVORB(s)       ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
37  
38   #define BORWIDTH        5               /* border width */
# Line 72 | Line 76 | char   *scene[MAXSCENE+1];             /* material and scene file l
76   int     nscenef = 0;                    /* number of scene files */
77   char    *octree;                        /* octree name (NULL if unnec.) */
78  
79 < int     rtpd[3];                        /* rtrace process descriptors */
79 > SUBPROC rtpd;                   /* rtrace process descriptors */
80  
81   int     silent = 0;                     /* run rad silently? */
82   int     backvis = 1;                    /* back faces visible? */
83   int     stereo = 0;                     /* do stereo? */
84  
85   #ifdef NOSTEREO
86 < #define setstereobuf(bid)       0
86 > #define setstereobuf(bid)      
87   #else
88   #define setstereobuf(bid)       (glXWaitGL(), \
89                                  XSGISetStereoBuffer(ourdisplay, gwind, bid), \
# Line 90 | Line 94 | int    displist;                       /* our scene display list */
94  
95   int     no_render = 0;                  /* don't rerender */
96  
93 extern char     *fgetline(), *atos(), *scan4var();
97   extern int      nowarn;                 /* turn warnings off? */
98  
99 + static void startrtrace(char    *octname);
100 + static void runrad(int  ac, char        **av);
101 + static int findvw(char  *nm);
102 + static int varmatch(char        *s, char        *vn);
103 + static char * scan4var(char     *buf, int       buflen, char    *vname, FILE    *fp);
104 + static void dev_open(char  *id);
105 + static void dev_close(void);
106 + static int dev_view(VIEW        *nv);
107 + static int dev_input(int        nsecs);
108 + static void render(void);
109 + static int moveview(int dx, int dy, int mov, int        orb);
110 + static void waitabit(void);
111 + static void getmove(XButtonPressedEvent *ebut);
112 + static int getintersect(FVECT   wp, FVECT       org, FVECT      dir, double     md);
113 + static void setglpersp(VIEW     *vp);
114 + static int getkey(XKeyPressedEvent  *ekey);
115 + static void zoomview(int        pct, int        dx, int dy);
116 + static void gotoview(int        vwnum);
117 + static void appendview(char     *nm, VIEW       *vp);
118 + static void copylastv(char      *cause);
119 + static void fixwindow(XExposeEvent  *eexp);
120 + static void resizewindow(XConfigureEvent  *ersz);
121  
122 < main(argc, argv)
123 < int     argc;
124 < char    *argv[];
122 >
123 > int
124 > main(
125 >        int     argc,
126 >        char    *argv[]
127 > )
128   {
129          char    *viewsel = NULL;
130          long    vwintvl = 0;
# Line 135 | Line 163 | char   *argv[];
163                                          /* run rad and get views */
164          runrad(argc-i, argv+i);
165                                          /* check view */
166 <        if (viewsel != NULL)
166 >        if (viewsel != NULL) {
167                  if (viewsel[0] == '-') {
168                          char    *ve = viewsel;
169                          if (!sscanview(&thisview, viewsel) ||
# Line 150 | Line 178 | char   *argv[];
178                                                  progname, viewsel);
179                          quit(1);
180                  }
181 +        }
182                                          /* open GL */
183          dev_open(radfile = argv[i]);
184                                          /* load octree or scene files */
# Line 170 | Line 199 | userr:
199                  "Usage: %s [-w][-s][-b][-S][-v view] rfile [VAR=value]..\n",
200                          argv[0]);
201          quit(1);
202 +        return 1; /* pro forma return */
203   }
204  
205  
206   void
207 < quit(code)                              /* exit gracefully */
208 < int     code;
207 > quit(                           /* exit gracefully */
208 >        int     code
209 > )
210   {
211          if (ourdisplay != NULL)
212                  dev_close();
213 <        if (rtpd[2] > 0) {
214 <                if (close_process(rtpd) > 0)
213 >        /* if (rtpd.pid > 0) { */
214 >        if (rtpd.running) {
215 >                if (close_process(&rtpd) > 0)
216                          wputs("bad exit status from rtrace\n");
217 <                rtpd[2] = 0;
217 >                /* rtpd.pid = 0; */
218          }
219          exit(code);
220   }
221  
222  
223 < startrtrace(octname)                    /* start rtrace on octname */
224 < char    *octname;
223 > static void
224 > startrtrace(                    /* start rtrace on octname */
225 >        char    *octname
226 > )
227   {
228          static char     *av[12] = {"rtrace", "-h", "-fff", "-ld+",
229                                          "-opL", "-x", "1"};
# Line 198 | Line 232 | char   *octname;
232          if (nowarn) av[ac++] = "-w-";
233          av[ac++] = octname;
234          av[ac] = NULL;
235 <        if (open_process(rtpd, av) <= 0)
235 >        if (open_process(&rtpd, av) <= 0)
236                  error(SYSTEM, "cannot start rtrace process");
237   }
238  
239  
240 < runrad(ac, av)                          /* run rad and load variables */
241 < int     ac;
242 < char    **av;
240 > static void
241 > runrad(                         /* run rad and load variables */
242 >        int     ac,
243 >        char    **av
244 > )
245   {
246          static char     optfile[] = TEMPLATE;
247          int     nvn = 0, nvv = 0;
248          FILE    *fp;
249 <        int     cval;
214 <        register char   *cp;
249 >        char    *cp;
250          char    radcomm[256], buf[128], nam[32];
251                                          /* set rad commmand */
252          strcpy(radcomm, "rad -w -v 0        "); /* look out below! */
# Line 238 | Line 273 | char   **av;
273                                                  /* get exposure */
274          if ((cp = scan4var(buf, sizeof(buf), "EXPOSURE", fp)) != NULL) {
275                  expval = atof(cp);
276 <                if (*cp == '-' | *cp == '+')
276 >                if ((*cp == '-') | (*cp == '+'))
277                          expval = pow(2., expval);
278                  expval *= 0.5;          /* compensate for local shading */
279          }
# Line 247 | Line 282 | char   **av;
282                  eyedist = atof(cp);
283                                                  /* look for materials */
284          while ((cp = scan4var(buf, sizeof(buf), "materials", fp)) != NULL) {
285 <                nscenef += wordstring(scene+nscenef, cp);
285 >                nscenef += wordstring(scene+nscenef, MAXSCENE-nscenef, cp);
286                  buf[0] = '\0';
287          }
288                                                  /* look for octree */
# Line 255 | Line 290 | char   **av;
290                  octree = savqstr(cp);
291                                                  /* look for scene files */
292          while ((cp = scan4var(buf, sizeof(buf), "scene", fp)) != NULL) {
293 <                nscenef += wordstring(scene+nscenef, cp);
293 >                nscenef += wordstring(scene+nscenef, MAXSCENE-nscenef, cp);
294                  buf[0] = '\0';
295          }
296                                                  /* load view names */
# Line 270 | Line 305 | char   **av;
305          do
306                  if (isview(buf)) {
307                          vwl[nvv].v = (VIEW *)bmalloc(sizeof(VIEW));
308 <                        copystruct(vwl[nvv].v, &stdview);
308 >                        *(vwl[nvv].v) = stdview;
309                          sscanview(vwl[nvv].v, buf);
310                          if ((cp = setview(vwl[nvv++].v)) != NULL) {
311                                  fprintf(stderr, "%s: bad view %d - %s\n",
# Line 299 | Line 334 | char   **av;
334   }
335  
336  
337 < int
338 < findvw(nm)                      /* find named view */
339 < register char   *nm;
337 > static int
338 > findvw(                 /* find named view */
339 >        char    *nm
340 > )
341   {
342 <        register int    n;
342 >        int     n;
343  
344 <        if (*nm >= '1' & *nm <= '9' &&
344 >        if ((*nm >= '1') & (*nm <= '9') &&
345                          (n = atoi(nm)-1) <= MAXVIEW && vwl[n].v != NULL)
346                  return(n);
347          for (n = 0; vwl[n].v != NULL; n++)
# Line 315 | Line 351 | register char  *nm;
351   }
352  
353  
354 < int
355 < varmatch(s, vn)                         /* match line to variable */
356 < register char   *s, *vn;
354 > static int
355 > varmatch(                               /* match line to variable */
356 >        char    *s,
357 >        char    *vn
358 > )
359   {
360 <        register int    c;
360 >        int     c;
361  
362          for ( ; *vn && *s == *vn; s++, vn++)
363                  ;
# Line 333 | Line 371 | register char  *s, *vn;
371   }
372  
373  
374 < char *
375 < scan4var(buf, buflen, vname, fp)        /* scan for variable from fp */
376 < char    *buf;
377 < int     buflen;
378 < char    *vname;
379 < FILE    *fp;
374 > static char *
375 > scan4var(       /* scan for variable from fp */
376 >        char    *buf,
377 >        int     buflen,
378 >        char    *vname,
379 >        FILE    *fp
380 > )
381   {
382          int     cval;
383 <        register char   *cp;
383 >        char    *cp;
384                                          /* search out matching line */
385          while ((cval = varmatch(buf, vname))) {
386                  if (cval > 0)                   /* gone too far? */
# Line 358 | Line 397 | FILE   *fp;
397   }
398  
399  
400 < dev_open(id)                    /* initialize GLX driver */
401 < char  *id;
400 > static void
401 > dev_open(                       /* initialize GLX driver */
402 >        char  *id
403 > )
404   {
405          static int      atlBest[] = {GLX_RGBA, GLX_RED_SIZE,4,
406                                  GLX_GREEN_SIZE,4, GLX_BLUE_SIZE,4,
# Line 409 | Line 450 | char  *id;
450                                          /* set window manager hints */
451          ourxwmhints.flags = InputHint|IconPixmapHint;
452          ourxwmhints.input = True;
453 <        ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay,
454 <                gwind, glradicon_bits, glradicon_width, glradicon_height);
453 >        ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, gwind,
454 >                (char *)glradicon_bits, glradicon_width, glradicon_height);
455          XSetWMHints(ourdisplay, gwind, &ourxwmhints);
456                                          /* set GLX context */
457          glXMakeCurrent(ourdisplay, gwind, gctx);
# Line 441 | Line 482 | char  *id;
482          no_render++;
483          do
484                  dev_input(0);           /* get resize event */
485 <        while (hres == 0 & vres == 0);
485 >        while ((hres == 0) & (vres == 0));
486          no_render--;
487          rgl_checkerr("initializing GLX");
488   }
489  
490  
491 < dev_close()                     /* close our display and free resources */
491 > static void
492 > dev_close(void)                 /* close our display and free resources */
493   {
494          glXMakeCurrent(ourdisplay, None, NULL);
495          glXDestroyContext(ourdisplay, gctx);
# Line 458 | Line 500 | dev_close()                    /* close our display and free resources
500   }
501  
502  
503 < int
504 < dev_view(nv)                    /* assign new driver view */
505 < register VIEW   *nv;
503 > static int
504 > dev_view(                       /* assign new driver view */
505 >        VIEW    *nv
506 > )
507   {
508          int     newhres = hres, newvres = vres;
509          double  wa, va;
# Line 469 | Line 512 | register VIEW  *nv;
512                  error(COMMAND, "illegal view type");
513                  nv->type = VT_PER;
514          }
515 <        if (nv->horiz > 160. | nv->vert > 160.) {
515 >        if ((nv->horiz > 160.) | (nv->vert > 160.)) {
516                  error(COMMAND, "illegal view angle");
517                  if (nv->horiz > 160.)
518                          nv->horiz = 160.;
519                  if (nv->vert > 160.)
520                          nv->vert = 160.;
521          }
522 <        if (hres != 0 & vres != 0) {
522 >        if ((hres != 0) & (vres != 0)) {
523                  wa = (vres*pheight)/(hres*pwidth);
524                  va = viewaspect(nv);
525                  if (va > wa+.05) {
# Line 492 | Line 535 | register VIEW  *nv;
535                                  newvres = (pwidth/pheight)*va*newhres + .5;
536                          }
537                  }
538 <                if (newhres != hres | newvres != vres) {
538 >                if ((newhres != hres) | (newvres != vres)) {
539                          no_render++;
540                          XResizeWindow(ourdisplay, gwind, newhres, newvres);
541                          do
542                                  dev_input(0);           /* get resize event */
543 <                        while (newhres != hres | newvres != vres);
543 >                        while ((newhres != hres) & (newvres != vres));
544                          no_render--;
545                  }
546          }
547 <        copystruct(&thisview, nv);
547 >        thisview = *nv;
548          setglpersp(&thisview);
549          render();
550          return(1);
551   }
552  
553  
554 < int
555 < dev_input(nsecs)                /* get next input event */
556 < int     nsecs;
554 > static int
555 > dev_input(              /* get next input event */
556 >        int     nsecs
557 > )
558   {
559   #if 0
560          static time_t   lasttime = 0;
# Line 541 | Line 585 | int    nsecs;
585          case KeyPress:
586                  return(getkey(levptr(XKeyPressedEvent)));
587          case ButtonPress:
588 <                getmove(levptr(XButtonPressedEvent));
588 >                switch (levptr(XButtonPressedEvent)->button) {
589 >                case Button4:                   /* wheel up */
590 >                        zoomview(100+WZOOMPCT, levptr(XButtonPressedEvent)->x,
591 >                                        vres-1-levptr(XButtonPressedEvent)->y);
592 >                        break;
593 >                case Button5:                   /* wheel down */
594 >                        zoomview(100-WZOOMPCT, levptr(XButtonPressedEvent)->x,
595 >                                        vres-1-levptr(XButtonPressedEvent)->y);
596 >                        break;
597 >                default:
598 >                        getmove(levptr(XButtonPressedEvent));
599 >                        break;
600 >                }
601                  break;
602          }
603          return(1);
604   }
605  
606  
607 < render()                        /* render our display list and swap buffers */
607 > static void
608 > render(void)                    /* render our display list and swap buffers */
609   {
610          double  d;
611  
# Line 574 | Line 631 | render()                       /* render our display list and swap buffers
631   }
632  
633  
634 < moveview(dx, dy, mov, orb)      /* move our view */
635 < int     dx, dy, mov, orb;
634 > static int
635 > moveview(       /* move our view */
636 >        int     dx,
637 >        int     dy,
638 >        int     mov,
639 >        int     orb
640 > )
641   {
642          VIEW    nv;
643          FVECT   odir, v1, wp;
644          double  d;
583        register int    li;
645                                  /* start with old view */
646 <        copystruct(&nv, &thisview);
646 >        nv = thisview;
647                                  /* change view direction */
648          if ((d = viewray(v1, odir, &thisview,
649                          (dx+.5)/hres, (dy+.5)/vres)) < -FTINY)
# Line 598 | Line 659 | int    dx, dy, mov, orb;
659                  VSUM(nv.vp, wp, odir, -1.);
660                  spinvector(nv.vdir, nv.vdir, nv.vup, d);
661          } else if (orb) {               /* orbit up/down */
662 <                fcross(v1, odir, nv.vup);
663 <                if (normalize(v1) == 0.)
662 >                if (geodesic(odir, odir, nv.vup,
663 >                                d=MOVDEG*PI/180.*orb, GEOD_RAD) == 0.0)
664                          return(0);
604                spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb);
665                  VSUM(nv.vp, wp, odir, -1.);
666 <                spinvector(nv.vdir, nv.vdir, v1, d);
666 >                geodesic(nv.vdir, nv.vdir, nv.vup, d, GEOD_RAD);
667          } else if (mov) {               /* move forward/backward */
668                  d = MOVPCT/100. * mov;
669                  VSUM(nv.vp, nv.vp, odir, d);
# Line 620 | Line 680 | int    dx, dy, mov, orb;
680   }
681  
682  
683 < static
684 < waitabit()                              /* pause a moment */
683 > static void
684 > waitabit(void)                          /* pause a moment */
685   {
686          struct timespec ts;
687          ts.tv_sec = 0;
688 <        ts.tv_nsec = 5000000;
688 >        ts.tv_nsec = 50000000;
689          nanosleep(&ts, NULL);
690   }
691  
692  
693 < getmove(ebut)                           /* get view change */
694 < XButtonPressedEvent     *ebut;
693 > static void
694 > getmove(                                /* get view change */
695 >        XButtonPressedEvent     *ebut
696 > )
697   {
698          int     movdir = MOVDIR(ebut->button);
699          int     movorb = MOVORB(ebut->state);
# Line 668 | Line 730 | XButtonPressedEvent    *ebut;
730   }
731  
732  
733 < getintersect(wp, org, dir, md)          /* intersect ray with scene geometry */
734 < FVECT   wp;             /* returned world intersection point */
735 < FVECT   org, dir;
736 < double  md;
733 > static int
734 > getintersect(           /* intersect ray with scene geometry */
735 >        FVECT   wp,             /* returned world intersection point */
736 >        FVECT   org,
737 >        FVECT   dir,
738 >        double  md
739 > )
740   {
741          float   fbuf[6];
742                                  /* check to see if rtrace is running */
743 <        if (rtpd[2] <= 0)
743 >        /* if (rtpd.pid <= 0) */
744 >        if (!rtpd.running)
745                  return(0);
746                                  /* assign origin */
747          fbuf[0] = org[0]; fbuf[1] = org[1]; fbuf[2] = org[2];
# Line 683 | Line 749 | double md;
749          if (md <= FTINY) md = FHUGE;
750          fbuf[3] = dir[0]*md; fbuf[4] = dir[1]*md; fbuf[5] = dir[2]*md;
751                                  /* trace that ray */
752 <        if (process(rtpd, (char *)fbuf, (char *)fbuf,
752 >        if (process(&rtpd, (char *)fbuf, (char *)fbuf,
753                          4*sizeof(float), 6*sizeof(float)) != 4*sizeof(float))
754                  error(INTERNAL, "error getting data back from rtrace process");
755          if (fbuf[3] >= .99*FHUGE)
# Line 693 | Line 759 | double md;
759   }
760  
761  
762 < setglpersp(vp)                  /* set perspective view in GL */
763 < register VIEW   *vp;
762 > static void
763 > setglpersp(                     /* set perspective view in GL */
764 >        VIEW    *vp
765 > )
766   {
767          double  d, xmin, xmax, ymin, ymax, zmin, zmax;
768  
# Line 725 | Line 793 | register VIEW  *vp;
793   }
794  
795  
796 < int
797 < getkey(ekey)                            /* get input key */
798 < register XKeyPressedEvent  *ekey;
796 > static int
797 > getkey(                         /* get input key */
798 >        XKeyPressedEvent  *ekey
799 > )
800   {
801          int  n;
802          char    buf[8];
# Line 745 | Line 814 | register XKeyPressedEvent  *ekey;
814          case 'l':                       /* retrieve last (premouse) view */
815                  if (lastview.type) {
816                          VIEW    vtmp;
817 <                        copystruct(&vtmp, &thisview);
817 >                        vtmp = thisview;
818                          dev_view(&lastview);
819 <                        copystruct(&lastview, &vtmp);
819 >                        lastview = vtmp;
820                  } else
821                          XBell(ourdisplay, 0);
822                  break;
# Line 771 | Line 840 | register XKeyPressedEvent  *ekey;
840          case 'V':                       /* append view to rad file */
841                  appendview(NULL, &thisview);
842                  break;
843 +        case 'Q':
844          case 'q':                       /* quit the program */
845                  return(0);
846          default:
# Line 781 | Line 851 | register XKeyPressedEvent  *ekey;
851   }
852  
853  
854 < zoomview(pct, dx, dy)                   /* zoom in or out around (dx,dy) */
855 < int     pct;
856 < int     dx, dy;
854 > static void
855 > zoomview(                       /* zoom in or out around (dx,dy) */
856 >        int     pct,
857 >        int     dx,
858 >        int     dy
859 > )
860   {
861          double  h, v;
789        FVECT   direc;
862  
863 <        if (pct == 100 | pct <= 0)
863 >        if ((pct == 100) | (pct <= 0))
864                  return;
865          copylastv("zooming");
866          h = (dx+.5)/hres - 0.5;
# Line 807 | Line 879 | int    dx, dy;
879   }
880  
881  
882 < gotoview(vwnum)                         /* go to specified view number */
883 < int     vwnum;
882 > static void
883 > gotoview(                               /* go to specified view number */
884 >        int     vwnum
885 > )
886   {
887          if (vwnum < 0)
888                  for (vwnum = currentview; vwl[vwnum+1].v != NULL; vwnum++)
# Line 820 | Line 894 | int    vwnum;
894   }
895  
896  
897 < appendview(nm, vp)                      /* append standard view */
898 < char    *nm;
899 < VIEW    *vp;
897 > static void
898 > appendview(                     /* append standard view */
899 >        char    *nm,
900 >        VIEW    *vp
901 > )
902   {
903          FILE    *fp;
904                                          /* check if already in there */
905 <        if (!bcmp(&thisview, vwl[currentview].v, sizeof(VIEW))) {
905 >        if (!memcmp(&thisview, vwl[currentview].v, sizeof(VIEW))) {
906                  error(COMMAND, "view already in standard list");
907                  return;
908          }
# Line 847 | Line 923 | VIEW   *vp;
923          if (currentview >= MAXVIEW)
924                  error(INTERNAL, "too many views in appendview");
925          vwl[currentview].v = (VIEW *)bmalloc(sizeof(VIEW));
926 <        copystruct(vwl[currentview].v, &thisview);
926 >        *(vwl[currentview].v) = thisview;
927          if (nm != NULL)
928                  vwl[currentview].nam = savqstr(nm);
929   }
930  
931  
932 < copylastv(cause)                        /* copy last view position */
933 < char    *cause;
932 > static void
933 > copylastv(                      /* copy last view position */
934 >        char    *cause
935 > )
936   {
937          static char     *lastvc;
938  
939          if (cause == lastvc)
940                  return;                 /* only record one view per cause */
941          lastvc = cause;
942 <        copystruct(&lastview, &thisview);
942 >        lastview = thisview;
943   }
944  
945  
946 < fixwindow(eexp)                         /* repair damage to window */
947 < register XExposeEvent  *eexp;
946 > static void
947 > fixwindow(                              /* repair damage to window */
948 >        XExposeEvent  *eexp
949 > )
950   {
951 <        if (hres == 0 | vres == 0) {    /* first exposure */
951 >        if ((hres == 0) | (vres == 0)) {        /* first exposure */
952                  resizewindow((XConfigureEvent *)eexp);
953                  return;
954          }
# Line 879 | Line 959 | register XExposeEvent  *eexp;
959   }
960  
961  
962 < resizewindow(ersz)                      /* resize window */
963 < register XConfigureEvent  *ersz;
962 > static void
963 > resizewindow(                   /* resize window */
964 >        XConfigureEvent  *ersz
965 > )
966   {
967          static char     resizing[] = "resizing window";
968          double  wa, va;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines