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.3 by gwlarson, Tue Jun 9 15:16:55 1998 UTC vs.
Revision 3.27 by greg, Fri Feb 28 05:18:49 2020 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Program to display Radiance scene using OpenGL.
6   */
7  
11 #include "radogl.h"
12 #include "view.h"
13 #include "paths.h"
8   #include <sys/types.h>
9   #include <GL/glx.h>
10 + #ifndef NOSTEREO
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 23 | Line 27 | static char SCCSid[] = "$SunId$ SGI";
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  
33 #define MINWIDTH        480             /* minimum graphics window width */
34 #define MINHEIGHT       400             /* minimum graphics window height */
35
38   #define BORWIDTH        5               /* border width */
39  
40   #define  ourscreen      DefaultScreen(ourdisplay)
# Line 65 | Line 67 | struct {
67  
68   int     currentview = 0;                /* current view number */
69   VIEW    thisview = STDVIEW;             /* displayed view */
70 + double  eyedist = 1;                    /* interocular distance */
71   VIEW    lastview;                       /* last recorded view */
72  
73   char    *progname;                      /* global argv[0] */
# Line 73 | 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 = SP_INACTIVE;             /* 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)      
87 + #else
88 + #define setstereobuf(bid)       (glXWaitGL(), \
89 +                                XSGISetStereoBuffer(ourdisplay, gwind, bid), \
90 +                                glXWaitX())
91 + #endif
92 +
93   int     displist;                       /* our scene display list */
94  
95 < int     in_dev_view = 0;                /* currently in dev_view() */
95 > int     no_render = 0;                  /* don't rerender */
96  
84 extern char     *fgets(), *fgetline(), *atos(), *scan4var();
97   extern int      nowarn;                 /* turn warnings off? */
86 extern time_t   time();
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 103 | Line 139 | char   *argv[];
139                  case 'w':
140                          nowarn = !nowarn;
141                          break;
142 +                case 's':
143 +                        silent = !silent;
144 +                        break;
145 +                case 'S':
146 +                        stereo = !stereo;
147 +                        break;
148                  case 'c':
149                          vwintvl = atoi(argv[++i]);
150                          break;
# Line 114 | Line 156 | char   *argv[];
156                  }
157          if (i >= argc)
158                  goto userr;
159 + #ifdef NOSTEREO
160 +        if (stereo)
161 +                error(INTERNAL, "stereo not supported in this version");
162 + #endif
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 132 | 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 */
185          if (octree != NULL) {
186 <                displist = rgl_octlist(octree, NULL, NULL);
186 >                displist = rgl_octlist(octree, NULL, NULL, NULL);
187                  startrtrace(octree);
188          } else
189 <                displist = rgl_filelist(nscenef, scene);
189 >                displist = rgl_filelist(nscenef, scene, NULL);
190                                          /* set initial view */
191          dev_view(currentview < 0 ? &thisview : vwl[currentview].v);
192                                          /* input/render loop */
# Line 148 | Line 195 | char   *argv[];
195                                          /* all done */
196          quit(0);
197   userr:
198 <        fprintf(stderr, "Usage: %s [-w][-b][-v view] rfile [VAR=value]..\n",
198 >        fprintf(stderr,
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 < quit(code)                              /* exit gracefully */
207 < int     code;
206 > void
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.flags & PF_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 178 | 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;
194 <        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! */
253          cp = radcomm + 19;
254 +        if (silent) {
255 +                strcpy(cp, "-s ");
256 +                cp += 3;
257 +        }
258          while (ac--) {
259                  strcpy(cp, *av++);
260                  while (*cp) cp++;
# Line 214 | 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          }
280 +                                                /* look for eye separation */
281 +        if ((cp = scan4var(buf, sizeof(buf), "EYESEP", fp)) != NULL)
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 228 | 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 243 | 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 258 | Line 320 | char   **av;
320                                                  /* open options file */
321          if ((fp = fopen(optfile, "r")) == NULL)
322                  error(SYSTEM, "cannot open options file");
323 <                                                /* get ambient value */
323 >                                                /* get relevant options */
324          while (fgets(buf, sizeof(buf), fp) != NULL)
325 <                if (!strncmp(buf, "-av ", 4)) {
325 >                if (!strncmp(buf, "-av ", 4))
326                          setcolor(ambval, atof(buf+4),
327                                          atof(sskip2(buf+4,1)),
328                                          atof(sskip2(buf+4,2)));
329 <                        break;
330 <                }
329 >                else if (backvis && !strncmp(buf, "-bv", 3) &&
330 >                                (!buf[3] || strchr("0-FfNn \n",buf[3])!=NULL))
331 >                        backvis = 0;
332          fclose(fp);
333          unlink(optfile);                        /* delete options file */
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 287 | 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 305 | 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 330 | 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,
407                                  GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE,15, None};
408          XSetWindowAttributes    ourwinattr;
409          XWMHints        ourxwmhints;
341        XSizeHints      oursizhints;
410                                          /* open display server */
411          ourdisplay = XOpenDisplay(NULL);
412          if (ourdisplay == NULL)
# Line 364 | Line 432 | char  *id;
432          if (gwind == 0)
433                  error(SYSTEM, "cannot create window\n");
434          XStoreName(ourdisplay, gwind, id);
435 + #ifndef NOSTEREO
436 +        if (stereo)                     /* check if stereo working */
437 +                switch (XSGIQueryStereoMode(ourdisplay, gwind)) {
438 +                case STEREO_TOP:
439 +                case STEREO_BOTTOM:
440 +                        break;
441 +                case STEREO_OFF:
442 +                        error(USER,
443 +                "wrong video mode: run \"/usr/gfx/setmon -n STR_TOP\" first");
444 +                case X_STEREO_UNSUPPORTED:
445 +                        error(USER, "stereo not supported on this screen");
446 +                default:
447 +                        error(INTERNAL, "unknown stereo mode");
448 +                }
449 + #endif
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);
373        oursizhints.min_width = MINWIDTH;
374        oursizhints.min_height = MINHEIGHT;
375        oursizhints.flags = PMinSize;
376        XSetNormalHints(ourdisplay, gwind, &oursizhints);
456                                          /* set GLX context */
457          glXMakeCurrent(ourdisplay, gwind, gctx);
458          glEnable(GL_DEPTH_TEST);
459          glDepthFunc(GL_LESS);
460          glShadeModel(GL_SMOOTH);
461          glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
462 <        glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
462 >        glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
463          glEnable(GL_LIGHTING);
464 +        glFrontFace(GL_CCW);
465 +        glCullFace(GL_BACK);
466          if (backvis)
467                  glDisable(GL_CULL_FACE);
468 <        else {
388 <                glFrontFace(GL_CCW);
389 <                glCullFace(GL_BACK);
468 >        else
469                  glEnable(GL_CULL_FACE);
391        }
470          glDrawBuffer(GL_BACK);
471                                          /* figure out sensible view */
472          pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
473                          DisplayWidth(ourdisplay, ourscreen);
474          pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) /
475                          DisplayHeight(ourdisplay, ourscreen);
476 +        if (stereo) {                   /* set stereo mode */
477 +                setstereobuf(STEREO_BUFFER_LEFT);
478 +                pheight *= 2.;
479 +        }
480                                          /* map the window */
481          XMapWindow(ourdisplay, gwind);
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 415 | 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 426 | 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 449 | Line 535 | register VIEW  *nv;
535                                  newvres = (pwidth/pheight)*va*newhres + .5;
536                          }
537                  }
538 <                if (newhres != hres | newvres != vres) {
539 <                        in_dev_view++;
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);
544 <                        in_dev_view--;
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 498 | 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 <        if (!mapped)
610 >        double  d;
611 >
612 >        if (!mapped | no_render)
613                  return;
614          glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
615          glCallList(displist);
616 +        if (stereo) {                           /* do right eye for stereo */
617 +                setstereobuf(STEREO_BUFFER_RIGHT);
618 +                glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
619 +                glMatrixMode(GL_MODELVIEW);
620 +                glPushMatrix();
621 +                d = -eyedist / sqrt(thisview.hn2);
622 +                glTranslated(d*thisview.hvec[0], d*thisview.hvec[1],
623 +                                d*thisview.hvec[2]);
624 +                glCallList(displist);
625 +                glMatrixMode(GL_MODELVIEW);
626 +                glPopMatrix();
627 +                setstereobuf(STEREO_BUFFER_LEFT);
628 +        }
629          glXSwapBuffers(ourdisplay, gwind);      /* calls glFlush() */
630          rgl_checkerr("rendering display list");
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;
525        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 540 | 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);
546                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 562 | Line 680 | int    dx, dy, mov, orb;
680   }
681  
682  
683 < getmove(ebut)                           /* get view change */
684 < XButtonPressedEvent     *ebut;
683 > static void
684 > waitabit(void)                          /* pause a moment */
685   {
686 +        struct timespec ts;
687 +        ts.tv_sec = 0;
688 +        ts.tv_nsec = 50000000;
689 +        nanosleep(&ts, NULL);
690 + }
691 +
692 +
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);
700          int     moved = 0;
# Line 578 | Line 708 | XButtonPressedEvent    *ebut;
708  
709          while (!XCheckMaskEvent(ourdisplay,
710                          ButtonReleaseMask, levptr(XEvent))) {
711 +                                        /* pause so as not to move too fast */
712 +                waitabit();
713  
714                  if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
715                                  &rootx, &rooty, &wx, &wy, &statemask))
# Line 598 | 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.flags & PF_RUNNING))
745                  return(0);
746                                  /* assign origin */
747          fbuf[0] = org[0]; fbuf[1] = org[1]; fbuf[2] = org[2];
# Line 613 | 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, fbuf, fbuf, 4*sizeof(float), 6*sizeof(float)) !=
753 <                        4*sizeof(float))
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)
756                  return(0);      /* missed local objects */
# Line 623 | 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 655 | 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 675 | 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 701 | 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 711 | 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;
719        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 737 | 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++)
889                          ;
890          else if (vwnum >= MAXVIEW || vwl[vwnum].v == NULL)
891                  vwnum = 0;
892 <        if (vwnum == currentview)
749 <                return;
750 <        /* copylastv("change view"); */
892 >        copylastv("standard view");
893          dev_view(vwl[currentview=vwnum].v);
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 779 | 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 811 | 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;
# Line 820 | Line 970 | register XConfigureEvent  *ersz;
970          glViewport(0, 0, hres=ersz->width, vres=ersz->height);
971          if (hres > maxhres) maxhres = hres;
972          if (vres > maxvres) maxvres = vres;
973 <        if (in_dev_view)
973 >        if (no_render)
974                  return;
975          wa = (vres*pheight)/(hres*pwidth);
976          va = viewaspect(&thisview);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines