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.25 by greg, Mon Apr 25 20:06:22 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 26 | Line 29 | static const char      RCSid[] = "$Id$";
29  
30   #define ZOOMPCT         9               /* percent to zoom at a time */
31  
32 < #define MOVPCT          7               /* percent distance to move /frame */
32 > #define MOVPCT          4               /* percent distance to move /frame */
33   #define MOVDIR(b)       ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1)
34 < #define MOVDEG          (-5)            /* degrees to orbit CW/down /frame */
34 > #define MOVDEG          (-1.5)          /* degrees to orbit CW/down /frame */
35   #define MOVORB(s)       ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
36  
37   #define BORWIDTH        5               /* border width */
# Line 72 | Line 75 | char   *scene[MAXSCENE+1];             /* material and scene file l
75   int     nscenef = 0;                    /* number of scene files */
76   char    *octree;                        /* octree name (NULL if unnec.) */
77  
78 < int     rtpd[3];                        /* rtrace process descriptors */
78 > SUBPROC rtpd;                   /* rtrace process descriptors */
79  
80   int     silent = 0;                     /* run rad silently? */
81   int     backvis = 1;                    /* back faces visible? */
82   int     stereo = 0;                     /* do stereo? */
83  
84   #ifdef NOSTEREO
85 < #define setstereobuf(bid)       0
85 > #define setstereobuf(bid)      
86   #else
87   #define setstereobuf(bid)       (glXWaitGL(), \
88                                  XSGISetStereoBuffer(ourdisplay, gwind, bid), \
# Line 90 | Line 93 | int    displist;                       /* our scene display list */
93  
94   int     no_render = 0;                  /* don't rerender */
95  
93 extern char     *fgetline(), *atos(), *scan4var();
96   extern int      nowarn;                 /* turn warnings off? */
97  
98 + static void startrtrace(char    *octname);
99 + static void runrad(int  ac, char        **av);
100 + static int findvw(char  *nm);
101 + static int varmatch(char        *s, char        *vn);
102 + static char * scan4var(char     *buf, int       buflen, char    *vname, FILE    *fp);
103 + static void dev_open(char  *id);
104 + static void dev_close(void);
105 + static int dev_view(VIEW        *nv);
106 + static int dev_input(int        nsecs);
107 + static void render(void);
108 + static int moveview(int dx, int dy, int mov, int        orb);
109 + static void waitabit(void);
110 + static void getmove(XButtonPressedEvent *ebut);
111 + static int getintersect(FVECT   wp, FVECT       org, FVECT      dir, double     md);
112 + static void setglpersp(VIEW     *vp);
113 + static int getkey(XKeyPressedEvent  *ekey);
114 + static void zoomview(int        pct, int        dx, int dy);
115 + static void gotoview(int        vwnum);
116 + static void appendview(char     *nm, VIEW       *vp);
117 + static void copylastv(char      *cause);
118 + static void fixwindow(XExposeEvent  *eexp);
119 + static void resizewindow(XConfigureEvent  *ersz);
120  
121 < main(argc, argv)
122 < int     argc;
123 < char    *argv[];
121 >
122 > int
123 > main(
124 >        int     argc,
125 >        char    *argv[]
126 > )
127   {
128          char    *viewsel = NULL;
129          long    vwintvl = 0;
# Line 135 | Line 162 | char   *argv[];
162                                          /* run rad and get views */
163          runrad(argc-i, argv+i);
164                                          /* check view */
165 <        if (viewsel != NULL)
165 >        if (viewsel != NULL) {
166                  if (viewsel[0] == '-') {
167                          char    *ve = viewsel;
168                          if (!sscanview(&thisview, viewsel) ||
# Line 150 | Line 177 | char   *argv[];
177                                                  progname, viewsel);
178                          quit(1);
179                  }
180 +        }
181                                          /* open GL */
182          dev_open(radfile = argv[i]);
183                                          /* load octree or scene files */
# Line 170 | Line 198 | userr:
198                  "Usage: %s [-w][-s][-b][-S][-v view] rfile [VAR=value]..\n",
199                          argv[0]);
200          quit(1);
201 +        return 1; /* pro forma return */
202   }
203  
204  
205   void
206 < quit(code)                              /* exit gracefully */
207 < int     code;
206 > quit(                           /* exit gracefully */
207 >        int     code
208 > )
209   {
210          if (ourdisplay != NULL)
211                  dev_close();
212 <        if (rtpd[2] > 0) {
213 <                if (close_process(rtpd) > 0)
212 >        /* if (rtpd.pid > 0) { */
213 >        if (rtpd.running) {
214 >                if (close_process(&rtpd) > 0)
215                          wputs("bad exit status from rtrace\n");
216 <                rtpd[2] = 0;
216 >                /* rtpd.pid = 0; */
217          }
218          exit(code);
219   }
220  
221  
222 < startrtrace(octname)                    /* start rtrace on octname */
223 < char    *octname;
222 > static void
223 > startrtrace(                    /* start rtrace on octname */
224 >        char    *octname
225 > )
226   {
227          static char     *av[12] = {"rtrace", "-h", "-fff", "-ld+",
228                                          "-opL", "-x", "1"};
# Line 198 | Line 231 | char   *octname;
231          if (nowarn) av[ac++] = "-w-";
232          av[ac++] = octname;
233          av[ac] = NULL;
234 <        if (open_process(rtpd, av) <= 0)
234 >        if (open_process(&rtpd, av) <= 0)
235                  error(SYSTEM, "cannot start rtrace process");
236   }
237  
238  
239 < runrad(ac, av)                          /* run rad and load variables */
240 < int     ac;
241 < char    **av;
239 > static void
240 > runrad(                         /* run rad and load variables */
241 >        int     ac,
242 >        char    **av
243 > )
244   {
245          static char     optfile[] = TEMPLATE;
246          int     nvn = 0, nvv = 0;
247          FILE    *fp;
248 <        int     cval;
214 <        register char   *cp;
248 >        char    *cp;
249          char    radcomm[256], buf[128], nam[32];
250                                          /* set rad commmand */
251          strcpy(radcomm, "rad -w -v 0        "); /* look out below! */
# Line 238 | Line 272 | char   **av;
272                                                  /* get exposure */
273          if ((cp = scan4var(buf, sizeof(buf), "EXPOSURE", fp)) != NULL) {
274                  expval = atof(cp);
275 <                if (*cp == '-' | *cp == '+')
275 >                if ((*cp == '-') | (*cp == '+'))
276                          expval = pow(2., expval);
277                  expval *= 0.5;          /* compensate for local shading */
278          }
# Line 247 | Line 281 | char   **av;
281                  eyedist = atof(cp);
282                                                  /* look for materials */
283          while ((cp = scan4var(buf, sizeof(buf), "materials", fp)) != NULL) {
284 <                nscenef += wordstring(scene+nscenef, cp);
284 >                nscenef += wordstring(scene+nscenef, MAXSCENE-nscenef, cp);
285                  buf[0] = '\0';
286          }
287                                                  /* look for octree */
# Line 255 | Line 289 | char   **av;
289                  octree = savqstr(cp);
290                                                  /* look for scene files */
291          while ((cp = scan4var(buf, sizeof(buf), "scene", fp)) != NULL) {
292 <                nscenef += wordstring(scene+nscenef, cp);
292 >                nscenef += wordstring(scene+nscenef, MAXSCENE-nscenef, cp);
293                  buf[0] = '\0';
294          }
295                                                  /* load view names */
# Line 270 | Line 304 | char   **av;
304          do
305                  if (isview(buf)) {
306                          vwl[nvv].v = (VIEW *)bmalloc(sizeof(VIEW));
307 <                        copystruct(vwl[nvv].v, &stdview);
307 >                        *(vwl[nvv].v) = stdview;
308                          sscanview(vwl[nvv].v, buf);
309                          if ((cp = setview(vwl[nvv++].v)) != NULL) {
310                                  fprintf(stderr, "%s: bad view %d - %s\n",
# Line 299 | Line 333 | char   **av;
333   }
334  
335  
336 < int
337 < findvw(nm)                      /* find named view */
338 < register char   *nm;
336 > static int
337 > findvw(                 /* find named view */
338 >        char    *nm
339 > )
340   {
341 <        register int    n;
341 >        int     n;
342  
343 <        if (*nm >= '1' & *nm <= '9' &&
343 >        if ((*nm >= '1') & (*nm <= '9') &&
344                          (n = atoi(nm)-1) <= MAXVIEW && vwl[n].v != NULL)
345                  return(n);
346          for (n = 0; vwl[n].v != NULL; n++)
# Line 315 | Line 350 | register char  *nm;
350   }
351  
352  
353 < int
354 < varmatch(s, vn)                         /* match line to variable */
355 < register char   *s, *vn;
353 > static int
354 > varmatch(                               /* match line to variable */
355 >        char    *s,
356 >        char    *vn
357 > )
358   {
359 <        register int    c;
359 >        int     c;
360  
361          for ( ; *vn && *s == *vn; s++, vn++)
362                  ;
# Line 333 | Line 370 | register char  *s, *vn;
370   }
371  
372  
373 < char *
374 < scan4var(buf, buflen, vname, fp)        /* scan for variable from fp */
375 < char    *buf;
376 < int     buflen;
377 < char    *vname;
378 < FILE    *fp;
373 > static char *
374 > scan4var(       /* scan for variable from fp */
375 >        char    *buf,
376 >        int     buflen,
377 >        char    *vname,
378 >        FILE    *fp
379 > )
380   {
381          int     cval;
382 <        register char   *cp;
382 >        char    *cp;
383                                          /* search out matching line */
384          while ((cval = varmatch(buf, vname))) {
385                  if (cval > 0)                   /* gone too far? */
# Line 358 | Line 396 | FILE   *fp;
396   }
397  
398  
399 < dev_open(id)                    /* initialize GLX driver */
400 < char  *id;
399 > static void
400 > dev_open(                       /* initialize GLX driver */
401 >        char  *id
402 > )
403   {
404          static int      atlBest[] = {GLX_RGBA, GLX_RED_SIZE,4,
405                                  GLX_GREEN_SIZE,4, GLX_BLUE_SIZE,4,
# Line 409 | Line 449 | char  *id;
449                                          /* set window manager hints */
450          ourxwmhints.flags = InputHint|IconPixmapHint;
451          ourxwmhints.input = True;
452 <        ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay,
453 <                gwind, glradicon_bits, glradicon_width, glradicon_height);
452 >        ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, gwind,
453 >                (char *)glradicon_bits, glradicon_width, glradicon_height);
454          XSetWMHints(ourdisplay, gwind, &ourxwmhints);
455                                          /* set GLX context */
456          glXMakeCurrent(ourdisplay, gwind, gctx);
# Line 441 | Line 481 | char  *id;
481          no_render++;
482          do
483                  dev_input(0);           /* get resize event */
484 <        while (hres == 0 & vres == 0);
484 >        while ((hres == 0) & (vres == 0));
485          no_render--;
486          rgl_checkerr("initializing GLX");
487   }
488  
489  
490 < dev_close()                     /* close our display and free resources */
490 > static void
491 > dev_close(void)                 /* close our display and free resources */
492   {
493          glXMakeCurrent(ourdisplay, None, NULL);
494          glXDestroyContext(ourdisplay, gctx);
# Line 458 | Line 499 | dev_close()                    /* close our display and free resources
499   }
500  
501  
502 < int
503 < dev_view(nv)                    /* assign new driver view */
504 < register VIEW   *nv;
502 > static int
503 > dev_view(                       /* assign new driver view */
504 >        VIEW    *nv
505 > )
506   {
507          int     newhres = hres, newvres = vres;
508          double  wa, va;
# Line 469 | Line 511 | register VIEW  *nv;
511                  error(COMMAND, "illegal view type");
512                  nv->type = VT_PER;
513          }
514 <        if (nv->horiz > 160. | nv->vert > 160.) {
514 >        if ((nv->horiz > 160.) | (nv->vert > 160.)) {
515                  error(COMMAND, "illegal view angle");
516                  if (nv->horiz > 160.)
517                          nv->horiz = 160.;
518                  if (nv->vert > 160.)
519                          nv->vert = 160.;
520          }
521 <        if (hres != 0 & vres != 0) {
521 >        if ((hres != 0) & (vres != 0)) {
522                  wa = (vres*pheight)/(hres*pwidth);
523                  va = viewaspect(nv);
524                  if (va > wa+.05) {
# Line 492 | Line 534 | register VIEW  *nv;
534                                  newvres = (pwidth/pheight)*va*newhres + .5;
535                          }
536                  }
537 <                if (newhres != hres | newvres != vres) {
537 >                if ((newhres != hres) | (newvres != vres)) {
538                          no_render++;
539                          XResizeWindow(ourdisplay, gwind, newhres, newvres);
540                          do
541                                  dev_input(0);           /* get resize event */
542 <                        while (newhres != hres | newvres != vres);
542 >                        while ((newhres != hres) & (newvres != vres));
543                          no_render--;
544                  }
545          }
546 <        copystruct(&thisview, nv);
546 >        thisview = *nv;
547          setglpersp(&thisview);
548          render();
549          return(1);
550   }
551  
552  
553 < int
554 < dev_input(nsecs)                /* get next input event */
555 < int     nsecs;
553 > static int
554 > dev_input(              /* get next input event */
555 >        int     nsecs
556 > )
557   {
558   #if 0
559          static time_t   lasttime = 0;
# Line 548 | Line 591 | int    nsecs;
591   }
592  
593  
594 < render()                        /* render our display list and swap buffers */
594 > static void
595 > render(void)                    /* render our display list and swap buffers */
596   {
597          double  d;
598  
# Line 574 | Line 618 | render()                       /* render our display list and swap buffers
618   }
619  
620  
621 < moveview(dx, dy, mov, orb)      /* move our view */
622 < int     dx, dy, mov, orb;
621 > static int
622 > moveview(       /* move our view */
623 >        int     dx,
624 >        int     dy,
625 >        int     mov,
626 >        int     orb
627 > )
628   {
629          VIEW    nv;
630          FVECT   odir, v1, wp;
631          double  d;
583        register int    li;
632                                  /* start with old view */
633 <        copystruct(&nv, &thisview);
633 >        nv = thisview;
634                                  /* change view direction */
635          if ((d = viewray(v1, odir, &thisview,
636                          (dx+.5)/hres, (dy+.5)/vres)) < -FTINY)
# Line 598 | Line 646 | int    dx, dy, mov, orb;
646                  VSUM(nv.vp, wp, odir, -1.);
647                  spinvector(nv.vdir, nv.vdir, nv.vup, d);
648          } else if (orb) {               /* orbit up/down */
649 <                fcross(v1, odir, nv.vup);
650 <                if (normalize(v1) == 0.)
649 >                if (geodesic(odir, odir, nv.vup,
650 >                                d=MOVDEG*PI/180.*orb, GEOD_RAD) == 0.0)
651                          return(0);
604                spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb);
652                  VSUM(nv.vp, wp, odir, -1.);
653 <                spinvector(nv.vdir, nv.vdir, v1, d);
653 >                geodesic(nv.vdir, nv.vdir, nv.vup, d, GEOD_RAD);
654          } else if (mov) {               /* move forward/backward */
655                  d = MOVPCT/100. * mov;
656                  VSUM(nv.vp, nv.vp, odir, d);
# Line 620 | Line 667 | int    dx, dy, mov, orb;
667   }
668  
669  
670 < static
671 < waitabit()                              /* pause a moment */
670 > static void
671 > waitabit(void)                          /* pause a moment */
672   {
673          struct timespec ts;
674          ts.tv_sec = 0;
675 <        ts.tv_nsec = 5000000;
675 >        ts.tv_nsec = 50000000;
676          nanosleep(&ts, NULL);
677   }
678  
679  
680 < getmove(ebut)                           /* get view change */
681 < XButtonPressedEvent     *ebut;
680 > static void
681 > getmove(                                /* get view change */
682 >        XButtonPressedEvent     *ebut
683 > )
684   {
685          int     movdir = MOVDIR(ebut->button);
686          int     movorb = MOVORB(ebut->state);
# Line 668 | Line 717 | XButtonPressedEvent    *ebut;
717   }
718  
719  
720 < getintersect(wp, org, dir, md)          /* intersect ray with scene geometry */
721 < FVECT   wp;             /* returned world intersection point */
722 < FVECT   org, dir;
723 < double  md;
720 > static int
721 > getintersect(           /* intersect ray with scene geometry */
722 >        FVECT   wp,             /* returned world intersection point */
723 >        FVECT   org,
724 >        FVECT   dir,
725 >        double  md
726 > )
727   {
728          float   fbuf[6];
729                                  /* check to see if rtrace is running */
730 <        if (rtpd[2] <= 0)
730 >        /* if (rtpd.pid <= 0) */
731 >        if (!rtpd.running)
732                  return(0);
733                                  /* assign origin */
734          fbuf[0] = org[0]; fbuf[1] = org[1]; fbuf[2] = org[2];
# Line 683 | Line 736 | double md;
736          if (md <= FTINY) md = FHUGE;
737          fbuf[3] = dir[0]*md; fbuf[4] = dir[1]*md; fbuf[5] = dir[2]*md;
738                                  /* trace that ray */
739 <        if (process(rtpd, (char *)fbuf, (char *)fbuf,
739 >        if (process(&rtpd, (char *)fbuf, (char *)fbuf,
740                          4*sizeof(float), 6*sizeof(float)) != 4*sizeof(float))
741                  error(INTERNAL, "error getting data back from rtrace process");
742          if (fbuf[3] >= .99*FHUGE)
# Line 693 | Line 746 | double md;
746   }
747  
748  
749 < setglpersp(vp)                  /* set perspective view in GL */
750 < register VIEW   *vp;
749 > static void
750 > setglpersp(                     /* set perspective view in GL */
751 >        VIEW    *vp
752 > )
753   {
754          double  d, xmin, xmax, ymin, ymax, zmin, zmax;
755  
# Line 725 | Line 780 | register VIEW  *vp;
780   }
781  
782  
783 < int
784 < getkey(ekey)                            /* get input key */
785 < register XKeyPressedEvent  *ekey;
783 > static int
784 > getkey(                         /* get input key */
785 >        XKeyPressedEvent  *ekey
786 > )
787   {
788          int  n;
789          char    buf[8];
# Line 745 | Line 801 | register XKeyPressedEvent  *ekey;
801          case 'l':                       /* retrieve last (premouse) view */
802                  if (lastview.type) {
803                          VIEW    vtmp;
804 <                        copystruct(&vtmp, &thisview);
804 >                        vtmp = thisview;
805                          dev_view(&lastview);
806 <                        copystruct(&lastview, &vtmp);
806 >                        lastview = vtmp;
807                  } else
808                          XBell(ourdisplay, 0);
809                  break;
# Line 781 | Line 837 | register XKeyPressedEvent  *ekey;
837   }
838  
839  
840 < zoomview(pct, dx, dy)                   /* zoom in or out around (dx,dy) */
841 < int     pct;
842 < int     dx, dy;
840 > static void
841 > zoomview(                       /* zoom in or out around (dx,dy) */
842 >        int     pct,
843 >        int     dx,
844 >        int     dy
845 > )
846   {
847          double  h, v;
789        FVECT   direc;
848  
849 <        if (pct == 100 | pct <= 0)
849 >        if ((pct == 100) | (pct <= 0))
850                  return;
851          copylastv("zooming");
852          h = (dx+.5)/hres - 0.5;
# Line 807 | Line 865 | int    dx, dy;
865   }
866  
867  
868 < gotoview(vwnum)                         /* go to specified view number */
869 < int     vwnum;
868 > static void
869 > gotoview(                               /* go to specified view number */
870 >        int     vwnum
871 > )
872   {
873          if (vwnum < 0)
874                  for (vwnum = currentview; vwl[vwnum+1].v != NULL; vwnum++)
# Line 820 | Line 880 | int    vwnum;
880   }
881  
882  
883 < appendview(nm, vp)                      /* append standard view */
884 < char    *nm;
885 < VIEW    *vp;
883 > static void
884 > appendview(                     /* append standard view */
885 >        char    *nm,
886 >        VIEW    *vp
887 > )
888   {
889          FILE    *fp;
890                                          /* check if already in there */
891 <        if (!bcmp(&thisview, vwl[currentview].v, sizeof(VIEW))) {
891 >        if (!memcmp(&thisview, vwl[currentview].v, sizeof(VIEW))) {
892                  error(COMMAND, "view already in standard list");
893                  return;
894          }
# Line 847 | Line 909 | VIEW   *vp;
909          if (currentview >= MAXVIEW)
910                  error(INTERNAL, "too many views in appendview");
911          vwl[currentview].v = (VIEW *)bmalloc(sizeof(VIEW));
912 <        copystruct(vwl[currentview].v, &thisview);
912 >        *(vwl[currentview].v) = thisview;
913          if (nm != NULL)
914                  vwl[currentview].nam = savqstr(nm);
915   }
916  
917  
918 < copylastv(cause)                        /* copy last view position */
919 < char    *cause;
918 > static void
919 > copylastv(                      /* copy last view position */
920 >        char    *cause
921 > )
922   {
923          static char     *lastvc;
924  
925          if (cause == lastvc)
926                  return;                 /* only record one view per cause */
927          lastvc = cause;
928 <        copystruct(&lastview, &thisview);
928 >        lastview = thisview;
929   }
930  
931  
932 < fixwindow(eexp)                         /* repair damage to window */
933 < register XExposeEvent  *eexp;
932 > static void
933 > fixwindow(                              /* repair damage to window */
934 >        XExposeEvent  *eexp
935 > )
936   {
937 <        if (hres == 0 | vres == 0) {    /* first exposure */
937 >        if ((hres == 0) | (vres == 0)) {        /* first exposure */
938                  resizewindow((XConfigureEvent *)eexp);
939                  return;
940          }
# Line 879 | Line 945 | register XExposeEvent  *eexp;
945   }
946  
947  
948 < resizewindow(ersz)                      /* resize window */
949 < register XConfigureEvent  *ersz;
948 > static void
949 > resizewindow(                   /* resize window */
950 >        XConfigureEvent  *ersz
951 > )
952   {
953          static char     resizing[] = "resizing window";
954          double  wa, va;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines