--- ray/src/util/glrad.c 1998/10/21 17:48:51 3.11 +++ ray/src/util/glrad.c 2003/07/21 22:30:19 3.17 @@ -1,9 +1,6 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: glrad.c,v 3.17 2003/07/21 22:30:19 schorsch Exp $"; #endif - /* * Program to display Radiance scene using OpenGL. */ @@ -14,10 +11,14 @@ static char SCCSid[] = "$SunId$ SGI"; #include #endif #include +#include +#include + #include "radogl.h" #include "view.h" #include "paths.h" #include "glradicon.h" +#include "rtprocess.h" #ifndef MAXVIEW #define MAXVIEW 63 /* maximum number of standard views */ @@ -74,7 +75,7 @@ char *scene[MAXSCENE+1]; /* material and scene file l int nscenef = 0; /* number of scene files */ char *octree; /* octree name (NULL if unnec.) */ -int rtpd[3]; /* rtrace process descriptors */ +SUBPROC rtpd; /* rtrace process descriptors */ int silent = 0; /* run rad silently? */ int backvis = 1; /* back faces visible? */ @@ -92,13 +93,8 @@ int displist; /* our scene display list */ int no_render = 0; /* don't rerender */ -#ifdef BSD -#define strchr index -#endif - -extern char *strchr(), *fgets(), *fgetline(), *atos(), *scan4var(); +extern char *fgetline(), *atos(), *scan4var(); extern int nowarn; /* turn warnings off? */ -extern time_t time(); main(argc, argv) @@ -142,7 +138,7 @@ char *argv[]; /* run rad and get views */ runrad(argc-i, argv+i); /* check view */ - if (viewsel != NULL) + if (viewsel != NULL) { if (viewsel[0] == '-') { char *ve = viewsel; if (!sscanview(&thisview, viewsel) || @@ -157,14 +153,15 @@ char *argv[]; progname, viewsel); quit(1); } + } /* open GL */ dev_open(radfile = argv[i]); /* load octree or scene files */ if (octree != NULL) { - displist = rgl_octlist(octree, NULL, NULL); + displist = rgl_octlist(octree, NULL, NULL, NULL); startrtrace(octree); } else - displist = rgl_filelist(nscenef, scene); + displist = rgl_filelist(nscenef, scene, NULL); /* set initial view */ dev_view(currentview < 0 ? &thisview : vwl[currentview].v); /* input/render loop */ @@ -180,15 +177,17 @@ userr: } +void quit(code) /* exit gracefully */ int code; { if (ourdisplay != NULL) dev_close(); - if (rtpd[2] > 0) { - if (close_process(rtpd) > 0) + /* if (rtpd.pid > 0) { */ + if (rtpd.running) { + if (close_process(&rtpd) > 0) wputs("bad exit status from rtrace\n"); - rtpd[2] = 0; + /* rtpd.pid = 0; */ } exit(code); } @@ -204,7 +203,7 @@ char *octname; if (nowarn) av[ac++] = "-w-"; av[ac++] = octname; av[ac] = NULL; - if (open_process(rtpd, av) <= 0) + if (open_process(&rtpd, av) <= 0) error(SYSTEM, "cannot start rtrace process"); } @@ -276,7 +275,7 @@ char **av; do if (isview(buf)) { vwl[nvv].v = (VIEW *)bmalloc(sizeof(VIEW)); - copystruct(vwl[nvv].v, &stdview); + *(vwl[nvv].v) = stdview; sscanview(vwl[nvv].v, buf); if ((cp = setview(vwl[nvv++].v)) != NULL) { fprintf(stderr, "%s: bad view %d - %s\n", @@ -507,7 +506,7 @@ register VIEW *nv; no_render--; } } - copystruct(&thisview, nv); + thisview = *nv; setglpersp(&thisview); render(); return(1); @@ -586,9 +585,8 @@ int dx, dy, mov, orb; VIEW nv; FVECT odir, v1, wp; double d; - register int li; /* start with old view */ - copystruct(&nv, &thisview); + nv = thisview; /* change view direction */ if ((d = viewray(v1, odir, &thisview, (dx+.5)/hres, (dy+.5)/vres)) < -FTINY) @@ -626,6 +624,16 @@ int dx, dy, mov, orb; } +static +waitabit() /* pause a moment */ +{ + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 5000000; + nanosleep(&ts, NULL); +} + + getmove(ebut) /* get view change */ XButtonPressedEvent *ebut; { @@ -642,6 +650,8 @@ XButtonPressedEvent *ebut; while (!XCheckMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent))) { + /* pause so as not to move too fast */ + waitabit(); if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, &rootx, &rooty, &wx, &wy, &statemask)) @@ -669,7 +679,8 @@ double md; { float fbuf[6]; /* check to see if rtrace is running */ - if (rtpd[2] <= 0) + /* if (rtpd.pid <= 0) */ + if (!rtpd.running) return(0); /* assign origin */ fbuf[0] = org[0]; fbuf[1] = org[1]; fbuf[2] = org[2]; @@ -677,8 +688,8 @@ double md; if (md <= FTINY) md = FHUGE; fbuf[3] = dir[0]*md; fbuf[4] = dir[1]*md; fbuf[5] = dir[2]*md; /* trace that ray */ - if (process(rtpd, fbuf, fbuf, 4*sizeof(float), 6*sizeof(float)) != - 4*sizeof(float)) + if (process(&rtpd, (char *)fbuf, (char *)fbuf, + 4*sizeof(float), 6*sizeof(float)) != 4*sizeof(float)) error(INTERNAL, "error getting data back from rtrace process"); if (fbuf[3] >= .99*FHUGE) return(0); /* missed local objects */ @@ -739,9 +750,9 @@ register XKeyPressedEvent *ekey; case 'l': /* retrieve last (premouse) view */ if (lastview.type) { VIEW vtmp; - copystruct(&vtmp, &thisview); + vtmp = thisview; dev_view(&lastview); - copystruct(&lastview, &vtmp); + lastview = vtmp; } else XBell(ourdisplay, 0); break; @@ -820,7 +831,7 @@ VIEW *vp; { FILE *fp; /* check if already in there */ - if (!bcmp(&thisview, vwl[currentview].v, sizeof(VIEW))) { + if (!memcmp(&thisview, vwl[currentview].v, sizeof(VIEW))) { error(COMMAND, "view already in standard list"); return; } @@ -841,7 +852,7 @@ VIEW *vp; if (currentview >= MAXVIEW) error(INTERNAL, "too many views in appendview"); vwl[currentview].v = (VIEW *)bmalloc(sizeof(VIEW)); - copystruct(vwl[currentview].v, &thisview); + *(vwl[currentview].v) = thisview; if (nm != NULL) vwl[currentview].nam = savqstr(nm); } @@ -855,7 +866,7 @@ char *cause; if (cause == lastvc) return; /* only record one view per cause */ lastvc = cause; - copystruct(&lastview, &thisview); + lastview = thisview; }